Java Reference
The Java Reference section provides a quick and structured
overview of important Java concepts, syntax, keywords, classes, and commonly used methods.
It is designed to help students revise topics quickly and find definitions or examples
without reading long explanations.
This reference guide is especially useful for exam preparation, interviews,
and last-minute revision.
1. Java Basic Syntax
Every Java program starts with a class and a main method.
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
2. Java Data Types
Java supports two types of data types:
- Primitive Data Types – int, double, float, char, boolean, byte, short, long
- Non-Primitive Data Types – String, Arrays, Classes, Interfaces
int age = 20;
double price = 99.99;
char grade = 'A';
boolean isPassed = true;
3. Java Operators
- Arithmetic: +, -, *, /, %
- Relational: ==, !=, >, <, >=, <=
- Logical: &&, ||, !
- Assignment: =, +=, -=, *=
4. Java Control Statements
Control statements are used to control the flow of execution.
- if, if-else, switch
- for loop, while loop, do-while loop
- break, continue
for(int i = 1; i <= 5; i++){
System.out.println(i);
}
5. Java OOP Concepts
- Class – Blueprint of an object
- Object – Instance of a class
- Inheritance – Acquiring properties of another class
- Polymorphism – Many forms of a method
- Encapsulation – Wrapping data and methods together
- Abstraction – Hiding implementation details
class Person {
String name;
void display() {
System.out.println(name);
}
}
6. Java Arrays
Arrays are used to store multiple values of the same data type.
int[] numbers = {1, 2, 3, 4};
System.out.println(numbers[0]);
7. Java Strings
The String class is used to handle text in Java.
String text = "Java";
System.out.println(text.length());
System.out.println(text.toUpperCase());
8. Java Exception Handling
Exception handling prevents runtime errors from crashing the program.
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Error occurred");
}
9. Java Collections
The Java Collections Framework provides classes like ArrayList, HashSet, and HashMap
to store and manipulate groups of objects.
import java.util.ArrayList;
ArrayList<String> list = new ArrayList<>();
list.add("Java");
list.add("Python");
System.out.println(list);
10. Java Keywords (Commonly Used)
- public
- private
- protected
- static
- final
- class
- interface
- extends
- implements
- return
Why Java Reference is Important?
- Quick revision before exams
- Helpful for coding practice
- Useful during interviews
- Provides structured overview of Java
- Saves time while revising concepts
Helpful Tip: Keep practicing examples from each section.
Java Reference is best used along with hands-on coding practice.