Study your flashcards anywhere!

Download the official Cram app for free >

  • Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key

image

Play button

image

Play button

image

Progress

1/138

Click to flip

138 Cards in this Set

  • Front
  • Back
What are Keywords?
Special reserved words in Java that you cannot use as identifiers for classes, methods, and variables.
All keywords start with what?
a lowercase letter
What does the "private" access modifier do?
Makes a method or variable accessible only from within its own class.
What does the "protected" access modifier do?
Makes a method or variable accessible only to classes in the same packages or subclasses of the class.
What does the "public" access modifier do?
Makes a class, method or variable accessible from any other class
How is the "abstract" modifier used?
Used to declare a class that cannot be instantiated, or a method that must be implemented by a nonabstract subclass.
How is the "extends" modifier used?
Used to indicate the superclass that a subclass is extending.
What does "final" do?
Makes it impossible to extend a class, override a method or reinitialize a variable.
How is "implements" used?
Used to indicate the interfaces that a class will implement.
What does "native" indicate?
Indicates a method is written in a platform-dependent language, such as C.
How is "new" used?
Used to instantiate an object by invoking the constructor.
What does "static" do?
Makes a method or a variable belong to a class as opposed to an instance.
How is strictfp used?
Used in front of a method or class to indicate that floating-point numbers will follow FP-strict rules in all expressions.
What does "synchonized" indicate?
Indicates that a method can be accessed by only one thread at a time.
What does "transient" do?
Prevents fields from ever being serialized. Transient fields are always skipped when objects are serialized.
What does "volatile" indicate?
Indicates a variable may change out of sync because it is used in threads.
What does "break" do?
Exits from the block of code in which it resides.
What does "case" do?
Executes a block of code, dependent on what the "switch" tests for.
What does "continue" do?
Stops the rest of the code following this statement from executing in a loop and then begins the next interation of the loop.
What does "default" do?
Executes this block of code if none of the switch-case statements match.
What does "do" do?
Executes a block of code one time, then, in conjunction with the "while" statement, it performs a test to determine whether the block should be executed again.
What does "else" do?
Executes a alternate block of code if an "if" test is false.
What is "for" used for?
Used to perform a conditional loop for a block of code.
What does "instanceof" determine?
Determines whether an object is an instance of a class, superclass, or interface.
What does "return" do?
Returns from a method without executing any code that follows the statement (can optionally return a variable).
What does "switch" indicate?
Indicates the variable to be compared with the "case" statements.
What does "while" do?
Executes a block of code repeatedly while a certain condition is "true".
What does "catch" do?
Declares the block of code used to handle an exception.
What is "finally"?
Block of code, usually following a try-catch statement, which is executed no matter what program flow occurs when dealing with an exception.
How is "throw" used?
Used to pass an exception up to the method that called this method.
What does "throws" indicate?
Indicates the method will pass an exception to the method that called it.
What is "try"?
Block of code that will be tried, but which may cause an exception.
What does "assert" do?
Evaluates a conditional expression to verify the programmer's assumption.
What does "import" do?
A statement to import packages or classes into code.
What does "package" do?
Specifies to which package all classes in a source file belong.
What is a "boolean"?
A value indicating "true" or "false".
What is a "byte"?
An 8-bit integer (signed).
What is a "char"?
A single Unicode character (16-bit unsigned).
What is a "double"?
A 64-bit floating-point number. (signed).
What is a "float"?
A 32-bit floating-point number. (signed).
What is an "int"?
A 32-bit integer (signed).
What is a "long"?
A 64-bit integer (signed).
What is a "short"?
A 16-bit integer (signed).
What type of reference variable is "super"?
Reference variable referring to the immediate superclass.
What type of reference variable is "this"?
Reference variable referring to the current instance of an object.
How is the "void" keyword used?
It is used only in the return value placeholder of a method declaration and indicates no return type for this method.
Name 2 keywords that are reserved in Java but which are not used?
"const" and "goto"
What should one use to declare a constant instead of "const"?
Use "public static final".
What happens if you use a keyword as a method name?
Code does not compile.
Give 3 literal values that for the purpose of the exam you should treat like keywords?
"null", "true", "false"
Are all 6 number types on Java signed or unsigned?
signed
Which bit represents the sign in the 6 number types?
The leftmost bit (the most significant bit)
What does a 1 in the sign bit of a number mean and what does a 0 in the sign bit mean? What do the rest of the bits represent?
1 means negative and a 0 means positive.
The rest of the bits represent the value in 2's complement notation.
Why is the positive range of a number one less than the negative range of a number?
Because the number zero is stored as a positive binary number.
What is the formula for calculating the negative range and what is the formula for calculating the positive range of a number?
negative range: -2^(bits -1)
positive range: 2^(bits -1) -1
A double holds ___ bits and a float holds ___ bits.
64
32
What are the values for a boolean?
"true" or "false"
What is the bit depth of a boolean?
It's virtual-machine dependent
What does the char type contain?
A single 16-bit Unicode character.
How many bits does the extended ASCII set known as ISO Latin-1 need?
only 8 bits (256 different characters)
How many possible Unicode characters are there?
They are represented by unsigned 16-bit integers which means 2^16 possible values, ranging from 0 to 65535 (2^16 - 1).
Since "char" is really an integer type, it can be assigned to any number large enough to hold ____.
65535
What is a primitive literal?
A source code representation of the primitive data types.
What are the 3 ways to represent integer numbers in the Java language?
decimal(base 10), octal(base 8), and hexadecimal(base 16)
Octal integers use only the digits __ to __.
0 to 7
How do you represent an octal form in Java?
By placing a zero in front of the number.
You have up to __ digits in an octal number, not including the leading zero.
21
Hexadecimal numbers are constructed using __ distinct symbols.
16
Count from 0 to 15 in hex.
0 1 2 3 4 5 6 7 8 9 a b c d e f
Can you use either capital or lowercase numbers for the extra digits in hex?
Yes, one of the few places Java is not case-sensitive.
You are allowed up to ___ digits in a hexadecimal number, not including the prefix __ and the optional suffix extension ___.
16
0x or OX?
L
How do you specify an integer literal as "long"?
By placing a suffix of L or l after the number.
How are floating-point numbers defined?
As a number, a decimal symbol, and more numbers representing the fraction.
Floating-point literals are defined as _____ by default.
double (64 bits)
If you want to assign a floating-point literal to a variable of type "float (32) bits" you must do what?
Attach the suffix F or f to the number.
What happens if you assign a double to a float variable?
You get a compiler error - possible loss of precision.
What happens if you put a comma in you numeric literal?
You get a compiler error.
Can you use numbers in Java to represent "true" or "false"?
No - Java is not C++
If you use a number where a boolean is required, what happens?
You get a compiler error.
How is a "char" literal represented?
By a single character in single quotes or the Unicode notation which is the Unicode value prefixed by "\u".
What integer numbers can you assign to a char variable?
Any unsigned number which is 65535 or less. If it is not in this range, you must cast it to char or else you get a compiler error - possible loss of precision.
Name some characters that can be used with the escape code?
characters that can't be types in as a literal like linefeed, newline, horizontal tab, backspace, and double or single quotes.
A string literal is a source code representation of _____________.
A value of a String object.
Are strings primitives?
No, but they can be represented as literals - typed directly into code.
What are arrays and where is the array located?
They are objects in Java that store multiple variables of the same type. They can hold either primitive or object references. The array itself will always be an object on the heap, even if the array is declare to hold primitive elements.
Arrays are efficient, but most of the time you'll want to use one of the ________ types from java.util.
Collection
How do you declare an array?
By stating the type of element the array will hold , which can be an object or a primitive, followed by square brackets to the left or right of the identifier.
What is a multidimensional array?
Array of arrays.
Is it legal to include the size of the array in its declaration? Why or why not?
No - it will be a compiler error. The JVM doesn't allow space until you actually instantiate the array object. That's when size matters.
What is the most straightforward way to construct an array?
Use the keyword "new" followed by the array type, with a bracket specifying how many elements of that type the array will hold.
What happens with the following example?
int[] testScores;
testScores = new int[4];
How can you do the above in one statement?
puts a new object on the heap - an array object holding four elements - with each element containing an "int" with a default value of 0.

