Java is one of the most popular programming languages in the world. It is simple, platform-independent, and widely used in software development. If you are new to programming, learning Java basics will give you a strong foundation. Let’s explore the key concepts step by step:
1. What is Java?
Java is a high-level, object-oriented, and
platform-independent programming language developed by Sun Microsystems (now
owned by Oracle).
- High-level → Easy to read and understand.
- Object-oriented → Based on real-world objects (like Car, Student,
BankAccount).
- Platform-independent → "Write once, run anywhere" using JVM (Java
Virtual Machine).
2. Features of Java
- Simple – Easy to learn compared to other programming
languages.
- Object-Oriented – Focuses on objects rather than functions.
- Platform Independent – Works on Windows, Mac, Linux, etc.
- Secure – Provides strong memory management and security features.
- Robust – Handles errors and exceptions smoothly.
- Multithreaded – Supports multiple tasks running at the same time.
3. Java Architecture
When you write and run Java code:
1. Source Code (.java file) → Written by the programmer.
2. Compiler (javac) → Converts Java code into Bytecode (.class file).
3. JVM (Java Virtual Machine) → Runs the bytecode on any platform.
This makes Java platform-independent. ✅
4. Basic Java Syntax Example
public class HelloWorld {
public static void main(String[]
args) {
System.out.println("Hello,
World!");
}
}
Explanation:
- public class HelloWorld → Defines a class.
- main(String[] args) → Entry point of any Java program.
- System.out.println() → Prints output to the screen.
5. Variables in Java
Variables are containers that store data values.
Example:
int age = 25; // Integer type
double price = 99.9; // Decimal number
String name = "John"; // Text
6. Data Types in Java
- Primitive Data Types: int, char, float, double, boolean,
byte, short, long.
- Non-Primitive Data Types: String, Arrays, Classes, Objects.
7. Operators in Java
Operators are symbols used to perform operations:
- Arithmetic Operators → + , - , * , / , %
- Relational Operators → == , != , > , < , >= , <=
- Logical Operators → && , || , !
8. Control Statements in Java
Used to control the flow of a program:
- if-else – Decision making
- switch – Multiple conditions
- for loop – Repeats a block of code
- while loop – Runs until condition is true
- do-while loop – Executes at least once
Example:
int num = 5;
if(num > 0){
System.out.println("Positive
Number");
} else {
System.out.println("Negative
Number");
}
9. Object-Oriented Concepts in Java
Java is built on OOPs (Object-Oriented Programming System).
The four main pillars are:
1. Encapsulation – Wrapping variables & methods into a single unit (class).
2. Inheritance – One class inherits properties of another.
3. Polymorphism – Same method behaves differently (overloading &
overriding).
4. Abstraction – Hiding implementation details and showing only functionality.
0 Comments