तुम्ही Java install आणि development setup पूर्ण केला आहे असे गृहित धरून आता आपण आपला पहिला actual Java program लिहिणार आहोत.
या chapter मध्ये फक्त Hello World print करून थांबायचे नाही. Program लिहिताना प्रत्येक line का आहे, class म्हणजे काय, main() कुठून येते, statement कसे ओळखायचे, comments कशासाठी असतात आणि source code compile होऊन run कसा होतो हे logically समजून घेणार आहोत.
Version Note: September 5, 2026 पर्यंत Java SE 26 हा latest released feature release आहे आणि Java 25 हा current LTS release आहे. या chapter मधील traditional Java program structure दोन्हीवर valid आहे.
1. Learning Outcomes#
हा chapter पूर्ण केल्यानंतर तुम्ही independently:
- basic Java program लिहू शकाल.
- Java source file मधील
class,main()method, statements आणि comments identify करू शकाल. public class HelloWorldया declaration चा basic अर्थ explain करू शकाल.- traditional
main()method मधीलpublic,static,void,String[] argsयांचा beginner-level purpose सांगू शकाल. System.out.println()वापरून console वर output print करू शकाल.- Java statement आणि semicolon यांचा संबंध समजू शकाल.
- single-line, multi-line आणि documentation comments ओळखू शकाल.
.javasource file compile करून.classfile तयार करू शकाल.javacआणिjavacommands मधील फरक सांगू शकाल.- basic compilation errors diagnose करू शकाल.
- Java program चा basic execution flow explain करू शकाल.
2. Hello World Program#
आपण सर्वात आधी complete program पाहू.
A Java program is a set of Java instructions organized according to Java language syntax to perform a specific task.
म्हणजे Java program हा Java language च्या rules प्रमाणे लिहिलेल्या instructions चा collection असतो. त्या instructions वापरून आपण computer कडून specific काम करून घेतो.
सुरुवातीला आपले requirement खूप simple आहे:
Requirement: Terminal वर Hello, World! print करायचे.Java#
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}Expected Output#
Hello, World!Program छोटा आहे, पण या पाच-सहा lines मध्ये Java चे अनेक fundamental concepts आहेत.
आपण program पाठ करणार नाही.
आपण त्याला break करून समजून घेणार आहोत.
3. Java Program Structure#
Program structure is the organized arrangement of declarations, methods, statements, and blocks that form a Java program.
Java program structure म्हणजे program मधील वेगवेगळे parts कोणत्या logical arrangement मध्ये लिहिले जातात ते.
आपल्या program कडे पुन्हा पाहा:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}याची simplified structure अशी आहे:
Class
│
└── main() Method
│
└── StatementActual code शी map केले तर:
public class HelloWorld
│
│ public static void main(String[] args)
│ │
│ │ System.out.println("Hello, World!");
│ │
│ └── main() method ends
│
└── class endsआता प्रत्येक part independently समजून घेऊ.
4. Class Declaration#
A class declaration defines a class by specifying its name and body.
Class declaration म्हणजे Java मध्ये class define करणारी declaration.
आपल्या program मधील:
public class HelloWorld {ही line class declare करते.
ती तीन important parts मध्ये पाहता येते:
public class HelloWorld
│ │ │
modifier keyword class name4.1 class Keyword#
The class keyword is used to declare a class in Java.
class हा Java चा reserved keyword आहे.
Keyword म्हणजे Java language ने आधीच specific purpose साठी reserve केलेला word.
उदाहरण:
class HelloWorld {
}येथे Java compiler ला सांगितले जाते:
HelloWorld नावाची class define केली जात आहे.या chapter मध्ये class ची object-oriented programming level ची deep theory आवश्यक नाही.
आत्ता एवढे लक्षात ठेवा:
Java applications मध्ये code सामान्यतः classes मध्ये organize केला जातो.
4.2 Class Name#
आपल्या code मध्ये:
HelloWorldहे class चे नाव आहे.
Class names लिहिताना सामान्य Java naming convention म्हणजे PascalCase.
उदाहरण:
HelloWorld
EmployeePortal
CourseManagement
StudentRegistrationPascalCase मध्ये प्रत्येक meaningful word capital letter ने सुरू होतो.
उदाहरण:
hello world ❌
helloworld ❌
HelloWorld ✅Naming convention compiler rule नसतो, पण professional Java code readable ठेवण्यासाठी तो महत्त्वाचा असतो.
4.3 public#
public is an access modifier that makes a declared program element accessible from other code where Java access rules permit it.
public हा access modifier आहे.
Access modifier म्हणजे code मधील एखादा element कुठून access करता येईल यावर control करणारा modifier.
आत्ता access modifiers detail मध्ये शिकायचे नाहीत.
आपल्या beginner program मध्ये:
public class HelloWorldअशी traditional structure वापरणार आहोत.
4.4 Curly Braces { }#
Class declaration नंतर:
{आणि शेवटी:
}असतात.
यांना curly braces म्हणतात.
Curly braces code चा block define करतात.
public class HelloWorld {
// class body
}Opening brace:
{block सुरू करते.
Closing brace:
}block समाप्त करते.
Beginner Trick#
Braces mentally pair करा:
public class HelloWorld { // class starts
public static void main(String[] args) { // main starts
System.out.println("Hello");
} // main ends
} // class endsIndentation compiler साठी नेहमी mandatory नसली तरी developer साठी अत्यंत महत्त्वाची आहे.
5. Source File Name and Class Name#
आपली class:
public class HelloWorldअसेल तर source file चे नाव असावे:
HelloWorld.javaकारण top-level class public असल्यास source filename आणि public class name match करणे आवश्यक आहे.
Correct#
File:
HelloWorld.java
Class:
public class HelloWorldIncorrect#
File:
Demo.java
Class:
public class HelloWorldCompile करण्याचा प्रयत्न केल्यास compiler filename/class-name mismatch report करेल.
Must Know#
Java case-sensitive आहे.
त्यामुळे:
HelloWorld
helloworld
HELLOWORLDहे तीन identical identifiers नाहीत.
6. main() Method#
आता program मधील सर्वात important line पाहू:
public static void main(String[] args) {A main method is a launchable entry method that the Java launcher can invoke to start a Java program.
Beginner perspective मधून main() हा program execution सुरू होण्याचा entry point समजा.
आपण या course मध्ये widely used traditional form वापरणार आहोत:
public static void main(String[] args)त्याला parts मध्ये break करू:
public static void main (String[] args)
│ │ │ │ │
access modifier return method parameter
type nameसगळे एकदम memorize करू नका.
एकेक part समजून घेऊ.
6.1 main#
mainहे method चे नाव आहे.
Java program launch करताना launcher launchable main method शोधतो.
या chapter साठी आपण conventional:
public static void main(String[] args)ही form वापरणार आहोत.
Current Java Accuracy Note#
Java 25 पासून Java मध्ये simplified आणि instance main methods सुद्धा supported आहेत. उदाहरणार्थ current Java versions मध्ये काही programs void main() सारख्या forms नेही launch होऊ शकतात. पण traditional public static void main(String[] args) अजूनही valid आहे आणि existing Java projects समजण्यासाठी अत्यंत महत्त्वाची आहे. त्यामुळे beginner foundation साठी आपण traditional form शिकत आहोत.
7. What is a Method?#
main() समजण्यापूर्वी method हा word समजून घेऊ.
A method is a named block of code that performs a specific task.
Method म्हणजे specific काम करण्यासाठी लिहिलेला named code block.
उदाहरण:
public static void main(String[] args) {
System.out.println("Hello");
}येथे:
mainहे method चे नाव.
आणि:
{
System.out.println("Hello");
}हा त्याचा body.
Methods आपण पुढील chapters मध्ये detail मध्ये शिकू.
8. public in main()#
publicहा access modifier आहे.
Traditional main() signature मध्ये तो method ला public access देतो.
Access control पुढे detail मध्ये शिकणार असल्यामुळे आत्ता:
public म्हणजे method openly accessible आहे.इतके understanding पुरेसे आहे.
9. static in main()#
static declares a member that belongs to the class rather than requiring a specific object instance.
Beginner level वर:
staticमुळे traditional main() method execute करण्यासाठी आधी त्या class चा object manually create करण्याची गरज पडत नाही.
Objects आणि static concept पुढे व्यवस्थित शिकणार आहोत.
आत्ता फक्त role ओळखा.
10. void#
void indicates that a method does not return a value.
void म्हणजे method execution पूर्ण झाल्यावर caller ला कोणतीही value return करत नाही.
आपल्या program मध्ये:
public static void main(...)म्हणजे main() method ची return type void आहे.
Return values पुढील chapters मध्ये शिकू.
11. String[] args#
String[] argsहा main() method चा parameter आहे.
A parameter is an input declared by a method so that data can be provided to it when it is invoked.
Parameter म्हणजे method ला data receive करण्यासाठी declare केलेला input.
Traditional main() मध्ये:
String[] argscommand-line वरून आलेल्या text arguments receive करण्यासाठी वापरला जाऊ शकतो.
या chapter मध्ये arrays किंवा variables detail मध्ये शिकायचे नाहीत.
फक्त structure ओळखा:
String[] argsहा traditional main() method चा parameter आहे.
12. The main() Body#
Complete main method:
public static void main(String[] args) {
System.out.println("Hello, World!");
}Opening:
{main block सुरू करते.
Closing:
}main block end करते.
या braces च्या आत executable statements लिहिले जातात.
13. Statements#
आपली actual काम करणारी line:
System.out.println("Hello, World!");ही एक statement आहे.
A statement is a complete instruction that performs an action in a Java program.
Statement म्हणजे Java program ला specific action perform करण्यासाठी दिलेली complete instruction.
उदाहरण:
System.out.println("Hello");ही instruction Java ला सांगते:
console वर Hello print कर.14. Understanding System.out.println()#
आता ही line visually break करू:
System.out.println("Hello, World!");
│ │ │
│ │ └── print a line
│ └─────── standard output
└────────────── System class14.1 System#
Systemहा Java च्या standard library मधील class आहे.
Standard library म्हणजे Java सोबत उपलब्ध असलेल्या ready-made classes आणि functionality चा collection.
14.2 out#
System.outमध्ये out standard output दर्शवतो.
Simple terminal application मध्ये standard output म्हणजे साधारणतः terminal/console.
14.3 println()#
println() prints data to standard output and then terminates the current output line.
println() content print करते आणि त्यानंतर पुढील output नवीन line वर सुरू होईल अशी line termination करते.
उदाहरण:
System.out.println("Java");
System.out.println("Course");Output:
Java
Courseकारण प्रत्येक println() नंतर पुढील output next line वर जातो.
15. Multiple Statements#
Method मध्ये एकापेक्षा जास्त statements लिहू शकतो.
public class CourseApplication {
public static void main(String[] args) {
System.out.println("CodeLangs AI");
System.out.println("Java Beginner Course");
System.out.println("Application Started");
}
}Expected Output#
CodeLangs AI
Java Beginner Course
Application StartedProgram top-to-bottom execute होत असल्यामुळे statements sequence मध्ये execute होतात.
Beginner level वर:
Statement 1
↓
Statement 2
↓
Statement 316. Semicolon ;#
वरील statements च्या शेवटी:
;आहे.
उदाहरण:
System.out.println("Hello");A semicolon terminates many kinds of Java statements.
Java मधील अनेक statements चा end ; ने दर्शवला जातो.
Correct#
System.out.println("Hello");Incorrect#
System.out.println("Hello")जर semicolon आवश्यक असलेल्या ठिकाणी missing असेल तर compilation error येईल.
उदाहरण compiler diagnostic:
';' expectedImportant#
प्रत्येक Java line नंतर semicolon असतो असे समजू नका.
उदाहरण:
public class HelloWorld {या line नंतर semicolon नाही.
तसेच:
public static void main(String[] args) {या declaration नंतरही semicolon नाही.
म्हणून:
Semicolon line चा end दाखवत नाही; तो specific Java statements/declarations चा terminator असतो.
17. Comments#
Professional code मध्ये फक्त executable instructions नसतात. Developers काही ठिकाणी human-readable explanation सुद्धा लिहितात.
त्यासाठी comments वापरतात.
A comment is non-executable text written in source code to provide information for people reading the code.
Comment म्हणजे developer साठी लिहिलेली explanation/note जी program instruction म्हणून execute होत नाही.
Java मध्ये beginner ने तीन comment forms ओळखाव्यात.
18. Single-Line Comment#
Single-line comment:
// textउदाहरण:
public class HelloWorld {
public static void main(String[] args) {
// Display welcome message
System.out.println("Hello, World!");
}
}// नंतर त्या line वर लिहिलेला text comment म्हणून treat होतो.
Use case:
// Start the application19. Multi-Line Comment#
अनेक lines चा comment लिहायचा असल्यास:
/*
comment
*/उदाहरण:
/*
This program demonstrates
the basic Java program structure.
*/
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}Start:
/*End:
*/20. Documentation Comment#
Java मध्ये documentation comments सुद्धा आहेत.
/**
* Displays a simple welcome message.
*/A documentation comment is a special comment form that can be processed by Java documentation tools such as javadoc.
हे comments API/documentation generate करण्यासाठी उपयोगी पडतात.
उदाहरण:
public class HelloWorld {
/**
* Starts the program.
*/
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}या chapter मध्ये javadoc deep मध्ये शिकायचे नाही.
फक्त फरक ओळखा:
// Single-line comment
/* */ Multi-line comment
/** */ Documentation comment21. Good Comments vs Bad Comments#
Comment ने obvious code फक्त repeat करू नये.
Weak Comment#
// Print Hello
System.out.println("Hello");इथे code स्वतःच स्पष्ट आहे.
More Useful Context#
// Display the message shown when the training application starts
System.out.println("Training Portal Started");Professional principle:
Comments should add useful context, not merely translate obvious code into English.
22. Complete Program Revisited#
आता पुन्हा तोच program पाहू.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}आता प्रत्येक part समजला पाहिजे:
public
access modifier
class
class declaration keyword
HelloWorld
class name
{
class body begins
public static void main(String[] args)
traditional main method declaration
{
main method body begins
System.out.println("Hello, World!");
executable statement
;
statement terminator
}
main method ends
}
class ends23. How Java Program Execution Flows#
आता source code computer पर्यंत कसा पोहोचतो ते समजून घेऊ.
आपण लिहितो:
HelloWorld.javaही source file आहे.
Source code is human-readable program code written in a programming language.
आपल्या case मध्ये source code Java मध्ये लिहिला आहे.
Execution flow:
HelloWorld.java
│
│ javac
▼
HelloWorld.class
│
│ java
▼
Java runtime executes the program
│
▼
Hello, World!24. Compile a Java Program#
Compilation is the process of translating Java source code into Java class-file bytecode while checking applicable language rules.
Java source file compile करण्यासाठी सामान्यतः javac command वापरतो.
Suppose file आहे:
HelloWorld.javaTerminal त्या directory मध्ये open करा.
Bash / Terminal#
javac HelloWorld.javaCommand successful असल्यास अनेक cases मध्ये terminal वर काही message दिसणार नाही.
पण directory मध्ये नवीन file तयार होईल:
HelloWorld.class25. What is Bytecode?#
Bytecode is the instruction format stored in Java class files for execution by the Java Virtual Machine.
Compile केल्यानंतर .class file मध्ये Java source code सारखा human-readable source नसतो.
त्यात JVM साठी instruction format असतो ज्याला bytecode म्हणतात.
या chapter मध्ये bytecode किंवा JVM internals शिकायचे नाहीत.
फक्त flow समजा:
.java source
↓
javac
↓
.class bytecode26. Run the Java Program#
Compilation successful झाल्यानंतर:
java HelloWorldलक्षात घ्या:
java HelloWorldइथे:
.javaलिहिलेले नाही.
Expected output:
Hello, World!27. javac vs java#
हा interview आणि practical दोन्हींसाठी important difference आहे.
| Command | Primary Purpose | Example |
|---|---|---|
javac | Java source code compile करणे | javac HelloWorld.java |
java | Java application launch/run करणे | java HelloWorld |
Simple memory trick:
javac = compile
java = run28. Complete Compile and Run Flow#
Step 1
Write code
↓
HelloWorld.java
Step 2
Compile
↓
javac HelloWorld.java
Step 3
Class file generated
↓
HelloWorld.class
Step 4
Run
↓
java HelloWorld
Step 5
Output
↓
Hello, World!29. Direct Source-File Execution — Good to Know#
Current Java versions source file directly launch करू शकतात.
उदाहरण:
java HelloWorld.javaJava launcher source file compile करून program launch करू शकतो.
पण beginner म्हणून खालील explicit process आधी चांगला समजून घ्या:
javac HelloWorld.java
java HelloWorldकारण यामुळे compilation आणि execution हे दोन वेगळे stages आहेत हे clearly समजते.
30. What Happens When Compilation Fails?#
Consider:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello")
}
}इथे semicolon missing आहे.
Compile:
javac HelloWorld.javaCompiler source code validate करतो.
Syntax चुकीची असल्यामुळे .class file successfully generate होणार नाही.
तुम्हाला diagnostic मिळू शकतो:
error: ';' expectedFlow:
Source Code
↓
Compiler
↓
Syntax problem found
↓
Compilation failed
↓
Fix code
↓
Compile againDeveloper workflow मध्ये errors येणे normal आहे.
महत्त्वाचे skill म्हणजे error systematically diagnose करणे.
31. Practical / Real-World Application#
Hello World हा learning example आहे.
Real project मध्ये program startup messages, CLI tools, migration utilities, scheduled jobs किंवा small administrative programs console output वापरू शकतात.
Suppose requirement आहे:
Training application start झाल्यावर application name आणि startup status console वर दाखवा.
Analysis#
आपल्याला अजून variables किंवा conditions आवश्यक नाहीत.
फक्त multiple output statements पुरेसे आहेत.
Java#
public class TrainingApplication {
public static void main(String[] args) {
// Display startup information
System.out.println("CodeLangs AI Training System");
System.out.println("Java Beginner Course");
System.out.println("Application Started Successfully");
}
}Expected Output#
CodeLangs AI Training System
Java Beginner Course
Application Started SuccessfullyCompile#
javac TrainingApplication.javaRun#
java TrainingApplicationयातून तुम्ही शिकलेले चार concepts एकत्र वापरले:
Class
+
main() method
+
Statements
+
Comment32. Reading an Unknown Beginner Java Program#
Interview किंवा project मध्ये unfamiliar code दिसल्यास वरून खाली scan करा.
उदाहरण:
public class PaymentApplication {
public static void main(String[] args) {
// Application startup message
System.out.println("Payment Application");
System.out.println("System Ready");
}
}Reading strategy:
Step 1 — Class शोधा#
public class PaymentApplicationClass name:
PaymentApplicationStep 2 — Entry method शोधा#
public static void main(String[] args)Step 3 — Statements पहा#
System.out.println("Payment Application");
System.out.println("System Ready");Step 4 — Comments पहा#
// Application startup messageStep 5 — Expected output reason करा#
Payment Application
System Readyही code-reading habit सुरुवातीपासून build करा.
33. Common Mistakes & Misconceptions#
Mistake 1 — Filename and Public Class Name Do Not Match#
Wrong#
File:
Demo.javaCode:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello");
}
}Symptom#
Compilation error.
Root Cause#
public class HelloWorld असल्यामुळे source filename HelloWorld.java असणे आवश्यक आहे.
Fix#
File rename करा:
HelloWorld.javaPrevention#
Public class तयार करताना लगेच matching filename वापरा.
Mistake 2 — Missing Semicolon#
Wrong#
System.out.println("Hello")Symptom#
Compiler diagnostic similar to:
';' expectedFix#
System.out.println("Hello");Mistake 3 — Wrong Letter Case#
Wrong#
system.out.println("Hello");Correct#
System.out.println("Hello");Java case-sensitive आहे.
Systemआणि:
systemidentical नाहीत.
Mistake 4 — Wrong main Spelling#
Wrong#
public static void Main(String[] args)Traditional program structure मध्ये method name:
mainlowercase ने लिहा.
Correct#
public static void main(String[] args)Mistake 5 — Wrong Compile Command#
Wrong#
javac HelloWorldCorrect#
javac HelloWorld.javajavac source filename घेतो.
Mistake 6 — Wrong Run Command#
Common Beginner Mistake#
java HelloWorld.javaCurrent Java versions मध्ये source-file mode मुळे ही command चालू शकते, त्यामुळे ती universally “wrong” नाही.
पण explicit compile-then-run workflow मध्ये expected command आहे:
java HelloWorldजेव्हा javac HelloWorld.java वापरून .class तयार केलेली आहे.
हा distinction समजणे महत्त्वाचे आहे.
Mistake 7 — Assuming Every Line Ends with ;#
Misconception#
Java मध्ये प्रत्येक line नंतर semicolon असतो.
Why It Sounds Believable#
अनेक executable statements ; ने end होतात.
Correct Understanding#
Semicolon specific statements/declarations terminate करतो.
उदाहरण:
System.out.println("Hello");पण:
public class HelloWorld {नंतर semicolon नाही.
Mistake 8 — Thinking Comments Execute#
Misconception#
// System.out.println("Hello");हे output print करेल.
Correct Understanding#
ही line comment असल्यामुळे executable Java statement म्हणून run होत नाही.
Mistake 9 — Memorizing main() Without Understanding It#
Beginners अनेकदा:
public static void main(String[] args)फक्त पाठ करतात.
Better approach:
public → access modifier
static → class-level method form used here
void → no return value
main → launchable method name
String[] args → command-line arguments parameterDeep concepts पुढे शिकू, पण basic responsibility आत्ताच स्पष्ट ठेवा.
34. Hands-On Practice#
Practice 1 — Your First Program#
Problem#
Console वर खालील output दाखवा:
Welcome to Java
My First Java ProgramLearner Task#
MyFirstProgram.java नावाची file तयार करा.
Constraints:
- class name
MyFirstProgram - traditional
main()method वापरा - exactly two
println()statements वापरा
Attempt करा.
Hint 1#
Class declaration:
public class MyFirstProgram {
}Hint 2#
Class मध्ये main() method add करा.
Solution#
public class MyFirstProgram {
public static void main(String[] args) {
System.out.println("Welcome to Java");
System.out.println("My First Java Program");
}
}Compile#
javac MyFirstProgram.javaRun#
java MyFirstProgram35. Practice 2 — Training Portal Startup#
Requirement#
Program output:
Training Portal
Java Course
Ready to Learnआणि statements च्या आधी useful single-line comment लिहा.
Solution#
public class TrainingPortal {
public static void main(String[] args) {
// Display training portal startup information
System.out.println("Training Portal");
System.out.println("Java Course");
System.out.println("Ready to Learn");
}
}36. Practice 3 — Find the Bug#
हा program compile होत नाही:
public class CoursePortal {
public static void main(String[] args) {
System.out.println("Course Portal")
System.out.println("Ready");
}
}Your Task#
Problem identify करा.
Answer#
पहिल्या statement नंतर semicolon missing आहे.
Corrected Code#
public class CoursePortal {
public static void main(String[] args) {
System.out.println("Course Portal");
System.out.println("Ready");
}
}37. Practice 4 — Predict Execution Order#
public class Application {
public static void main(String[] args) {
System.out.println("Start");
System.out.println("Processing");
System.out.println("Complete");
}
}Program output आधी स्वतः लिहा.
Correct Output#
Start
Processing
CompleteStatements top-to-bottom execute होतात.
38. Interview Preparation#
Q1. What is the basic structure of a traditional Java program?#
A traditional beginner Java program commonly contains a class declaration, a main() method, and executable statements inside the main() method.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello");
}
}What the interviewer is testing: Whether you can identify the structural parts of a basic Java application.
Q2. What is the purpose of the main() method in Java?#
The main() method can act as the entry method used by the Java launcher to start a program. A widely used traditional form is:
public static void main(String[] args)Modern Java versions also support additional launchable main method forms, but the traditional form remains valid and common.
Common weak answer: “The JVM always requires exactly public static void main(String[] args).”
That statement is no longer fully accurate for Java 25 and later.
Q3. What does public mean in public class HelloWorld?#
public is an access modifier. It specifies public accessibility for the declared class, subject to Java's access rules.
Q4. What does static mean in the traditional main() method?#
static means the method belongs to the class rather than requiring a specific object instance. In the traditional startup form, this allows the method to be invoked without first creating an object of the class.
Q5. What does void mean in the main() method?#
void means the method does not return a value.
Q6. What is String[] args in the traditional main() method?#
String[] args is a parameter that can receive command-line arguments as strings.
For a beginner, it is enough to understand its purpose without going deeply into arrays yet.
Q7. What is a Java statement?#
A Java statement is a complete instruction that performs an action.
Example:
System.out.println("Hello");Q8. What is the purpose of a semicolon in Java?#
A semicolon terminates many Java statements.
Example:
System.out.println("Hello");It is incorrect to say that every line in Java must end with a semicolon.
Q9. What does System.out.println() do?#
System.out.println() writes data to standard output and terminates the current output line so subsequent output normally begins on a new line.
Q10. What is the difference between javac and java?#
javac compiles Java source code into class files.
javac HelloWorld.javajava launches a Java program.
java HelloWorldQ11. What is generated after compiling HelloWorld.java?#
Normally, compiling a class named HelloWorld produces:
HelloWorld.classThe class file contains Java bytecode.
Q12. What is Java bytecode?#
Java bytecode is the instruction format stored in Java class files for execution by the Java Virtual Machine.
Q13. Why should a public class name match its source file name?#
A top-level public class must be declared in a source file whose name matches the public class name.
Example:
public class EmployeePortalshould be stored in:
EmployeePortal.javaQ14. Is Java case-sensitive?#
Yes.
For example:
Systemand:
systemare different identifiers.
Q15. What types of comments are available in Java?#
Java supports:
// Single-line comment/*
Multi-line comment
*/and documentation comments:
/**
* Documentation comment
*/Q16. Do comments execute when a Java program runs?#
No. Comments are source-code text intended primarily for developers or documentation tooling; they are not executed as Java program statements.
Q17. What happens if a compilation error occurs?#
The compiler reports diagnostics and successful class-file generation for the affected compilation cannot proceed until the relevant error is corrected.
A developer should read the error, locate the source problem, fix it, and compile again.
Q18. Can a Java source file be run directly in current Java versions?#
Yes. Current Java versions support source-file launching, for example:
java HelloWorld.javaHowever, beginners should also understand the explicit two-step process:
javac HelloWorld.java
java HelloWorldbecause it clearly demonstrates compilation and execution as separate stages.
39. Quick Revision#
Java source file
↓
.java
Class declaration
↓
public class HelloWorld
Traditional entry method
↓
public static void main(String[] args)
Executable instruction
↓
Statement
Console output
↓
System.out.println(...);
Single-line comment
↓
// comment
Multi-line comment
↓
/* comment */
Compile
↓
javac HelloWorld.java
Generated class file
↓
HelloWorld.class
Run compiled program
↓
java HelloWorldFive Things You Must Remember#
- Java is case-sensitive.
- A top-level
publicclass should have a matching.javafilename. javaccompiles;javalaunches.- Many executable statements end with
;. - Do not memorize program structure without understanding what each part represents.
40. You Should Now Be Able To#
तुम्ही आता स्वतः:
HelloWorld.javaतयार करू शकता.- traditional Java class structure लिहू शकता.
main()method identify करू शकता.- simple output statements लिहू शकता.
- statement आणि class/method declaration मधला फरक ओळखू शकता.
- comments add करू शकता.
- matching public class/file naming maintain करू शकता.
- program compile करू शकता.
- compiled class run करू शकता.
.javaआणि.classयांच्यातला basic difference सांगू शकता.- basic syntax errors शोधू शकता.
javacआणिjavaयांच्यातला difference interview मध्ये explain करू शकता.
41. Final Challenge#
Requirement#
EmployeePortal.java नावाचा Java program तयार करा.
Program ने खालील output print केले पाहिजे:
Employee Portal
System Starting
System ReadyRequirements:
- public class name
EmployeePortal - traditional
main()method - three output statements
- output section च्या आधी एक meaningful single-line comment
- correct indentation
- correct semicolons
- compile आणि run commands स्वतः लिहा
उत्तर पाहण्याआधी स्वतः attempt करा.
Reference Solution#
public class EmployeePortal {
public static void main(String[] args) {
// Display application startup status
System.out.println("Employee Portal");
System.out.println("System Starting");
System.out.println("System Ready");
}
}Compile#
javac EmployeePortal.javaRun#
java EmployeePortalExpected Output#
Employee Portal
System Starting
System Ready