What are the 2 types from Java?
Define the output
int i = 10 ; int j = 10;
if ( 10 > 9 | ( i++ > 9 ) {
System.out.println(i) // Output 1
}
if ( 10 > 9 || ( j++ > 9 ) {
System.out.println(j) // Output 2
}Define a long variable
long a5 = 10L
How to create a new object and access the name and balance method for Student class?
Student john = new Student(); john.name = "John Smith" john.balance = 12345
How to create a variable to define if 11 is greater than 12, if yes , the variable is 1, if no, the variable is -1
Use Ternary Expression
int i = 11 > 12 ? 1 : -1
What is the output for
~~~
System.out.println(‘a’ > ‘b’);
~~~
false
a in ASCII is 97, while b in ASCII is 98
How to define a float value?
float b2 = 9.9f
What is the type for
double a2 = 10.1F
Still double
How many of types that an Object have?
We can create our own types
What is the number range for byte value type
-128 to 127
8 bit
What is the number range for short value type?
-32,768 to 32767
16 bit
What is the number range for int value type?
-2³¹ to 2³¹ - 1
32 bit
What is the number range for long value type?
-2⁶³ to 2⁶³ - 1
64 bit
What is the difference between String and Char?
char a = ‘A’
What’s the difference between ++i and i++?
What is the output
int i = 5; System.out.println(++i);
i is incremented before being printed
What is the output
int i = 5; System.out.println(i++);
i is printed before being incremented
What will be the value of i and b?
int i = 5; int b = ++i;
What will be the value of i and b?
int i = 5; int b = i++;
What does this print?
int i = 10; System.out.println(i++); // ? System.out.println(++i); // ?
After the first print, it was added to 11 and was added to 12 before printing the second line
List out 8 value type primitive types
Why we can’t print
int y = 082504; System.out.println(y);
Because Java defined it as Octal numbers ( 0 at first ) , and since there are number 8 , which is greater than 7
What is the output for
System.out.println(071307);
How to use another class in different package?
public ClassB extends ClassA{
}