Java परिचय
In this page:
What is Java?
Java एक class-based, object-oriented language है जिसे बहुत कम implementation dependencies रखने के लिए design किया गया है, मतलब code जो एक platform पर सही चलता है उसे minimal changes के साथ किसी भी दूसरे पर भी वैसे ही चलना चाहिए।
उदाहरण: What is Java?
// Define the class Main
public class Main {
// Program entry point: the JVM starts running here
public static void main(String[] args) {
// Print a line to the console
System.out.println("Java is class-based and object-oriented.");
}
}
Login to try C/C++/Java/PHP code in the editor
Write Once, Run Anywhere
WORA का मतलब है आप एक Java program को एक बार bytecode में compile करते हैं, फिर उसी bytecode को Windows, Linux, या macOS पर बिना फिर compile किए चलाते हैं -- JVM आपके लिए platform-specific translation handle करता है।
उदाहरण: Write Once, Run Anywhere
public class Main {
// javac Main.java -> Main.class (bytecode)
// java Main runs identically on Windows, Linux, or macOS
public static void main(String[] args) {
System.out.println("Same bytecode runs on any OS with a JVM.");
}
}
Login to try C/C++/Java/PHP code in the editor
How Java Works
आपकी .java source file javac द्वारा .class bytecode files में compile होती है, और Java Virtual Machine उस bytecode को पढ़ता है और इसे instructions में translate करता है जो आपका specific CPU execute कर सके।
उदाहरण: How Java Works
public class Main {
// Step 1: Main.java (source)
// Step 2: javac Main.java -> Main.class (bytecode)
// Step 3: java Main -> JVM translates bytecode for your CPU
public static void main(String[] args) {
System.out.println("Compiled to bytecode, then run by the JVM.");
}
}
Login to try C/C++/Java/PHP code in the editor
Applications of Java
Java असली systems की एक बड़ी range को power देती है: Android app internals, banks और e-commerce companies में बड़े enterprise backends, और cloud services, काफी हद तक इसलिए क्योंकि इसका JVM और standard library scale पर mature और battle-tested हैं।
उदाहरण: Applications of Java
// Define the class Main
public class Main {
// Program entry point: the JVM starts running here
public static void main(String[] args) {
String[] uses = {"Android app internals", "Enterprise backends", "Cloud services"};
for (String use : uses) {
// Print a line to the console
System.out.println("Java powers: " + use);
}
}
}
Login to try C/C++/Java/PHP code in the editor
Benefits of Java
Portability से आगे, Java को इसके garbage collector के ज़रिए automatic memory management (इसलिए आप शायद ही कभी memory manually manage करते हैं) और strict compile-time type checking के लिए value दी जाती है, जो program चलने से पहले ही कई bugs पकड़ती है।
उदाहरण: Benefits of Java
public class Main {
public static void main(String[] args) {
String text = "auto-managed"; // no manual free() - garbage collector handles it
// int number = text; // fails at COMPILE time - type checking catches this early
System.out.println("Memory is " + text + " by the garbage collector.");
}
}
Login to try C/C++/Java/PHP code in the editor
- Java को JavaScript के साथ confuse करना, जब वे अलग uses और syntax वाली अलग languages हैं।
- सिर्फ JRE install करना और code compile करने की उम्मीद करना, जब
javacसे compile करने के लिए JDK चाहिए। - यह सोचना कि Java सीधे machine पर चलता है, जब source bytecode में compile होता है जिसे JVM चलाता है।
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: