Java Essentials - Hello world program on java
17K views
Nov 18, 2024
Java Essentials - Hello world program on java Watch more Videos at https://www.tutorialspoint.com/videotutorials/index.htm Lecture By: Mr. Arnab Chakraborty, Tutorials Point India Private Limited
View Video Transcript
0:00
Hello World Program on Java
0:02
So let us go for our first program to be written and to be executed on our Java Eclipse IDE
0:11
So we'll be creating our Java class. So let the Java class name we have given here is hello world.java
0:18
We have created one package under which this Java class has got created and that is the name
0:23
of the package is getting started. And then we know that this is the program name, that is the
0:29
file name that is a hello world or java so the respective class name should be also the hello world
0:35
so under this we're having one main function that is the first function which is going to get
0:39
executed that is a main function the main function is having the prototype here is public static void
0:45
main string arcs is a string array and there's the arcs is there as the input parameter so it is a
0:52
public so can be accessed from outside of the class also it is a static that means a single instance
0:58
of this main function will be existing, it returns void, the name of the function is main
1:03
and it takes one string array, and the name of the array is our args. That means it is
1:09
it is ready to take the common line input arguments. There is a multiple arguments it can
1:15
take, and that will be stored into one string array. And under this, we have written only one
1:20
statement, that is a system.d. out, print, LN, and that is our Hallowold. System is nothing but one
1:26
class this class is existing under the package Java. So Java. Daugler lang is the default package which will get imported automatically
1:35
So here you can write import to Java. .lank. That is optional
1:40
You may or may not type that one because this Java will get imported by default automatically System is defined as a class within that Java Dot lang package And this is a out Out is nothing but one print stream class object
1:56
So there is a print stream class object. Out is there. And this particular object out is a static object
2:04
So that's why from the class name I can access it using system
2:08
dot out and print ln is one of the non-static member function under the print stream class so that's
2:16
why we have we can write that is a system that is a class name here dot out that is a print
2:22
stream static object out here so system dot out and print stream is having one method that is our print
2:31
ln so out dot print ellen we can write and it takes a string as input argument so whatever the strings
2:36
we have putting here that must be enclosed within double quotes because in case of Java
2:41
all the strings must get enclosed within double quotes so here we have given the string as
2:47
hallow world so hallow world will get it will get printed when this program will be in execution
2:53
for the better understanding let us go for further explanation and discussion on this
2:58
respective program with one demonstration so here is a demonstration for you
3:04
on the eclipse editor we are going to type code on to display the Hallowold string in the package Explorer we're going for
3:12
the right click new and Java project giving the name as my hello world you can
3:19
give any other name here so here we are going for this Java SC 1.8 all the
3:26
things have been set now going for next so it will create one SRC folder going for finish so my hello world has got created this Java project has got created on this SRC we are going for this right click new and then going for this package
3:43
given the name as com.demo. helloworld com dot demo.t hello world so that is my package name we're going for finish
3:58
then on this package going for right click the new then going for class it will go
4:05
on creating a Java class so let it be hello world this class name and the
4:13
file name must be same so here you can find that we have given the name hello
4:17
world with H and W capital letters rest letters are in the lower case then the
4:23
hello world java will be created and that will be having the same name as that
4:27
of the class name the package name has got displayed here so under this we're
4:32
going to create one function that is a main I'm not going to type the full main
4:38
prototype we're going for this web type this main and then control space bar
4:42
we're using the eclipse intelligence here so that is a main method which
4:48
will have the prototype that is public static void main string �
4:57
respective function has got printed so now we are going for this cease out I
5:01
shall not go on typing our system dot out or print eland I shall type only
5:06
c's out and then control space bar so we are using eclipse in tellisance
5:12
so here we typing here hallow world so in this way the respective program we have typed So here public class Hallowold the name of the class is Hallowold
5:28
The Hallowold must be same as that of the file name. So the file name is Hallowold. Java
5:33
We're going to save that one. And the first function which will start its execution is known as the main function, which
5:40
will have the prototype. That is public static void main string array args
5:45
obviously this arcs can be changed because it is nothing but one string at
5:50
object and instead of writing this public static also can write static public so
5:58
that is also allowed so that is also allowed but it is our common practice to
6:04
write public static so public means this particular function is accessible from
6:09
outside of the class and static means this particular function will have a single
6:13
instance irrespective of the number of objects we are going to create under the
6:18
class hallowold and void indicates that this function returns nothing it returns void and system.outt printallon we will be using it to display some
6:28
string on the screen so on the console so here the string must be enclosed within
6:33
double quotes in Java so how to execute this program just we shall click on this
6:39
run hallowold java in eclipse and then the respective output will be obtained that is a hallow world so in this demonstration
6:48
we have given you the idea that how to create a java project java package java class how to type
6:55
code in eclipse in that particular java class whatever you have created here it is hallowold
7:01
and how to execute the code to get the output in the console thanks for watching this video
#Computer Education
#Java (Programming Language)
#Programming
#Training & Certification