My First Java Program


Hello Students! In this video, I am going to show you
how to create your first Java program. For this demo, we are using the Eclipse IDE
and the Java 8 Development Kit (JDK) So, let’s get started! Step 1 is to create a package For this action we’re going to right click
on the project or source folder select “new”… …package we’re going to give it a name for this example let’s name our package “sample” click “finish” As you can see, a new
package was created I will discuss the importance of packages
in another video For now, just follow along. step 2 is to create a class then, we are going to right click on the package select “new”… …”class” we are going to give it a name For this name, we’re going to give it
the name “Hello World” And, one thing that I wanted to mention here for program to be executable a program must contain a class… …that has a main method; with a very specific method signature. The neat thing about Eclipse
is that you can actually choose to include such method in your class when you create it So, by checking this box we are telling the IDE to create
a class with that method. Click “Finish”… …and a source file it’s being created that contains a main method. So, this is an executable class. Step 3 is to actually tell program what to do. So we are tell it to do something. That something is going to be
to display “Hello World” to the console. So for that, we are going to use the System class which is provided by the Java library and then pick… uh… type a period, and we can see
that the Eclipse IDE provides a list of methods that can be invoked and also accessible attributes
of that class (System). So we’re going to utilize
one of those attributes or one of those fields uh… which is a PrintStream object called “out”. So this is the object that handles all of the outputs…. …of the System class. And we … print dot and again we are given a list
of the recommended methods. They are weighted by percentages and so we are going choose the top one which is “println”. You can see another one
down below called “print”. The difference is that hte
“println” appends a new line at the end of the String that is
going to be passed to the method. And that String is the message “Hello World”. We’re going to save the file… …and then the last step, step 4 is to actually run the program. We can do that by
right click on the file We can right click on
the package explorer or we can click this “run” button
on the top menu. So we’re going to run it using
the button on the toolbar And, as you can see
the message “Hello World” is actually printed to the console. And that concludes this presentation. You can follow me on Twitter and Google+ to receive notifications when
new videos are uploaded. And, as always, don’t forget to subscribe. See you next time.

Leave a Reply

Your email address will not be published. Required fields are marked *