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 🍪