This blog explains Java programming step by step in very simple English. Each topic is explained using easy words, so beginners, students, and freshers can understand clearly. Useful for interviews and basics.
1. What is Java?
Java is a popular programming language.
- Created by James Gosling
- Java is object-oriented
- Used to build web apps, mobile apps, desktop apps
👉 In simple words: Java helps us create applications that can run anywhere.
2. Why Learn Java?
- Very popular in jobs
- Platform independent
- Strong OOPS concepts
- Used in Android development
3. Features of Java
- Simple and secure
- Object-oriented
- Platform independent
- Automatic memory management
4. Java Program Structure
class Hello {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Simple explanation:
class→ used to create classmain()→ program starts hereSystem.out.println()→ prints output
5. Variables
Variables store values.
int age = 20;
👉 Here, age stores value 20.
6. Data Types
Data types tell Java what type of value we store.
| Data Type | Meaning |
|---|---|
| int | Whole number |
| float | Decimal |
| double | Large decimal |
| char | Single character |
| boolean | true / false |
7. Input and Output
Output
System.out.println("Welcome");
Input
import java.util.Scanner;
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
8. Operators
Operators perform operations.
- Arithmetic:
+ - * / % - Relational:
> < == != - Logical:
&& || ! - Assignment:
=
9. Conditional Statements
Used to make decisions.
if(age >= 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}
10. Switch Statement
Used when there are many choices.
switch(day) {
case 1: System.out.println("Monday"); break;
default: System.out.println("Invalid");
}
11. Loops
Loops repeat code.
for loop
for(int i = 1; i <= 5; i++) {
System.out.println(i);
}
while loop
while(i <= 5) {
i++;
}
12. Arrays
Arrays store multiple values.
int[] marks = {10, 20, 30};
OOPS Concepts in Java (Very Simple)
13. What is OOPS?
OOPS means Object-Oriented Programming System.
👉 Programming using classes and objects.
14. Class and Object
class Student {
int id;
String name;
}
Student s1 = new Student();
👉 Class is a blueprint, object is real.
15. Constructor
Constructor runs automatically when object is created.
class Test {
Test() {
System.out.println("Constructor called");
}
}
16. Encapsulation
Encapsulation means binding data and methods together.
👉 Data is protected using access modifiers.
17. Inheritance
Inheritance allows one class to use another class features.
class Parent {
void show() {}
}
class Child extends Parent {}
18. Polymorphism
Polymorphism means one method, many forms.
class A {
void show() {}
}
class B extends A {
void show() {}
}
19. Abstraction
Abstraction means hiding internal details.
👉 Achieved using abstract class or interface.
20. Interface
Interface is a blueprint of a class.
interface Test {
void show();
}
21. Exception Handling
Used to handle errors.
try {
int a = 10/0;
} catch(Exception e) {
System.out.println("Error");
}
22. File Handling (Basic)
Used to store data in files.
23. Advantages of Java
- Platform independent
- Secure
- Strong OOPS
24. Disadvantages of Java
- Slower than C/C++
- More code compared to Python
Advanced Java – Simple & Easy Guide
This section covers important Advanced Java topics often asked in interviews and used in real projects.
1. Java Collections Framework
Collections are used to store and manage groups of data easily.
Common Collection Interfaces
- List – Allows duplicate values (ArrayList, LinkedList)
- Set – Does NOT allow duplicates (HashSet)
- Map – Stores data as key-value pairs (HashMap)
Example: ArrayList
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<String> names = new ArrayList<>();
names.add("Krishna");
names.add("Raj");
names.add("Java");
System.out.println(names);
}
}
Why use Collections?
- Dynamic size
- Built-in methods
- Easy data handling
2. Multithreading
Multithreading means running multiple tasks at the same time.
Example: One program doing download + music + UI together.
Creating Thread using Thread class
class MyThread extends Thread {
public void run() {
System.out.println("Thread is running");
}
}
public class Main {
public static void main(String[] args) {
MyThread t1 = new MyThread();
t1.start();
}
}
Creating Thread using Runnable
class MyTask implements Runnable {
public void run() {
System.out.println("Runnable thread running");
}
}
public class Main {
public static void main(String[] args) {
Thread t = new Thread(new MyTask());
t.start();
}
}
Why Multithreading?
- Faster execution
- Better performance
3. JDBC (Java Database Connectivity)
JDBC is used to connect Java with a database like MySQL.
Steps in JDBC
- Load driver
- Create connection
- Execute query
- Close connection
JDBC Example
import java.sql.*;
public class Main {
public static void main(String[] args) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/testdb",
"root",
"password"
);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
while (rs.next()) {
System.out.println(rs.getString("name"));
}
con.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
Why JDBC?
- Store data permanently
- Used in web applications
4. File Handling in Java
File handling is used to read and write data into files.
Writing to a File
import java.io.FileWriter;
public class Main {
public static void main(String[] args) {
try {
FileWriter fw = new FileWriter("data.txt");
fw.write("Hello Java File Handling");
fw.close();
System.out.println("File written successfully");
} catch (Exception e) {
System.out.println(e);
}
}
}
Reading from a File
import java.io.File;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
try {
File file = new File("data.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine()) {
System.out.println(sc.nextLine());
}
sc.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
Why File Handling?
- Store logs
- Read configuration files
- Save user data
5. Why Advanced Java is Important
- Used in real-time applications
- Required for Java Developer jobs
- Frequently asked in interviews
Final Tip
If you understand:
- OOP Concepts
- Collections
- Multithreading
- JDBC
- File Handling
👉 You are job-ready Java beginner to intermediate level 🚀
Conclusion
Java is one of the most important programming languages. Learning Java builds strong OOPS knowledge and helps in software jobs and interviews.