You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: section3/HelloWorld/README.md
+175-5Lines changed: 175 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,10 @@
1
1
# Getting Started with Java in IntelliJ IDEA
2
-
Welcome to our Java course! In this guide, we'll walk you through creating your first Java class using IntelliJ IDEA, a powerful integrated development environment (IDE) for Java development.
2
+
Welcome to our Java course! In this guide, we'll walk you through creating your first Java class using IntelliJ IDEA, a powerful
3
+
integrated development environment (IDE) for Java development.
3
4
### Prerequisites
4
5
Before getting started, ensure that you have the following installed on your system:
5
-
- IntelliJ IDEA (Community or Ultimate edition) https://www.jetbrains.com/idea/download/?section=windows
6
-
- Java Development Kit (JDK) installed on your machine https://docs.aws.amazon.com/corretto/latest/corretto-21-ug/downloads-list.html
6
+
- IntelliJ IDEA (Community or Ultimate edition) https://www.jetbrains.com/idea/download/
7
+
- Java Development Kit (JDK) installed on your machine https://docs.aws.amazon.com/corretto/latest/corretto-25-ug/downloads-list.html
7
8
### Steps to Create Your First Java Class
8
9
1.#### Open IntelliJ IDEA : Launch IntelliJ IDEA on your system.
9
10
2.#### Create a New Project :
@@ -13,7 +14,7 @@ Before getting started, ensure that you have the following installed on your sys
13
14
- Choose a Project Location where you want to save your project files.
14
15
- Select the Language as Java.
15
16
- Build system as IntelliJ.
16
-
- Add JDK as corretto-21 or click on New... and locate your JDK installation directory.
17
+
- Add JDK as corretto-25 or click on New... and locate your JDK installation directory.
17
18
- Click on Create to create the project.
18
19
4.#### Create a Java Class :
19
20
- In the Project tool window (usually located on the left-hand side), right-click on the src folder.
@@ -38,5 +39,174 @@ public class HelloWorld {
38
39
- Click on the green Run icon next to the main method or right-click anywhere inside the main method and select Run 'HelloWorld.main()'.
39
40
7.#### View Output :
40
41
- You should see the output "Hello Madan" printed in the Run tool window at the bottom of the IntelliJ IDEA window.
The Single-File Source-Code Program feature, introduced in `Java 11`, allows developers to run Java programs directly from a source file without the need for separate compilation.
46
+
47
+
This was later enhanced in `Java 22` to support Multi-File Source-Code Programs, enabling the execution of Java applications that span across multiple `.java` files — still without explicit compilation.
48
+
49
+
### ⚙️ Traditional Java (Before Java 11)
50
+
51
+
Prior to `Java 11`, you had to compile your Java code before running it:
52
+
53
+
### 🧾 Example
54
+
```java
55
+
publicclassHello {
56
+
publicstaticvoidmain(String[] args) {
57
+
System.out.println("Hello World...");
58
+
}
59
+
}
60
+
```
61
+
62
+
▶️ Commands
63
+
```
64
+
javac Hello.java # Compilation
65
+
java Hello # Execution
66
+
```
67
+
Two distinct steps were required — compile first, then run.
68
+
69
+
### 🚀 From Java 11 — Single-File Source Programs
70
+
71
+
Starting in Java 11, you can execute a Java program directly from its source file using a single command.
72
+
73
+
### 🧾 Example
74
+
```java
75
+
publicclassHello {
76
+
publicstaticvoidmain(String[] args) {
77
+
System.out.println("Hello World...");
78
+
}
79
+
}
80
+
```
81
+
82
+
▶️ Command
83
+
```
84
+
java Hello.java
85
+
```
86
+
✅ The JVM automatically compiles and runs the file in one step.
87
+
88
+
**⚠️ Limitation :** Works only if all the code is within a single file.
89
+
If your logic spans multiple source files, Java 11 cannot handle it.
90
+
91
+
92
+
### 🧱 From Java 22 — Multi-File Source Programs
93
+
94
+
Java 22 extends this functionality — now you can run Java programs that use multiple source files (with dependencies) without manual compilation.
95
+
96
+
### 🧾 Example
97
+
```java
98
+
publicclassHello {
99
+
publicstaticvoidmain(String[] args) {
100
+
Greetings.sayHello();
101
+
}
102
+
}
103
+
104
+
publicclassGreetings {
105
+
publicstaticvoidsayHello() {
106
+
System.out.println("Hello World...");
107
+
}
108
+
}
109
+
```
110
+
111
+
▶️ Command
112
+
```
113
+
java Hello.java
114
+
```
115
+
116
+
✅ Even though Hello depends on another class (Greetings), `Java 22` automatically detects and compiles both files before execution.
|**Ease of Use**| Manual | Simplified | Seamless |
143
+
144
+
## Compact Source Files & Instance Main Methods
145
+
146
+
The Compact Source Files and Instance Main Methods features introduced in Java 25 make Java simpler and more approachable for beginners, while still being powerful for experienced developers.
147
+
148
+
These features reduce boilerplate and let you start coding Java applications without needing to define classes or static methods.
149
+
150
+
### 💻 Traditional vs. Compact Example
151
+
🧾 Before (Classic Java Program)
152
+
```java
153
+
publicclassHelloWorld {
154
+
publicstaticvoidmain(String[] args) {
155
+
System.out.println("Hello World!");
156
+
}
157
+
}
158
+
```
159
+
160
+
✅ After (Compact Source File in Java 25)
161
+
```java
162
+
void main() {
163
+
IO.println("Hello World!");
164
+
}
165
+
```
166
+
167
+
### 🧠 Explanation
168
+
169
+
- Compact Source Files remove the need for explicit class definitions in simple programs.
170
+
- Instance Main Methods allow main() to be defined without the static keyword.
171
+
- This keeps code concise, beginner-friendly, and ideal for quick prototypes or lightweight scripts.
172
+
173
+
💡 The Java compiler automatically creates an implicit top-level class for compact source files.
174
+
175
+
### ⚙️ Instance Main Method Explained
176
+
177
+
Traditionally, Java required main() to be static:
178
+
```java
179
+
180
+
publicstaticvoid main(String[] args) { }
181
+
```
182
+
183
+
Now, in Java 25, the `main()` method can be non-static — the JVM automatically instantiates the implicit class to execute it.
184
+
185
+
🧾 Allowed Variations of main() in Compact Source Files
186
+
```java
187
+
void main() {}
188
+
publicvoid main() {}
189
+
staticvoid main() {}
190
+
publicstaticvoid main() {}
191
+
publicvoid main(String[] args) {}
192
+
publicstaticvoid main(String[] args) {}
193
+
```
194
+
🧩 If both a `main(String[] args)` and a no-argument `main()` exist, the JVM prefers `main(String[] args)` as the program’s entry point.
195
+
196
+
### 💬 Why It Matters
197
+
198
+
- Beginner-Friendly: No need to understand classes, objects, or static context before writing your first program.
199
+
- Less Boilerplate: Write quick experiments, demos, or simple utilities faster.
200
+
- Flexible for Experts: Enables rapid prototyping before scaling into larger applications.
0 commit comments