Hi everyone.
Welcome back.
In this lecture we will go and learn about a new way of making the Java class executable by the JVM.
So in this particular lecture we'll be working on the compact main package.
If you expand this one you will see a class named Hello World.
Let's open that.
Traditionally every Java application.
Let me add the public also over here.
As you can see, the public is being made redundant.
That means this public access modifier is not needed anymore.
Actually, we can remove the public access modifier over there on top of it.
There is also something called a compact source code.
Let's go ahead and explore that one actually.
So now I'm going to go to the compact main.
And then I'm going to create a Java class.
In here you will have a new option called Compact Source File.
So now I'm going to be creating a class named Simple Hello World okay.
And then click on the compact source here and press okay.
It's in a different package.
Let's go ahead and move it inside the compact main package.
There you go.
So now as you can see this particular class this class doesn't have a class name, and this class doesn't
have the public static void main that we have over here.
So traditionally before Java 25 you need to have public static void main.
And also you need to have a class on top of it.
And you can only have this main function within a class.
That's not the case anymore actually.
So now you can just provide the void main function.
Over here.
The JVM automatically creates an instance of the class and calls its main method.
The benefit here is that it reduces verbosity.
So now what I'm going to do I'm going to be copying this and put it over here.
So as you can see we're pretty much doing the same thing over here.
It's just that you need the simple main function.
You don't need the class and also the main function in it.
The main function just is enough.
Let's go ahead and execute this program.
There you go.
You're able to see the result in the console which is hello world okay.
And we have a new println function.
So so far we have been using that System.out.println.
println.
Right?
So you have new functions like io dot println.
You can do this.
It will give you the same result over here.
And also you can actually add variables.
So previously the main function can only access static variables.
That's not the case anymore actually.
So you can give any name you want in the source code file.
And you will be able to access that in the main function.
So here if you try to do the same thing.
So let's say I'm going to be copying this and putting it over here.
Let's say if I try to do the same thing over here, let's see what the result is going to be.
So the result is going to be it will complain that non-static field name cannot be referenced from a
static context.
So you have one additional benefit is that you have the ability to declare the variables and also access
them in your main function.
Let's go ahead and execute this particular main function.
There you go.
So in the console we have the result as hello world.
So this is one of the new feature that's part of the Java 25.
And the benefit here is that it reduces the verbosity.
And this also keeps your class concise and easy to read.
This marks the end of this lecture.
Thank you for watching.