Skip to content

Commit e8ea5c0

Browse files
Initial commit
0 parents  commit e8ea5c0

File tree

10 files changed

+245
-0
lines changed

10 files changed

+245
-0
lines changed

.github/dependabot.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
groups:
9+
actions-deps:
10+
patterns:
11+
- "*"
12+
13+
# Maintain dependencies for Maven
14+
- package-ecosystem: "maven"
15+
directory: "/"
16+
schedule:
17+
interval: "weekly"
18+
groups:
19+
maven-deps:
20+
patterns:
21+
- "*"

.github/workflows/auto-merge.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Auto Merge Dependabot PRs
2+
3+
on: pull_request_target
4+
5+
permissions:
6+
pull-requests: write
7+
contents: write
8+
9+
jobs:
10+
dependabot:
11+
name: 'Dependabot'
12+
runs-on: ubuntu-latest
13+
if: ${{ github.actor == 'dependabot[bot]' }}
14+
steps:
15+
- name: Enable auto-merge for Dependabot PRs
16+
run: gh pr merge --auto --squash "$PR_URL"
17+
env:
18+
PR_URL: ${{ github.event.pull_request.html_url }}
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target/
2+
/.idea/

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# 🚀 Create Your First Java Program
2+
3+
Java has evolved to become more beginner-friendly. This guide walks you through creating a simple program that prints “Hello World,” using both the classic syntax and the new streamlined approach introduced in Java 21.
4+
5+
---
6+
7+
## ✨ Classic Java Approach
8+
9+
Traditionally, Java requires a class with a `main` method as the entry point:
10+
11+
```java
12+
public class Main {
13+
public static void main(String[] args) {
14+
System.out.println("Hello World");
15+
}
16+
}
17+
```
18+
19+
This works across all Java versions and forms the foundation of most Java programs.
20+
21+
---
22+
23+
## 🆕 Java 25: Unnamed Class with Instance Main Method
24+
25+
In newer versions like **Java 25**, you can use **Unnamed Classes** and an **Instance Main Method**, which allows for a much cleaner syntax:
26+
27+
```java
28+
void main() {
29+
System.out.println("Hello World");
30+
}
31+
```
32+
33+
### 💡 Why is this cool?
34+
35+
- ✅ No need for a `public class` declaration
36+
- ✅ No `static` keyword required
37+
- ✅ Great for quick scripts and learning
38+
39+
To compile and run this, use:
40+
41+
```bash
42+
java --source 25 HelloWorld.java
43+
```
44+
45+
---
46+
47+
## 📚 Learn More
48+
49+
This feature is part of Java’s ongoing effort to streamline syntax. You can explore deeper in [Baeldung’s guide to Unnamed Classes and Instance Main Methods](https://www.baeldung.com/java-21-unnamed-class-instance-main).

pom.xml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>JavaTemplate</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.release>23</maven.compiler.release>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<junit.jupiter.version>6.0.2</junit.jupiter.version>
15+
<assertj.core.version>3.27.7</assertj.core.version>
16+
<mockito.version>5.21.0</mockito.version>
17+
</properties>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.junit.jupiter</groupId>
21+
<artifactId>junit-jupiter</artifactId>
22+
<version>${junit.jupiter.version}</version>
23+
<scope>test</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.assertj</groupId>
27+
<artifactId>assertj-core</artifactId>
28+
<version>${assertj.core.version}</version>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.mockito</groupId>
33+
<artifactId>mockito-junit-jupiter</artifactId>
34+
<version>${mockito.version}</version>
35+
<scope>test</scope>
36+
</dependency>
37+
</dependencies>
38+
<build>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-clean-plugin</artifactId>
43+
<version>3.5.0</version>
44+
</plugin>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-compiler-plugin</artifactId>
48+
<version>3.15.0</version>
49+
</plugin>
50+
<plugin>
51+
<groupId>org.apache.maven.plugins</groupId>
52+
<artifactId>maven-install-plugin</artifactId>
53+
<version>3.1.4</version>
54+
</plugin>
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-jar-plugin</artifactId>
58+
<version>3.5.0</version>
59+
</plugin>
60+
<plugin>
61+
<groupId>org.apache.maven.plugins</groupId>
62+
<artifactId>maven-resources-plugin</artifactId>
63+
<version>3.4.0</version>
64+
</plugin>
65+
<plugin>
66+
<groupId>org.apache.maven.plugins</groupId>
67+
<artifactId>maven-dependency-plugin</artifactId>
68+
<version>3.9.0</version>
69+
<executions>
70+
<execution>
71+
<goals>
72+
<goal>properties</goal>
73+
</goals>
74+
</execution>
75+
</executions>
76+
</plugin>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-surefire-plugin</artifactId>
80+
<version>3.5.4</version>
81+
<configuration>
82+
<argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar} -Xshare:off</argLine>
83+
</configuration>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-failsafe-plugin</artifactId>
88+
<version>3.5.4</version>
89+
<executions>
90+
<execution>
91+
<goals>
92+
<goal>integration-test</goal>
93+
<goal>verify</goal>
94+
</goals>
95+
</execution>
96+
</executions>
97+
</plugin>
98+
<plugin>
99+
<groupId>org.jacoco</groupId>
100+
<artifactId>jacoco-maven-plugin</artifactId>
101+
<version>0.8.14</version>
102+
<configuration>
103+
<skip>true</skip>
104+
</configuration>
105+
<executions>
106+
<execution>
107+
<id>default-prepare-agent</id>
108+
<goals>
109+
<goal>prepare-agent</goal>
110+
</goals>
111+
</execution>
112+
<execution>
113+
<id>default-report</id>
114+
<phase>prepare-package</phase>
115+
<goals>
116+
<goal>report</goal>
117+
</goals>
118+
</execution>
119+
</executions>
120+
</plugin>
121+
</plugins>
122+
</build>
123+
</project>

src/main/java/org/example/App.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.example;
2+
3+
public class App {
4+
public static void main(String[] args) {
5+
System.out.println("Hello There!");
6+
}
7+
}

src/main/resources/.gitkeep

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.example;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.assertj.core.api.Assertions.assertThat;
6+
7+
public class AppIT {
8+
@Test
9+
void itTest() {
10+
assertThat(false).isFalse();
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.example;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.assertj.core.api.Assertions.assertThat;
6+
7+
class AppTest {
8+
@Test
9+
void test() {
10+
assertThat(true).isTrue();
11+
}
12+
}

src/test/resources/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)