Java का इतिहास और विशेषताएँ
In this page:
History of Java
James Gosling ने Sun Microsystems में Java बनाने वाली team को lead किया, पहली बार इसे 1995 में Oak नाम के तहत release करके फिर Java नाम दिया -- शुरू से goal C++ का एक simpler, safer alternative था।
उदाहरण: History of Java
// Define the class Main
public class Main {
// Program entry point: the JVM starts running here
public static void main(String[] args) {
// Declare originalName and set it to "Oak"
String originalName = "Oak";
// Declare releaseYear and set it to "1995"
String releaseYear = "1995";
// Print a line to the console
System.out.println("Java was created by James Gosling at Sun Microsystems in " + releaseYear + ", originally named " + originalName + ".");
}
}
Login to try C/C++/Java/PHP code in the editor
Platform Independence
चूंकि compiler एक specific CPU के machine code के बजाय bytecode को target करता है, बिल्कुल वही compiled program JVM installed वाले किसी भी operating system पर unmodified चलता है।
उदाहरण: Platform Independence
public class Main {
public static void main(String[] args) {
// This same Main.class file runs unmodified on Windows, Linux, and macOS
System.out.println("Compiled once, runs on any OS with a JVM installed.");
}
}
Login to try C/C++/Java/PHP code in the editor
Object-Oriented Programming
Java आपको शुरू से अपने program को classes और objects के रूप में model करने पर मजबूर करती है, जो बड़ी problems को एक लंबे procedural script के बजाय छोटे, testable, reusable pieces में तोड़ने को प्रोत्साहित करती है।
उदाहरण: Object-Oriented Programming
// Define the class Task
class Task {
String name;
Task(String name) { this.name = name; }
void run() { System.out.println("Running: " + name); }
}
// Define the class Main
public class Main {
// Program entry point: the JVM starts running here
public static void main(String[] args) {
// Create a new Task object and store it in task
Task task = new Task("Send Email");
task.run();
}
}
Login to try C/C++/Java/PHP code in the editor
Robustness and Security
JVM bytecode को चलाने से पहले validate करता है, array bounds checking enforce करता है, और आपको memory corrupt करने के लिए कोई raw pointers नहीं देता -- ऐसे trade-offs जो कुछ raw speed को कहीं कम crash-causing bugs के लिए sacrifice करते हैं।
उदाहरण: Robustness and Security
public class Main {
public static void main(String[] args) {
int[] numbers = {1, 2, 3};
try {
System.out.println(numbers[5]); // out-of-bounds access
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Caught by JVM bounds checking: " + e.getMessage());
}
}
}
Login to try C/C++/Java/PHP code in the editor
Multi-threading Support
चूंकि threads language का एक first-class हिस्सा हैं (Thread class और java.util.concurrent के ज़रिए), आप genuinely independent tasks को parallel में चला सकते हैं ताकि एक CPU-bound या I/O-bound program responsive रहे।
उदाहरण: Multi-threading Support
// Define the class Main
public class Main {
// Program entry point: the JVM starts running here
public static void main(String[] args) throws InterruptedException {
// Create a new Thread object and store it in worker
Thread worker = new Thread(() -> System.out.println("Running independently on its own thread"));
// Start the thread; it runs in parallel with this code
worker.start();
// Wait for the thread to finish
worker.join();
}
}
Login to try C/C++/Java/PHP code in the editor
- यह कहना कि Java में pointers नहीं इसलिए इसमें memory problems नहीं, जब object references अब भी
nullहो सकते हैं औरNullPointerExceptionका कारण बन सकते हैं। - यह मान लेना कि "platform independent" का मतलब है वही
.javaबिना JDK के कहीं भी compile होती है, जब bytecode को target machine पर एक JVM चाहिए। - यह सोचना कि automatic garbage collection का मतलब है आप कभी memory leak नहीं कर सकते, जब referenced रहने वाले objects कभी free नहीं होते।
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: