Variables and Data Types
Primitive Data Types
Numeric: int, float, double, long, short, byte
Non-numeric: char, boolean
Non-Primitive Data Types
Array
Strings
Custom-defined Data Types
Classes
Interfaces
Operators
Arithmetic Operators
+: Addition
-: Subtraction
*: Multiplication
/: Division
%: Modulus
Comparison Operators
>: Greater than
<: Less than
>=: Greater than or equal to
<=: Less than or equal to
==: Equal to
!=: Not equal to
Logical Operators
&&: Logical AND
||: Logical OR
!: Logical NOT
Assignment Operators
=: Simple assignment
+=: Add and assign
-=: Subtract and assign
*=: Multiply and assign
/=: Divide and assign
%=: Modulus and assign
Bitwise Operators
&: Bitwise AND
|: Bitwise OR
^: Bitwise XOR
~: Bitwise NOT
<<: Left shift
>>: Right shift
Type Casting
Implicit Type Casting
Automatically converts from one data type to another when the value of the original
data type is within the range of the target data type
Explicit Type Casting
Conversion is done manually by the programmer to convert from one data type to
another where the value of the original data type may not be within the range of
the target data type.
Types of Type Casting
Widening Casting
Narrowing Casting
User Input and Scanner Class
Scanner Class
Java class used to read user input
Imported via the statement import java.util.Scanner;
Object of Scanner class instantiated by Scanner input = new Scanner(System.in);