Hello World in Java 25

problem

A classic introduction program when learning or testing out a new language. In this case Java version 25. Let’s see a simple Hello World program.

SOLUTION

We will write a program that when it runs, simply outputs a “Hello World” message on the screen/ console.

Main.java
				
					void main() {
   IO.println("Hello World!");
}
				
			
running
				
					java Hello25.java
				
			

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

output
Running Hello World in java 25
INPUT - read from console

Let’s ask the user to enter their name. We can do it simply by using the IO.readln() method as follows:

Main.java
				
					void main() {
   var name = IO.readln("What is your name?");
   IO.print("Hello ");
   IO.println(name);
}
				
			
running
				
					java Main.java
				
			
output
Input Output from console in java 25
Program arguments

If we wish to use program arguments, we can simply write the parameter in the main method as follows:

Main.java
				
					void main(String[] args) {
}

				
			

And then use them in our code. For example, doing a for loop to print their values.

Main.java
				
					void main(String[] args) {
   IO.println("Program arguments:");
   for(String arg : args) {
       IO.println(arg);
   }
}
				
			
running
				
					java Main.java argument1 argument2 etc
				
			
output
Program arguments in java 25

conclusion

In this post we saw how to write a Hello World in Java 25 and also how to prompt the user to type their name.

References:

https://openjdk.org/jeps/512

https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IO.html#readln()

Share it!

Facebook
Twitter
LinkedIn
Reddit
Picture of Ellion

Ellion

Professional IT consultant, writer, programmer enthusiast interested in all sorts of coding.
Eats all cookies 🍪

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Strictly Necessary Cookies

Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

Google Analytics Cookies

This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.

Keeping this cookie enabled helps us to improve our website.

HotJar Cookies

We use Hotjar in order to better understand our users’ needs and to optimize this service and experience. Hotjar is a technology service that helps us better understand our users’ experience (e.g. how much time they spend on which pages, which links they choose to click, what users do and don’t like, etc.) and this enables us to build and maintain our service with user feedback. Hotjar uses cookies and other technologies to collect data on our users’ behavior and their devices. This includes a device's IP address (processed during your session and stored in a de-identified form), device screen size, device type (unique device identifiers), browser information, geographic location (country only), and the preferred language used to display our website. Hotjar stores this information on our behalf in a pseudonymized user profile. Hotjar is contractually forbidden to sell any of the data collected on our behalf.

For further details, please see the ‘about Hotjar’ section of Hotjar’s support site.