Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/semusings/in-5-minutes
In 5 Minutes
https://github.com/semusings/in-5-minutes
Last synced: 3 days ago
JSON representation
In 5 Minutes
- Host: GitHub
- URL: https://github.com/semusings/in-5-minutes
- Owner: semusings
- License: apache-2.0
- Created: 2024-05-04T02:25:19.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-05-04T04:03:05.000Z (7 months ago)
- Last Synced: 2024-05-05T03:25:00.141Z (7 months ago)
- Language: Java
- Homepage: https://semusings.github.io/in-5-minutes/
- Size: 87.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
---
marp: true
theme: your-theme
paginate: true
header: '© Software Engineering Musings - - subscribe us on '
---section { overflow: auto; display: block; width: 100%; height: 100%; }
# Unnamed Classes and Instance Main Methods
**JEP-445**
- Ever found Java's "Hello, World!" program a bit too complex?
- Java's complexity can be daunting for beginners.
- No more unnecessary clutter in simple programs.
---
## Classic Approach
Classic Hello, World! program that is often used as the first program for Java students:
```java
public class HelloWorld {
static String greeting = "Hello, World!";public static void main(String[] args) {
System.out.println(String.format(":%s\n:%s\n:%s", HelloWorld.class.getName(), greeting,
"Subscribe us on youtube.com/@semusings"));
}
}
``````bash
java --source 22 --enable-preview HelloWorld.java
```In this approach -> too much code, too many concepts, too many constructs
---
## Mordern Approach
Allow to lunch instance main methods. Such methods are not static, need not be public, and need not have a String[] parameter.
```java
class HelloWorldUsingInstanceMethod {String greeting = "Hello, World!";
void main() {
System.out.println(String.format(":%s\n:%s\n:%s", getClass().getName(), greeting,
"Subscribe us on youtube.com/@semusings"));
}}
``````bash
java --source 22 --enable-preview HelloWorldUsingInstanceMethod.java
```---
## Mordern Approach (contd.)
Unnamed classes to make the class declaration implicit
```java
String greeting = "Hello, World!";void main() {
System.out.println(String.format(":%s\n:%s\n:%s", getClass().getName(), greeting,
"Subscribe us on youtube.com/@semusings"));
}
``````bash
java --source 22 --enable-preview HelloWorldUsingUnnamedClass.java
```---
## Thank You!
> Please feel free to reach out to me if you have any question.
>
> [email protected]
Subscribe us on YouTube---
### References
-