int[] testScores = new int[14];
In the following code:
Thread[] threads = new Thread[5]
is the Thread constructor being invoked?
No. We're not creating a Thread instance, but rather a single Thread array object. There are still no actual Thread objects.
The Thread array object holds five Thread reference variables.
What happens if you don't give a size when an array is constructed?
You get a compile error.
What do the words "construct", "create", and "instantiate" all mean?
An object is build and placed on the heap. They imply that the object's constructor runs.
What can you say about any code that uses the word "new"?
It causes the class constructor and all superclass constructors to run.
Can objects be created even without ever using the keyword "new"?
Yes - e.g. an array can be created using a kind of syntax shorthand that creates the array while simultaneously initializing the array elements to values supplied in the code.
Is the following acceptable in Java?
int[][] ratings = new int[3][];
Yes, since the JVM needs to know only the size of the object assigned to the variable ratings.
What are the 2 possibilites that an array element can be?
1. a primitive value
2. objects referred to by the reference variables in the array.
A reference that has not had an object assigned to it is a ____ reference. What happens if you use this reference?
null
You get the infamous NullPointerException.
How do you access the individual elements in an array?
With an index number that always begins with zero.
If an array has three elements, what happens when you try to access the [3] element? What happens if you get a negative number as an array index.
You get the runtime exception ArrayIndexOutOfBoundsException.
You get a runtime exception.
What does the public variable "length" do?
It gives you the number elements the array holds, but it does not tell you whether those elements have been initialized.
Give an example of declaring, constructing, and Initializing an array in one step.
int[] dots = {3, 6, x, 8};

1. Declares an "int" array reference variable "dots"
2. Creates an "int" array with a length of four
3. Populates the elements with the values 3, 6, 7, and 8
4. Assigns the new array objects to the reference variable "dots"
How many objects are created in the following statement?
int[][] scores = {{5,2,4,7}, {9,2}, {3,4}};
4 objects: one array of "int" arrays, and three "int" arrays.
What is the shortcut called "anonymous array creation"?
construct and initialize an array and then assign the array to a previously declared array reference variable. Example:
int[] testScores;
testScores = new int[] {4,7.2};
What good is an array if you don't assign it to a reference variable?
You can use it to create a just-in-time array to use as an argument to a method that takes an array parameter.
Do you specify a size when using anonymous array creation syntax?
No - the size is derived from the number of items between the curly braces.
What kind of values can a primitive array accept?
Any value that can be promoted implicitly to the declared type of the array. For example, an "int" array can hold an value that can fit into a 32-bit "int" variable.
What kind of values can a class array type accept?
Objects of any subclass of the declared type.
What kind of values can a interface array type accept?
The array elements can refer to any instance of any class that implements the declared interface.
If you declare an "int" array, what can the reference variable you declared be reassigned to?
Any "int" array (of any size) but cannot be reassigned to anything that is not an "int" array, including an "int" value.
Arrays that hold object references, as opposed to primitives, aren't as _________.
restrictive
What test should you use to decide if object array can be reassigned to another object array?
the IS-A test.
What operator can be used to check the IS-A test in code?
the "instanceof" operator
For multidimensional arrays, what must be true when you assign an array to a previously declared array reference?
The array you're assigning must be the same dimension as the reference you're assigning it to.
Where is an "instance variable" declared?
defined at class level. The variable declaration is not made within a method, constructor, or any other initializer block.
Where is a "local variable" declared?
within a method (or in the argument list of the method)
What are some other names given to "local variables"?
stack, temporary, automatic, or method variables
Are instance variables initialized to a default value each time a new instance is created?
Yes
What is the default value for primitive number "instance variables"?
zero
What is an object reference "instance variable" initialized to as a default?
null
Is "null" the same as an empty String ("")?
No
What does a "null" value mean for an object reference variable?
It means that the reference variable is not referring to any object on the heap.
What happens when you use the "toLowerCase" method on a String object which is null?
You get a NullPointerException.
If we initialize an array, what happens to the array elements?
They are always initialized to their default values.
What is an object reference "instance variable" initialized to as a default?
null
Is "null" the same as an empty String ("")?
No
What does a "null" value mean for an object reference variable?
It means that the reference variable is not referring to any object on the heap.
What happens when you use the "toLowerCase" method on a String object which is null?
You get a NullPointerException.
If we initialize an array, what happens to the array elements?
They are always initialized to their default values regardless of where the array itself is declared or instantiated.
What must you do to local variables, including primitives, before you attempt to use them?
You must initialize them before you attempt to use them.
What happens if you try to use an uninitialized primitive local variable in your code?
You get a compiler error.
Can you declare a local variable without initializing it if you don't use it?
Yes
Is a null reference the same as an uninitialized reference?
No, uninitialized means it doen't have a value.
Are array elements given their default values even if the array is declared as a local variable?
Yes
What kind of parameter does the main method take?
a String array parameter which holds the arguments you send along with the command to run your Java program.
What is the length of the "args" array parmeter to main?
Always equal to the number of command-line arguments.
What happens if you try to access beyond the "length" of an array?
you'll get an ArrayIndexOutOfBoundsException.