Java Programming Fundamentals
- 118Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is the Java Development Kit (JDK), and what does it contain?
The JDK is a software development environment for building Java applications. It includes a compiler, reusable code libraries, a Java Runtime Environment, and other tools.
Or swipe the card
118 cards
What is the Java Development Kit (JDK), and what does it contain?
The JDK is a software development environment for building Java applications. It includes a compiler, reusable code libraries, a Java Runtime Environment, and other tools.
What are the JRE and JVM, and how are they related?
The Java Runtime Environment (JRE) provides what is needed to run Java programs. It includes the Java Virtual Machine (JVM), which executes Java bytecode.
What are the two main stages when a Java program runs?
Compilation converts Java source code into bytecode; execution runs that bytecode on the JVM.
Which command-line tool compiles a Java source file, and what is an example command?
The Java compiler,
javac, compiles source files. For example:javac Main.java.What is a
.classfile?It contains the bytecode produced by compiling a Java source file.
What does the JVM do with Java bytecode?
It translates bytecode into native code for the operating system on which the program is running.
Why are Java applications described as platform-independent?
The same bytecode can run on different operating systems, provided each has a compatible JRE and JVM.
What popular Java IDEs are mentioned, and which is used in the course?
NetBeans, Eclipse, and IntelliJ are mentioned; the course uses IntelliJ IDEA.
Which IntelliJ IDEA edition is recommended for the course, and why?
The free Community Edition is recommended because it is sufficient for the course.
Who developed Java, when, and at which company?
James Gosling developed Java in 1995 at Sun Microsystems, which Oracle acquired in 2010.
What names did Java have before it was called Java?
It was first called Oak, then Green, and finally Java.
What inspired the name Java?
Java coffee inspired the name; the course also connects the coffee inspiration to Java’s logo.
What are Java SE and Java EE used for?
Java SE is the core Java platform. Java EE builds on SE with additional libraries for large-scale, distributed, multi-tier systems.
What are Java ME and Java Card designed for?
Java ME is a subset of Java SE designed for mobile devices; Java Card is used in smart cards.
What Java adoption and version figures does the content cite?
As reported in 2019, Java SE 12 had been released in March 2019; the content cites close to 9 million developers, about 3 billion mobile phones, 120 million TV sets, every Blu-ray player, and an average U.S. Java developer salary just over $100,000.
What is a function in programming?
A function is a block of code that performs a task, such as sending an email or validating user input.
What is a method, and how does it differ from a function?
A method is a function that belongs to a class. Some languages allow functions outside classes, but Java methods belong to classes.
What is a Java class used for?
A class is a container for related methods and helps organize code.
What is the
mainmethod’s role in a Java program?It is the program’s entry point: when the program runs, execution begins in
main.What minimum structure does a basic Java program need?
At least one class containing a
mainmethod.What does the
staticmodifier mean for themainmethod in this course’s basic program structure?The
mainmethod should be declaredstatic; the course notes that the details ofstaticwill be covered later.What does a method’s return type specify, and what does
voidmean?The return type specifies the kind of value a method returns.
voidmeans the method returns no value.What are method parameters used for?
Parameters provide a method with values it needs to perform its task.
What is an access modifier?
A special keyword that determines whether other classes or methods can access a class or method.
publicis commonly used.Where does Java conventionally place the opening brace for a class or method?
On the same line as the class or method declaration.
What naming conventions does Java use for classes and methods?
Class names use PascalCase, with each word beginning with an uppercase letter. Method names use camelCase, with the first word lowercase and later words capitalized.
What is a Java package, and why use one?
A package groups related classes and provides a namespace, helping organize projects as they grow.
What is the conventional base-package naming pattern described for a Java project?
Use the company’s domain name in reverse order, such as
com.example. It creates a namespace and does not require owning a registered domain.What does a package statement do, and how is it terminated?
It specifies the package a class belongs to and, like other Java statements, ends with a semicolon.
What file extension do Java source files use, and what does an import statement do?
Java source files use
.java. Animportmakes a class from another package available for use.Why can Java code use classes in
java.langwithout an explicit import?The
java.langpackage is imported automatically.What is a variable, and why must it be initialized before it is read?
A variable is a named memory location used to store data temporarily. It must be given an initial value before its value is read.
In a declaration such as
int age = 30, what do the type, identifier, assignment operator, and initial value represent?intis the type,ageis the identifier,=assigns a value, and30is the initial value.Can a variable’s value change after initialization?
Yes. A variable can be assigned a different value later in the program.
What is an identifier, and what makes a variable name useful?
An identifier is a name used to identify a variable. Meaningful, descriptive names make code easier to understand.
Why is declaring several variables on one line generally discouraged?
Although Java permits it, separate declarations are usually easier to read and maintain.
What is the difference between primitive and reference types?
Primitive types store simple values; reference types store references to complex objects.
How much memory do
byte,short,int, andlonguse, and what rough ranges does the content give?They use 1, 2, 4, and 8 bytes respectively. The content gives
byteas ranging from −128 to 127,shortup to about 32,000, andintup to about 2 billion;longstores still larger whole numbers.When should
floatordoublebe used, and how do their sizes compare?Use them for numbers with decimal points. A
floatuses 4 bytes; adoubleuses 8 bytes and can represent larger values.What do
charandbooleanstore?charstores one character and uses 2 bytes;booleanstores eithertrueorfalse.Why must a large integer literal assigned to a
longsometimes end withL?Java treats an unsuffixed whole-number literal as an
intby default. TheLsuffix marks it as along; uppercaseLis clearer than lowercasel.Why must a decimal literal assigned to a
floatsometimes end withF?Java treats decimal literals as
doubleby default. TheFsuffix marks the literal as afloat.How should Java character and string literals be delimited?
A single character uses single quotes; a string containing multiple characters uses double quotes.
What are reserved keywords, and can they be used as variable names?
Reserved keywords have special meanings in Java, so they cannot be used as names for variables, classes, or methods.
How is a reference-type object commonly created, and what is an object’s relationship to its class?
Use
newfollowed by the class name and constructor arguments. The class is a template; an object is an instance created from it.How does assigning a reference variable differ from assigning a primitive variable?
Primitive assignment copies the value, so the variables are independent. Reference assignment copies the reference, so both variables can refer to the same object and observe changes to it.
How can a variable be made constant, and what naming convention is used for constants?
Declare it with
final; after initialization, its value cannot be changed. Constants are conventionally named with uppercase letters, such asPI.What is a Java string, and why is assigning a string literal a convenient way to create one?
A string is a reference type representing a sequence of characters. Java allows a string variable to be initialized directly with a string literal instead of explicitly using
new String(...).How can strings be concatenated in Java?
Use the
+operator to join strings, or to join a string with another value such as a number.What do the
startsWithandendsWithstring methods check?They return whether a string begins or ends with the specified character sequence.
What does the
lengthmethod return for a string?The number of characters in the string.
What does
indexOfreturn, and what does a result of-1mean?It returns the index of the first occurrence of the specified character or sequence. It returns
-1if that content is not found.What does the string
replacemethod do, and does it modify the original string?It returns a new string with the target content replaced. It does not modify the original string because strings are immutable.
What do
toLowerCaseandtrimdo, and do they change the original string?toLowerCasereturns a lowercase version;trimreturns a version with surrounding whitespace removed. Neither changes the original string.How can a double quote be included inside a Java string literal?
Escape it with a backslash:
\".How can a literal backslash be included in a Java string?
Escape the backslash with another backslash:
\\in Java source represents one backslash in the resulting string.What do the Java string escape sequences
\nand\trepresent?\ninserts a new line;\tinserts a tab.What are arrays used for, and what is an important size limitation?
Arrays store lists of items, such as numbers or messages. Their length is fixed when they are created.
How are array elements accessed, and what index identifies the first element?
Use an index in square brackets; the first element has index
0.What happens when a program accesses an array index that is outside the array’s bounds?
Java raises an exception, and the program may terminate if the exception is not handled.
What default values does the content identify for uninitialized integer and boolean array elements?
Integer array elements default to
0; boolean array elements default tofalse.What does
Arrays.toStringdo, and how does it relate to method overloading?It returns a readable string representation of an array. The method is overloaded, with implementations for different array element types.
How can an array be sorted using Java’s
Arraysclass?Call
Arrays.sort(array)to sort the array.How do multidimensional arrays differ from one-dimensional arrays, and how can a multidimensional array be displayed?
A multidimensional array contains arrays, such as rows and columns in a matrix. Use
Arrays.deepToStringto get a readable representation;Arrays.toStringis for a one-dimensional array.Which arithmetic operators are covered, and what does the modulus operator return?
Addition, subtraction, multiplication, division, and modulus are covered. Modulus returns the remainder of a division.
What is an operand in an arithmetic expression?
A value on which an operator acts; for example, in an addition, the numbers being added are operands.
What happens when one whole number is divided by another in Java?
The result is a whole number; any fractional part is discarded. Convert an operand to a floating-point type to get a fractional result.
What is an expression in Java?
A piece of code that produces a value, such as an arithmetic calculation or a comparison.
What is the order of precedence for the arithmetic operators covered?
Parentheses are evaluated first, followed by multiplication and division, then addition and subtraction.
How do prefix and postfix increment differ when used in an assignment?
Postfix (
x++) supplies the original value before incrementing; prefix (++x) increments first and supplies the new value.What do the increment and decrement operators do?
Increment increases a value by one; decrement decreases it by one.
What is a compound assignment operator, such as
+=?It combines an operation with assignment:
x += 2is equivalent tox = x + 2. Similar forms exist for other arithmetic operations.What is implicit casting, and when is it generally safe?
It is automatic conversion between compatible types when conversion does not lose data, such as widening a smaller numeric type to a larger one.
What is explicit casting, and what is a potential consequence?
It is a conversion requested by the programmer, such as
(int) value. It may discard information, such as digits after a decimal point.Can a string be converted to a number using a numeric cast? What should be used instead?
No. Use a wrapper-class parsing method, such as
Integer.parseIntfor an integer orDouble.parseDoublefor a double.What does
Math.rounddo, and what return types does the content describe?It rounds a floating-point value to a whole number. The float version returns an
int; the double version returns along.What do
Math.ceilandMath.floorreturn?ceilreturns the smallest integer-valued result greater than or equal to the input;floorreturns the largest integer-valued result less than or equal to it. Both return adouble.What do
Math.maxandMath.mindo?They return the greater or lesser of two values, respectively; their methods are overloaded for numeric types.
What range does
Math.randomproduce, and how can it be scaled?It produces a
doublefrom 0 up to but not including 1. Multiplying it by 100 scales the range to 0 up to but not including 100.Why can casting
Math.random()to an integer before multiplying by 100 produce only zero?The random value is less than 1, so casting it to an integer first discards its fractional part and gives 0. Multiply first, then cast if an integer result is needed.
What is the purpose of Java’s
Scannerclass when reading terminal input?It reads input from a source such as the terminal; use
System.into supply terminal input.What is the difference between
Scanner.next()andScanner.nextLine()?next()reads one token, ending at whitespace.nextLine()reads the entire line, including spaces within it.Why might
trim()be useful on user input?It removes whitespace at the beginning and end of a string, which can prevent unwanted spaces from affecting input handling.
Why is it inefficient to create a new
Scannerinside every iteration of an input loop?It repeatedly creates unnecessary objects. Create one scanner before the loop and reuse it.
How can a string entered by a user be converted to a numeric value?
Use an appropriate parsing method, such as
Integer.parseInt,Float.parseFloat, orDouble.parseDouble.What can happen if a numeric parsing method receives invalid input?
It can raise an exception, which is Java’s way of reporting an error at runtime.
Why can’t
NumberFormatbe instantiated directly, and how can an instance be obtained?NumberFormatis abstract. Use a factory method such asgetCurrencyInstance()orgetPercentInstance()to obtain an instance.How does a currency formatter present a number?
It returns a formatted string, typically using a currency symbol, grouping separators, and two digits after the decimal point.
How does a percent formatter interpret a value such as 0.1?
It formats the value as a percentage, so 0.1 is displayed as 10%.
What is method chaining?
Calling a method on the result of another method, such as calling
formaton the object returned by aNumberFormatfactory method.What is the general formula for a monthly mortgage payment described in the content?
Let P be the principal, r the monthly interest rate, and n the total number of monthly payments. The payment is (1+r)n−1Pr(1+r)n.
How is an annual interest rate entered as a percent converted to a monthly rate?
Divide the annual percentage by 100 to convert it to a decimal, then divide by 12: r=100×12annual rate.
How is the number of monthly payments for a loan term in years calculated?
Multiply the number of years by 12.
What does a comparison operator produce?
A boolean value,
trueorfalse. Operators covered include equality, inequality, greater than, greater than or equal to, less than, and less than or equal to.What is a boolean expression?
An expression that evaluates to
trueorfalse.What does the logical AND operator
&&require to evaluate totrue?Both conditions must be true. Java can stop evaluating once it finds a false condition.
What does the logical OR operator
||require to evaluate totrue?At least one condition must be true. Java can stop evaluating once it finds a true condition.
What does the logical NOT operator
!do?It reverses a boolean value: true becomes false, and false becomes true.
What are the clauses of an
ifstatement used for?ifhandles the first condition,else ifhandles additional conditions, andelsehandles the case when none of the preceding conditions is true.When are braces needed around an
ifbranch in Java?They are required when the branch contains multiple statements. The content notes that programmers may also use braces around single statements for consistency.
How can a boolean variable be assigned directly from a condition instead of using an
ifstatement?Assign the boolean expression itself, such as
hasHighIncome = income > 100000;.What does the ternary operator do?
It chooses between two values based on a condition:
condition ? valueIfTrue : valueIfFalse.How does a
switchstatement select a branch?It compares an expression with
casevalues and executes the matching case;defaulthandles cases with no match.Why are
breakstatements commonly used inswitchcases?They exit the switch after a case runs. Without a break, execution can continue into later cases.
Which types does the content say can be used in
switchcases?It describes strings and integer-like values such as
byte,short, andint, but excludeslong.What are the three main parts of a
forloop header?Initialization of a loop variable, a boolean continuation condition, and an update such as incrementing the variable.
How does a
whileloop differ from ado-whileloop?A
whileloop checks its condition before running the body and may run zero times. Ado-whilechecks afterward and runs at least once.What is the difference between
breakandcontinueinside a loop?breakexits the loop;continueskips to the next iteration.What are the key limitations of a
for-eachloop compared with a traditionalforloop?A for-each loop moves forward through the items and does not directly provide their indexes. Use a traditional
forloop when you need an index or reverse traversal.How does the FizzBuzz example use the modulus operator?
A number is divisible by another number when the remainder is zero; for example, test divisibility by 5 with
number % 5 == 0.Why should FizzBuzz test divisibility by both 3 and 5 before testing either one separately?
The combined condition is more specific. If a number such as 15 is tested against 5 first, the program may print only
Fizzand never reach the combined case.What trade-off does the content describe between nested conditions and repeating a condition?
Nested conditions can avoid repeating tests but may make code harder to read. A flatter structure may repeat a test but be clearer; there is not always one ideal solution.
How can an infinite loop be used to validate user input?
Ask the question inside the loop, test the input, and use
breakwhen it is valid. If it is invalid, display an error and loop to ask again.Why might variables used after a validation loop need to be declared outside it?
A variable’s scope is limited to the block where it is declared. Declaring it outside the loop lets later code access it.
What input ranges does the mortgage-calculator validation example use?
It accepts a principal from 1,000 to 1,000,000, an annual interest rate greater than 0 and at most 30, and a loan term from 1 to 30 years.
Why should a mortgage calculator use named constants rather than unexplained numeric literals?
Named constants clarify what values mean, such as months per year or the percent divisor, and avoid magic numbers.
What types does the mortgage-calculator example choose for principal, interest, and loan term?
It uses an
intfor principal, afloatfor the small annual interest value, and abytefor a term capped at 30 years.What general principle about clean code is emphasized in the content?
Good code should be understandable to humans, not merely executable by a computer; readable names and clear structure support maintainability.

Ask anything
We've read this whole study set, so questions about it get the best answers.