chapter 1_JavaBuildingBlocks Flashcards
- What are the primary elements in Java Class?
a. methods (functions)
b. fields, (variables)
- what are the 3 types of comments?
a. A single-line comment -> //
b. A multiple-line comment
- > /* Multiple
* line comment
* /
c. Javadoc comment
- > * Javadoc multiple-line comment
* @author Jeanne and Scott
* /
- what command need to run java
- javac .java
- java
- what java not import
- It doesn’t import child packages, fi elds, or methods; it imports only classes.
- what is special package that java automatically import
- java.lang.
- how many import that redundant?
1: import java.lang.System;
2: import java.lang.;
3: import java.util.Random;
4: import java.util.;
5: public class ImportExample {
6: public static void main(String[] args) {
7: Random r = new Random();
8: System.out.println(r.nextInt(10));
9: }
10: }
- three of the imports are redundant. Lines 1 and 2 are redundant because everything in java, Line 4 is also redundant in this example because Random is already imported from java.util.Random.
- What is constructor look like? can you give some example?
public class Chick { public Chick() { System.out.println("in constructor"); } }
- What is instance look like? can you give some example?
Random r = new Random();
- what is read and write variables is known as?
Reading a variable is known as getting it. Writing to a variable is known as setting it.
- What is ‘instace initializers’?
Code blocks that appear outside a method.
- Explain order of initialization
- Fields and instance initializer blocks are run in the order in which they appear in
the file. - The constructor runs after all fields and instance initializer blocks have run.
- how many built-in data types or Java primitive types, and state it.
Eight, which are boolean, byte, short, int, long, float, double and char
- Can you state all keyword and type contains in Java primitive type
a. boolean - true or false
b. byte - 8-bit integral value
c. short - 16-bit integral value
d. int - 32-bit integral value
e. long - 64-bit integral value
f. float - 32-bit floating-point value
g. double - 64-bit floating-point value
h. char - 16-bit Unicode value
- how many base can write in java, and how to write it
a. base 10 - System.out.println(56); // 56
b. binary - System.out.println(0b11); // 3
c. octal - System.out.println(017); // 15
d. hexadecimal - System.out.println(0x1F); // 31
- explain about numeric literals
can have underscores in numbers to make them easier to read, You can add
underscores anywhere except at the beginning of a literal, the end of a literal, right before a
decimal point, or right after a decimal point.