ChatGPT said:
Here’s a useful 2-page Java PDF content — clean,
educational, and ready to convert to a PDF for notes or
assignment submission.
It focuses on “Core Java Concepts with Examples”, enough to
fill two A4 pages neatly.
Core Java Concepts and Examples
1. Introduction to Java
Java is a high-level, object-oriented, platform-independent
programming language developed by Sun Microsystems (now
Oracle).
Its “Write Once, Run Anywhere (WORA)” principle allows
Java code to run on any device that supports the Java Virtual
Machine (JVM).
Features:
Simple and secure
Platform-independent
Object-oriented
Robust and portable
Supports multithreading
2. Structure of a Java Program
A basic Java program consists of:
A class definition
A main() method
Statements enclosed within {}
Example:
class HelloWorld {
public static void main(String[] args)
{
System.out.println("Hello, Java!");
}
}
Explanation:
class – Defines a blueprint.
main() – Entry point of every Java application.
System.out.println() – Prints text to the console.
3. Data Types and Variables
Java has two types of data:
1. Primitive Types: int, float, char, boolean, etc.
2. Non-Primitive Types: String, Array, Class,
Interface.
Example:
int age = 21;
float height = 5.8f;
char grade = 'A';
boolean isPass = true;
String name = "Jeyasri";
4. Control Statements
Java supports decision-making and looping constructs.
Decision Making:
if(age >= 18)
System.out.println("Eligible to vote");
else
System.out.println("Not eligible");
Loops:
for(int i = 1; i <= 5; i++) {
System.out.println("Count: " + i);
}
5. Object-Oriented Programming Concepts
Concept Description Example
class Student {
Class Blueprint for objects
}
Student s1 =
Object Instance of a class
new Student();
Data hiding using
Encapsulation private int id;
getters/setters
Acquiring properties of class Child
Inheritance
another class extends Parent
Concept Description Example
{ }
display(int a) /
Many forms (method
Polymorphism display(String
overloading/overriding)
b)
Hiding implementation abstract class
Abstraction
details Shape {}
6. Example: Class and Object
class Student {
String name;
int age;
void displayInfo() {
System.out.println(name + " - " +
age + " years old");
}
public static void main(String[] args)
{
Student s1 = new Student();
s1.name = "Ananya";
s1.age = 20;
s1.displayInfo();
}
}
7. Exception Handling
Used to handle runtime errors gracefully.
Example:
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Error: Division by
zero!");
} finally {
System.out.println("Program
continues...");
}
8. File Handling
Java uses classes like FileReader, BufferedReader,
FileWriter for reading and writing files.
Example:
import java.io.*;
class FileExample {
public static void main(String[] args)
throws IOException {
FileWriter fw = new
FileWriter("output.txt");
fw.write("Hello Java File!");
fw.close();
System.out.println("File created
successfully.");
}
}
9. Collections Framework
Java provides predefined data structures in the java.util
package.
Example using ArrayList:
import java.util.*;
class CollectionExample {
public static void main(String[] args)
{
ArrayList<String> list = new
ArrayList<>();
list.add("Java");
list.add("Python");
list.add("C++");
for(String lang : list)
System.out.println(lang);
}
}
10. Threads and Concurrency
Threads allow multiple tasks to run concurrently.
Example:
class MyThread extends Thread {
public void run() {
for(int i = 1; i <= 3; i++)
System.out.println("Running
thread: " + i);
}
public static void main(String[] args)
{
MyThread t = new MyThread();
t.start();
}
}
11. Conclusion
Java remains one of the most versatile and secure
programming languages, powering web apps, Android apps,
and enterprise software.
Its strong OOP base, large standard library, and portability make
it essential for every developer to learn.