0% found this document useful (0 votes)
80 views

OCA Java SE8: Boolean True Byte 123 Short 123 Int 123 Long 123 Float 123.45f Double 123.456 Char 'A'

The document summarizes key concepts from OCA Java SE8 Chapters 1-4. Chapter 1 defines Java primitive types and their values. It also discusses class accessibility, imports, and instance initializers. Chapter 2 covers Java operators and data type promotions. Chapter 3 discusses Strings and array equality. Chapter 4 notes that varargs parameters must be last and a method can only have one varargs parameter.

Uploaded by

Mihai Alexandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

OCA Java SE8: Boolean True Byte 123 Short 123 Int 123 Long 123 Float 123.45f Double 123.456 Char 'A'

The document summarizes key concepts from OCA Java SE8 Chapters 1-4. Chapter 1 defines Java primitive types and their values. It also discusses class accessibility, imports, and instance initializers. Chapter 2 covers Java operators and data type promotions. Chapter 3 discusses Strings and array equality. Chapter 4 notes that varargs parameters must be last and a method can only have one varargs parameter.

Uploaded by

Mihai Alexandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

OCA Java SE8

Chapter 1
If in a java file you have two classes defined, only one is allowed to be
PUBLIC.
In imports, you cannot import methods,ONLY class names.
Instance initializers= Braces that are outside a method.
Primitive types and their values:
Keyword Type Example
boolean true or false true
byte 8-bit integral value 123
short 6-bit integral value 123
int 32-bit integral value 123
long 64-bit integral value 123
float 32-bit floating-point value 123.45f
double 64-bit floating-point value 123.456
char 16-bit Unicode value 'a'

You can have underscores in numbers to make them easier to read:


Example: int million1 = 1000000;
int million2 = 1_000_000;

Reference types can be assigned null.


Primitive types will give you a compiler error if you attempt to assign them
null. In this example, value cannot point to null because it is of type int:
int value = null; // DOES NOT COMPILE
String s = null;

You can declare variables ONLY OF THE SAME TYPE in a single line.

Chapter 2-Java Operators

All of the arithmetic operators may be applied to any Java primitives, except boolean
and String.
Only the addition operators + and += may be applied to String
values, which results in String concatenation.
Smaller data types, namely byte, short, and char, are FIRST promoted to int any time
they’re used with a Java binary arithmetic operator, even if neither of the operands is
int.

Example:
!!!!!!What is the data type of x + y?
double x = 39.21;
float y = 2.1;
This is actually a trick question, as this code will not compile! As you may remember
from Chapter 1, fl oating-point literals are assumed to be double, unless postfi xed with
an f, as in 2.1f. If the value was set properly to 2.1f, then the promotion would be
similar to the last example, with both operands being promoted to a double, and the
result would be a double value.
Data types supported by switch statements include the following:
■ int and Integer

■ byte and Byte

■ short and Short

■ char and Character

■ int and Integer

■ String

■ enum values

Chapter 3

Strings
The equals() method checks whether two String objects contain exactly the same characters
in the same order. The equalsIgnoreCase() method checks whether two String
objects contain the same characters with the exception that it will convert the characters’
case if needed.

We can call equals() because an array is an object. It returns true because of reference
equality. The equals() method on arrays does not look at the elements of the array.
Remember, this would work even on an int[] too. int is a primitive; int[] is an object.

Chapter 4

If we have varargs in a parameter list, it must be put the LAST one and a method can only contain
one parameter of type varargs.

You might also like