Head First Java Flashcards
What should the first line of your program be in the main class?
public static void main (String[] args){
}
What are the 3 standard loop constructs in Java?
while, do while and for
How do you declare and give initial values to a three-element String array in Jave?
String[] pets = {“Fido”, “Zeus”, “Bin”};
What does random() return in Java? How do you use this?
It returns a number between 0 and just less than one. You use it by multiplying the max amount of your desired range by whatever random return to give you your random number.
In terms of adaptability, what is one of the biggest advantages of OOP?
You can accommodate new requirements without altering previously tested, delivered, and accepted code. There is no need to recompile the existing code.
What does the dot operator do in respect of a class?
It gives you access to the objects state and behavior i.e. the instance variables and the methods,
What’s the function of the main method? Why
It serves to test your classes and to start your program off. The real idea of OOP is to get classes talking to classes.
How do you write a global variable called totalValue in Java?
You don’t. There is no concept of global variables in Java.
What is a manfest text file?
It is a text file bundled with your application classes that defines which class in the zipped jat file holds the main method.
What are 2 types of variable?
Primitive and Reference
What are the four integer primitives in Java?
long, int, short, byte
What are the two floating-point primitives in Java?
float and double
What are the six types of integer and floating-point variables in Java?
float double
byte short int long
What values can be held in a byte, short, integer, and long?
Byte:c. -127 to 127
Short: c.-31k to 31k
Int: c. -2bn to 2bn
long - more than 2bn
How many primitive types are there in Java?
8