Java is a high-level, class-based, object-oriented programming language designed to be platform-independent.
Core Principle: Write Once, Run Anywhere (WORA)
Step 1: Source Code
Programmer Java code likhta hai aur use .java file mein save karta hai. Example:Hello.java
The programmer writes Java code and saves it in a .java file. Example:Hello.java
Step 2: Compilation
Java Compiler (javac) source code ko bytecode mein convert karta hai. Example:Hello.class
The Java Compiler (javac) converts source code into intermediate bytecode. Example:Hello.class
Step 3: JVM Execution
JVM bytecode ko execute karti hai. Isme Interpretation aur Just-In-Time (JIT) Compilation jaisi techniques upyog ki ja sakti hain.
The JVM executes the bytecode using Interpretation and Just-In-Time (JIT) Compilation.
Hello.java
classHello {
public static void main(String[] args) {
System.out.println("Hello, Java! Write Once, Run Anywhere.");
}
}
Expected Output
Hello, Java! Write Once, Run Anywhere.
Question 2 • Page 1
Main Features of Java
1. Simple:Seekhne aur likhne mein aasan syntax (no explicit pointers).Easy to learn and clean syntax without complex pointer arithmetic.
2. Object-Oriented:Har cheez class aur object par aadharit hoti hai.Everything is modeled around classes and objects.
3. Platform-Independent:Compatible JVM wale alag-alag platforms par chalta hai.Runs across different operating systems that have a compatible JVM.
4. Secure:Bytecode verification aur sandboxed JVM execution se surakshit.Protected by bytecode verification and JVM runtime security checks.
5. Robust:Exceptions aur automatic memory management (Garbage Collection) ki suvidhayein.Strong exception handling and automatic memory management.
6. Multithreaded:Multiple threads ke madhyam se concurrent execution.Supports concurrent execution using multiple threads.
7. Portable:Alag-alag platforms par bina badlav ke portability.Bytecode can be carried and executed on any platform without changes.
8. High Performance:JIT (Just-In-Time) compilation se performance behtar ho sakti hai.JIT compilation boosts execution speed close to native code.
Question 3 • Page 1
Why is Java Platform-Independent?
Java compiler source code ko seedhe kisi ek operating system ke machine code mein convert karne ke bajay bytecode mein badalta hai. Phir compatible JVM us bytecode ko execute karti hai. Isliye ek hi compiled Java program ko alag-alag operating systems par chalaya ja sakta hai.
Instead of compiling source code directly into OS-specific machine code, the Java compiler converts it into platform-neutral bytecode. Any OS with a compatible JVM can then execute that bytecode.
Example: Ek Java program ko Windows par compile karke Linux par bhi chalaya ja sakta hai, yadi target system par compatible Java Runtime (JRE/JVM) uplabdh ho!
Example: A Java program compiled on Windows into a .class file can run directly on Linux or macOS, provided a compatible Java Runtime is installed on the target system.