Tutorial 2 - JAVA first program ( Hello World ) in ubuntu

Today I'm going to show you how to create your first java program "Hello world" as a beginners. This is the very basic java programming.



This is the first tutorial I brought you to create your first java program "Hello Wolrd" as beginners. I will guide you step by step with illustration.

You can run any java program in following steps. 

  1. JDK package is need to be installed to your pc. If you don't know or still didn't setup your jdk environment you can follow our previous tutorials. 
  2. For ubuntu users see this tutorial or for windows users see this tutorial.
  3. Then next step is create the java program
  4. Compile and run the java program
Let's begin with introduction to a java code.

What is a class in java?
  • Class is an essential part of a java code which is a template used to create objects. Simply java class is a set of objects. Object is an instant or an entity of a class. You will learn further abou an object from our next tutorial.
  • Java files need to have at least one class defined in it. If there are multiple classes, then one class should have 'public' keyword. 
  • The name of the public class in a java file has to be the same name as java file.
What are the things java class contains?

  1. Member
  2. method
  3. constructor
  4. class
  5. interface
example: 
========================================================
class <className>{
    
    className(){     // constructor created

    }    

     public static void main(String[] args){      // main method

        int a = 10;                 
        className object = new className();    // object created

    }

}
========================================================

Let's start creating your first java program 

  • You can write your code in any text editor or in an IDE like eclipse. I have used text editor in this tutorial.
  • I am using nano text editor to write my java program. You may use gedit text editor too. 
How to open a nano text editor?

  • It is very easy to open nano text editor in ubuntu. First open the terminal and go to your path where you want to save your java file. 
  • Then type nano HelloWolrd.java in your terminal to open text editor. Then the nano is open in your terminal. 



  • Now you can write your code in the terminal.
  • Or else you can use gedit editor.
  • First go to the directory where you want to save your program using the temrinal and enter gedit HelloWorld.java in the terminal and press enter. Then the gedit editor will open.


  • Don't forget to save your java file in ".java" extension ( Ex. HelloWorld.java ).
  • Then type the following code in the java file you created. 
================================================================

class HelloWorld{

    public static void main(String[] args){

        System.out.println("Hello World");

    }

}

================================================================

you can download the java file from here.


  • Now compile this program by typing javac HelloWorld.java in the terminal.
  • Then run the program by typing java HelloWorld

  • So you can see the output in the terminal. 

  • This is java basic program and you can see the demo in following video.



If you cannot see this video you can watch it by clicking here.

Thank you very much for reading this tutorial. Our Next tutorial is about Java Variable and Data Types. If you have any problems regarding this tutorial feel free to make a comment below or you can contact us by sending email to this address, progtpoint@gmail.com.
Follow us on facebook and twitter also subcribe us youtube.

7 comments:

  1. That is the great one which I found on your website. Thank you so much for sharing this information.best of luck it was a good job.
    digital marketing services in delhi

    ReplyDelete
  2. Supplements For Fitness inform you about health products and also plan a meal plan for you. Doing the right amount of exercise to lose weight works wonders for your weight management plan. There are many training modes you

    ReplyDelete
  3. Premium Pure keto is a weight loss supplement. It is made by very unique formula of all natural ingredients. Now a day it is not difficult task to lose. More than around thousand of weight loss supplements are in market. These all supplements are helping you to lose your weight but the thing is that you have to select the best supplement which is pure naturally formulated and effective. Some of people are worried about their weight which is increasing day by day, and some of them may be worried for their skin disorders. Kindly Visit On Premium Pure keto Weight Loss Supplement

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. This article is a great article that I have seen so far in my Java programming career, it will help a lot in setting up a new career for non experience developers.

    website development company in Surat Gujarat

    ReplyDelete
  6. Tutorial 2 in Java, the "Hello, World!" program, marks the exciting beginning of coding. Impact Net Neutrality This foundational lesson introduces essential syntax and structure, igniting the journey into Java programming.

    ReplyDelete

Social