Chapter 2 Flashcards
What is a constructor in java
this is a special type of method that creates a new object based on the parent Class.
What is the correct syntax of a constructor within in a class
public name () { }
What does a normal method have that a constructor does not have
A return type
What do we know of the name of a constructor class
The name matches the name of the parent class.
what is between the braces in java { }
a Code block
Name four types of code blocks
A Class definition
A Method declaration
A Inner Block
A instance initializer
What is the correct order of initialization in a class in regards to running the code
Fields and instance initializer first in order of appearnce in the code (top to bot) Followed by the constructor.
is a “String” variable a primitive type?
No, A string is a object, not a primitive type.
What are correct values for a boolean
True or False
What is the correct value range for a byte
-128 to 127
what is the difference between a int and a float
The same range as the fields of a int, but with up to 7 decimal digits
what is the difference between a long and a double
The same range as the fields of a long, but with up to 16 decimal digits
what do all possible values of the ‘char’ type have in commen.
They are all members of the Unicode Ascii values
What is a easy way to calculate the total range of a “byte”
A byte is 8 bits. A bit can have 2 values : 1 or 0. So a byte can have a range of 2^8 different combinations of bits.
How are the maximum number of bits used by the Java engine.
Java uses the bits to figure out how much memeory is needed for a Var. For example Java allocates 32 bits if you write (int num;) Memory is wasted if the value of num never exceeds a “short” wich is halve the size.
What happens when we you declare a value that fits a long and does not fit a int. But without including a capitol L at the end of the value.
java will throw a error because any number in java code is considered a int if not declared as a long by adding the L like : 3123456789L
Where can you NOT use a underscore inside a number decleration.
Not at the start 001.0
Not at the end 001.0
Not next to a decimal. 001_.0
This is fine : 0_01.0 or 001_0
will this compile :
String reference = “hello”
int len = reference.length();
int bad = len.length();
It will not compile.
len is a primitive data type that we can not use to call methods. The method length can be called on the string because a string is not a primitive.
what is the difference between declaring a variable and initializing a variable.
A declared variable is not used yet, the java problem is simply aware of the variable and it can be initialized. Initializing the variable is the first time a value is assigned to this.
What is the correct syntax to declare and initialize a variable
=
String zooName = “Arits”;
or
int numberAnimals = 100;
what is a java identifier
this is the name of a variable method class interface package
what does a java identifier have to begin with
a letter : example
a $ symbol $example
a _ symbol _example
what are the special rules regarding numbers in identifier
they can be used in a identifier but can not be used as the first character.
not valid : 1example
valid example : example2
Can a single _ (underscore) be used as a identifier
no, this is not allowed in versions after java 9