WEBVTT

00:00.120 --> 00:00.680
Hi everyone.

00:00.680 --> 00:01.320
Welcome back.

00:01.320 --> 00:07.680
In this lecture we will go and learn about a new way of making the Java class executable by the JVM.

00:07.680 --> 00:12.160
So in this particular lecture we'll be working on the compact main package.

00:12.200 --> 00:15.680
If you expand this one you will see a class named Hello World.

00:15.720 --> 00:16.600
Let's open that.

00:16.640 --> 00:18.880
Traditionally every Java application.

00:19.120 --> 00:21.080
Let me add the public also over here.

00:21.080 --> 00:23.880
As you can see, the public is being made redundant.

00:23.880 --> 00:27.680
That means this public access modifier is not needed anymore.

00:27.720 --> 00:32.280
Actually, we can remove the public access modifier over there on top of it.

00:32.280 --> 00:35.880
There is also something called a compact source code.

00:35.880 --> 00:37.640
Let's go ahead and explore that one actually.

00:37.640 --> 00:40.040
So now I'm going to go to the compact main.

00:40.040 --> 00:42.040
And then I'm going to create a Java class.

00:42.040 --> 00:46.640
In here you will have a new option called Compact Source File.

00:46.640 --> 00:50.960
So now I'm going to be creating a class named Simple Hello World okay.

00:51.000 --> 00:53.840
And then click on the compact source here and press okay.

00:53.880 --> 00:54.920
It's in a different package.

00:54.920 --> 00:57.960
Let's go ahead and move it inside the compact main package.

00:58.000 --> 00:58.440
There you go.

00:58.480 --> 01:03.730
So now as you can see this particular class this class doesn't have a class name, and this class doesn't

01:03.730 --> 01:07.570
have the public static void main that we have over here.

01:07.570 --> 01:12.130
So traditionally before Java 25 you need to have public static void main.

01:12.130 --> 01:15.610
And also you need to have a class on top of it.

01:15.610 --> 01:18.650
And you can only have this main function within a class.

01:18.850 --> 01:20.890
That's not the case anymore actually.

01:20.890 --> 01:24.250
So now you can just provide the void main function.

01:24.250 --> 01:24.970
Over here.

01:25.010 --> 01:30.450
The JVM automatically creates an instance of the class and calls its main method.

01:30.490 --> 01:33.490
The benefit here is that it reduces verbosity.

01:33.490 --> 01:37.450
So now what I'm going to do I'm going to be copying this and put it over here.

01:37.450 --> 01:40.410
So as you can see we're pretty much doing the same thing over here.

01:40.410 --> 01:43.170
It's just that you need the simple main function.

01:43.170 --> 01:46.410
You don't need the class and also the main function in it.

01:46.410 --> 01:48.050
The main function just is enough.

01:48.050 --> 01:49.650
Let's go ahead and execute this program.

01:51.290 --> 01:51.890
There you go.

01:51.930 --> 01:55.490
You're able to see the result in the console which is hello world okay.

01:55.530 --> 01:58.010
And we have a new println function.

01:58.010 --> 02:01.330
So so far we have been using that System.out.println.

02:01.330 --> 02:01.390
println.

02:01.390 --> 02:01.710
Right?

02:01.710 --> 02:04.390
So you have new functions like io dot println.

02:04.430 --> 02:05.430
You can do this.

02:05.510 --> 02:07.310
It will give you the same result over here.

02:07.310 --> 02:09.670
And also you can actually add variables.

02:09.670 --> 02:13.390
So previously the main function can only access static variables.

02:13.390 --> 02:15.310
That's not the case anymore actually.

02:15.310 --> 02:18.230
So you can give any name you want in the source code file.

02:18.230 --> 02:21.470
And you will be able to access that in the main function.

02:21.470 --> 02:23.350
So here if you try to do the same thing.

02:23.390 --> 02:26.430
So let's say I'm going to be copying this and putting it over here.

02:26.430 --> 02:30.270
Let's say if I try to do the same thing over here, let's see what the result is going to be.

02:30.310 --> 02:35.870
So the result is going to be it will complain that non-static field name cannot be referenced from a

02:35.870 --> 02:37.190
static context.

02:37.190 --> 02:42.590
So you have one additional benefit is that you have the ability to declare the variables and also access

02:42.590 --> 02:44.150
them in your main function.

02:44.150 --> 02:46.390
Let's go ahead and execute this particular main function.

02:46.390 --> 02:47.110
There you go.

02:47.110 --> 02:49.790
So in the console we have the result as hello world.

02:50.350 --> 02:53.830
So this is one of the new feature that's part of the Java 25.

02:53.830 --> 02:56.910
And the benefit here is that it reduces the verbosity.

02:57.230 --> 03:00.670
And this also keeps your class concise and easy to read.

03:00.670 --> 03:01.790
This marks the end of this lecture.

03:01.790 --> 03:02.670
Thank you for watching.
