Related post

Java programming syntax

 Java Syntax

In this tutorial, you will learn the anatomy of Java. We would use a simple example which is Hello world to explain Java anatomy. This tutorial covers the syntax and semantics of Java program.




public class FirstJavaProgram {

  public static void main(String[] args){

    System.out.println("This is my first program in java");

  }//End of main

}//End of FirstJavaProgram 




Java Syntax



Take a good look at the line of code above. Don't worry, I know it looks hard but don't worry let's break it down. All you need is a Java code editor and a cup of coffee.

Let's get started.


Step 1

Download a code editor on your Windows or Mac , save your program as helloWorld.java

You may be wondering why I asked you to save as HelloWorld.java. Well in Java, the name of the program must be the same as the one in public class name. Take a look at this.


Now let's take a good look at the program itself.


The class Heading

Let's take a closer look at this class Heading.

            public class HelloWorld


This particular line is called the class heading that defines the program class. We will talk about class later in other tutorials.


 The first two world before HelloWorld -- 'public' and 'class' are reserved words or simply keywords. By reserved word, we mean words that have been predefined by Java to serve a purpose. So those word are very important.


The last word on the line -- HelloWorld is the name of name of class. Please take note that you can choose any class name of your choice.


The main method heading

           public static void main ( String [ ]  args)


Public -- is an access modifier. This means that it is accessible by the public

Static -- allows the method to be accessed immediately.

Void -- this word indicates that the method returns nothing.

Braces 

In Java, braces are very important. They come in pairs. 

System.out.println

This line tells the computer to print something. The world to be printed will appear in the bracket and quoted.


Okay, with the explanation above. Here is a take home assignment for you.


Take home : Write a program in Java that prints you name , age, profession and state of origin.


Let's move


Break statement in Java


Continue statement in Java


Inheritance in Java



Please share 







Follow us on



 

Comments