Java Fundamentals Flashcards

1
Q

Is Java a compiled or interpreted language?

A

Java can be considered both a compiled and an interpreted language because its source code is first compiled into a binary byte-code. This byte-code runs on the Java Virtual Machine (JVM), which is usually a software-based interpreter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the JDK?

A

The Java Development Kit (JDK) is one of three core technology packages used in Java programming, along with the JVM (Java Virtual Machine) and the JRE (Java Runtime Environment). It’s important to differentiate between these three technologies, as well as understanding how they’re connected:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the JVM

A

Java Virtual Machine

The JVM is the Java platform component that executes programs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the Java Runtime Environment

A

The JRE is the on-disk part of Java that creates the JVM.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the JDK

A

The Java Development Kit:

The JDK allows developers to create Java programs that can be executed and run by the JVM and JRE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What primitive types does Java provide?

A

Byte, short, int, long, float, double, Boolean and char

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a byte?

A

byte: The byte data type is an 8-bit signed two’s complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable’s range is limited can serve as a form of documentation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a short?

A

short: The short data type is a 16-bit signed two’s complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an int?

A

int: By default, the int data type is a 32-bit signed two’s complement integer, which has a minimum value of -2^31 and a maximum value of 2^31-1. In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 2^32-1. Use the Integer class to use int data type as an unsigned integer. Static methods like compareUnsigned, divideUnsigned etc have been added to the Integer class to support the arithmetic operations for unsigned integers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a long?

A

long: The long data type is a 64-bit two’s complement integer. The signed long has a minimum value of -2^63 and a maximum value of 2^63-1. In Java SE 8 and later, you can use the long data type to represent an unsigned 64-bit long, which has a minimum value of 0 and a maximum value of 2^64-1. Use this data type when you need a range of values wider than those provided by int. The Long class also contains methods like compareUnsigned, divideUnsigned etc to support arithmetic operations for unsigned long.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a float?

A

float: The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a double?

A

double: The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a Boolean?

A

boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its “size” isn’t something that’s precisely defined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a char?

A

char: The char data type is a single 16-bit Unicode character. It has a minimum value of ‘\u0000’ (or 0) and a maximum value of ‘\uffff’ (or 65,535 inclusive).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are some of the ways that a reference type differs from a primitive type?

A

Assignment
copies the contents of RHS variable into LHS variable
primitives: the primitive value is copied
references: the address is copied
implications: for references the object is not copied, it is shared (reference variables are aliases)
Comparisons (e.g. ==)
compares the contents of the variables
primitives: the primitive values are compared
references: the addresses are compared
implications: for references the contents of the objects are not compared
Passing Parameters
terminology:
formal parameter: the parameter variable that is listed (along with its type) in the method declaration
actual parameter: the parameter that is given when the method is called
copies the contents of actual parameter into the formal parameter (i.e., pass-by-value)
primitives: the primitive value is copied
references: the address is copied
implications: for references the object is not copied, it is shared (i.e., actual parameter and formal parameter are aliases)
primitives: changing the formal parameter’s value doesn’t affect the actual parameter’s value
references: changing the formal parameter’s address doesn’t affect the actual parameter’s address but changing the formal parameter’s object does change the actual parameter’s object since they refer to the same object
Returning Values
returns a result to where the method was called
primitives: the primitive value is returned
references: the address is returned
recall: local variables and parameters are destroyed when the method finishes execution
implications: a locally created object can survive if it is returned or if it is stored in a data member

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When using a debugger, what does it mean to step into a method?

A

A method is about to be invoked, and you want to debug the code of that method, so the next step is to go into that method and continue debugging step-by-step.

17
Q

What are the parts of a method?

A

A method definition has two major parts: the method declaration and the method body. The method declaration defines all the method’s attributes, such as access level, return type, name, and arguments, as shown in the following figure. The method body is where all the action takes place.

18
Q

What does it mean to overload a method?

A

Method overloading allows a class to have more than one method with the same name, if their argument lists are different.

19
Q

Can the size of an array be changed?

A

No. You must decide the size of the array when it is constructed. You can’t change the size of the array after it’s constructed.