Skip to main content

To implement a simple java program Hello Java.

Introduction:-

   Today we shall be writing a java program to see how the program is writen in java and the basic of java shall be discussed in this post here will will be writing and executing the program I will show you the output . All the steps will be shown simultaneously.

Writing a hello java program.

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

Step 1: Copy the upper program in a notepad file and then save it as hellojava.java with changing the text file to all files.
Note :That the file name should be save as the class name because java is case sensitive .

Step 2: Fire up your cmd as Adminstrator and then change the path to the saved java file .
(To change the path type in the cmd as cd <path to the java file>)

Step 3: To Compile the java program type in the command "javac hellojava.java".By execting the upper command the javac create a bytecode which is know as the .class file.

Step 4: To run the java program type in the "java hellojava" .This will execute the program.

Output:-
Hello java

 So this was the post about the first java program compilation and executution in the next post there will a topic if statement. So stay alert for the next post and watch for the post.

Click here to check the pervious post about the installation of java on the local machine

Comments

Popular posts from this blog

Program to calculate the room area and volume to illustrate the concept of single inheritance.

CODE: class Roomarea   { protected double l, b; Roomarea(double len, double br) { l=len; b=br; } void putdata() { System.out.println("Area of Room: "+(l*b)); } } class Roomvol extends Roomarea   { double h; Roomvol(double len, double br, double he) { super(len, br); h=he;   } void putdata() { super.putdata(); System.out.println("Volume of Room: "+(l*b*h)); } } public class EXP18Q4 { public static void main(String[] args) { Roomvol r1 = new Roomvol(10, 20, 10); r1.putdata();   } }

Define an exception called ‘NotMatchexception’ that is thrown when a string is not equal to ‘India’. Write a java program that uses this exception.

Code: import java.util.Scanner; class NotMatchException extends Exception {   public NotMatchException (String str)   {     System.out.println(str);   } } public class StringExc {    public static void main(String[] args)    {      Scanner scan = new Scanner(System.in);      System.out.print("Enter the string : ");      String input = scan.nextLine();      try      {        if(input.equalsIgnoreCase("India"))          System.out.println("String matched !!!");        else          throw new NotMatchException ("String not matched !!!");     }     catch (NotMatchException s)     {       System.out.println(s);     }   } } Output:

Develop a program using control loops in applets.

Code: import java.awt.*; import java.applet.*; public class Control extends Applet {      public void paint(Graphics g)      {      for(int i=1;i<=4;i++)     {          if(i%2==0)         {            g.fillOval(90,i*50+10,50,50);           g.setColor(Color.black);        }        else       {          g.fillOval(90,i*50+10,50,50);          g.setColor(Color.red);       }    }   } } /* <applet code=Control width=300 height=300> </applet> */ Output: