Java एनवायरनमेंट सेटअप
In this page:
What is the JDK?
JDK वह सब कुछ bundle करता है जो आपको Java software बनाने के लिए चाहिए: javac compiler, java launcher, debugging tools, और JRE (जिसमें खुद JVM और core class libraries हैं) सिर्फ compiled programs चलाने के लिए चाहिए।
उदाहरण: What is the JDK?
public class Main {
// The JDK provides: javac (compiler), java (launcher), debugging tools, and the JRE/JVM
public static void main(String[] args) {
System.out.println("Built and run using tools bundled in the JDK.");
}
}
Login to try C/C++/Java/PHP code in the editor
Writing Your Code
कोई भी plain text editor काम करता है, लेकिन IntelliJ IDEA, Eclipse, या Java extension pack वाले VS Code जैसे IDEs यहां असली value जोड़ते हैं -- autocomplete, inline error highlighting, और one-click running जो typos पकड़ना कहीं तेज़ बनाते हैं।
उदाहरण: Writing Your Code
public class Main {
// Written in an IDE like IntelliJ IDEA, Eclipse, or VS Code (Java extension pack)
public static void main(String[] args) {
System.out.println("Code written with autocomplete and inline error highlighting.");
}
}
Login to try C/C++/Java/PHP code in the editor
Saving Your File
Java इसके बारे में strict है: अगर आपकी file public class Calculator declare करती है, इसे बिल्कुल Calculator.java के रूप में save किया जाना चाहिए, case match करते हुए, नहीं तो compiler इसे build करने से मना कर देगा।
उदाहरण: Saving Your File
public class Calculator {
// This file MUST be saved as Calculator.java, matching the class name exactly (case-sensitive)
public static void main(String[] args) {
System.out.println("Saved as Calculator.java to match 'public class Calculator'.");
}
}
Login to try C/C++/Java/PHP code in the editor
Compiling Your Code
अपने terminal से javac filename.java चलाना आपका source पढ़ता है, इसे syntax और type errors के लिए जांचता है, और अगर यह clean है, उसी folder में JVM bytecode रखने वाली एक matching filename.class file emit करता है।
उदाहरण: Compiling Your Code
public class Main {
// Terminal: javac Main.java
// Checks syntax/types, then emits Main.class (JVM bytecode) in the same folder
public static void main(String[] args) {
System.out.println("Compiled with: javac Main.java");
}
}
Login to try C/C++/Java/PHP code in the editor
Running the Bytecode
java ClassName command (नोट: यहां .java या .class extension नहीं) उस bytecode file को load करता है और इसे JVM को सौंपता है, जो आपके program के main method से execute करना शुरू करता है।
उदाहरण: Running the Bytecode
public class Main {
// Terminal: java Main (no .java or .class extension)
public static void main(String[] args) {
System.out.println("Executed by the JVM starting from main().");
}
}
Login to try C/C++/Java/PHP code in the editor
- सिर्फ JRE setup करना, इसलिए
javacनहीं मिलता क्योंकि compiler JDK में है। - JDK
binfolder कोPATH(याJAVA_HOME) में न जोड़ना, इसलिएjavaऔरjavacrecognize नहीं होते। - Extension के साथ
java Hello.classचलाना, जब commandjava Helloहै।
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: