logo
logo1 Home Latest Central Engineering Defence Tutorials menu

Java Basic Syntax

Lets code the very basic program that all the begineers code first Hello World in java. Dont worry about all the kerwords, structure names in this program this is just a welcome program for this tutorial. Lets see how easy the java program is to understand. Don't give up at any of this Java tutorial session, keep on read, code and sleep. You will surely become the master in this Java program.

Example: Hello World Program

      public class FirstProgram 
      {

        public static void main(String[] args) 
        {
    
        System.out.println("Hello World");
        }

      }
    

Output : Hello World

Lets decode this simple Hello World program in java,

Comments in Java

Comments are non executable parts in the code. Why we want to use commends? Java commends are used to understand the code, it is written in simple english are language of your choice. For example to create a software application includes many software developer in order to understand the code of one developer to another by reading the comments of that particular code block. It is more usefully when fixing the bug, we can easily identify the block and its function through proper comments.

In java comments are divided into two types:

Single line Comments

Single line comments are denoted by placing double forward slash // before the line. It is applicable to only one line, When you want to add more lines of Comments or to hide particular code in a program single line comments is not suitable.

Example: Single Line Commands

      public class Demo 
      {

        public static void main(String[] args) 
        {
        
        // this is singleline comments, it dont execute while executing the program
        
        System.out.println("Single line Comment example");
        }

      }
    

Output : Single line Comment example

Multi-line Comments

Multi-line comments are useful when you want to use more than 1 line of code. It is denoted by /* */ It is often used to hide the block in program. lets see the example below

Example: Multi-Line Comments

      public class Demo 
      {

        public static void main(String[] args) 
        {
        
        /*this is singleline comments, it don't 
        execute while executing the program
        we can write anything within this multi -line 
        commands,it wont execute while running the program

          System.out.println("Multi line Comment example");

        */
        
        System.out.println("Multi line Comment example");
        }

      }
    

Output : Multi line Comment example

In the above program lines within /* */ wont execute during running the program. you can use this muli-line comments anywhere you want in the java program

Open your IDE or any text editor, In this tutorial we are using Eclipse IDE. Copy the code and execute the program. If you are new to the IDE check out Eclipse tutorial to learn the basics of eclipse IDE.

About Us | Contact | Disclaimer