← Back to Core Java Course | Chapter 1: Introduction & Basics | Lesson 2 of 12

Java का इतिहास और विशेषताएँ

Java इसलिए बनाई गई ताकि programs एक बार लिखे जा सकें और कई तरह के computers पर चल सकें। इसकी features इसे safe, organized, और एक साथ कई जॉब करने में सक्षम बनाती हैं।

History of Java

James Gosling ने Sun Microsystems में Java बनाने वाली team को lead किया, पहली बार इसे 1995 में Oak नाम के तहत release करके फिर Java नाम दिया -- शुरू से goal C++ का एक simpler, safer alternative था।

उदाहरण: History of Java

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 + ".");
	}
}

Platform Independence

चूंकि compiler एक specific CPU के machine code के बजाय bytecode को target करता है, बिल्कुल वही compiled program JVM installed वाले किसी भी operating system पर unmodified चलता है।

उदाहरण: Platform Independence

java
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.");
	}
}

Object-Oriented Programming

Java आपको शुरू से अपने program को classes और objects के रूप में model करने पर मजबूर करती है, जो बड़ी problems को एक लंबे procedural script के बजाय छोटे, testable, reusable pieces में तोड़ने को प्रोत्साहित करती है।

उदाहरण: Object-Oriented Programming

java
// 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();
	}
}

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

java
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());
		}
	}
}

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

java
// 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();
	}
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह कहना कि Java में pointers नहीं इसलिए इसमें memory problems नहीं, जब object references अब भी null हो सकते हैं और NullPointerException का कारण बन सकते हैं।
  2. यह मान लेना कि "platform independent" का मतलब है वही .java बिना JDK के कहीं भी compile होती है, जब bytecode को target machine पर एक JVM चाहिए।
  3. यह सोचना कि automatic garbage collection का मतलब है आप कभी memory leak नहीं कर सकते, जब referenced रहने वाले objects कभी free नहीं होते।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.