To run java program you can download eclipse from here. At the beginning let’s start with writing a program which will print “hello world”. Let’s Now let see our first java code
Next we declare a main() method. From this line program will start executing. “public” is a access specifier. In main() method we declares a parameter named args which is a String. “void” before main() declare that main() does not return anything. static means that the method is associated with the class, not a specific instance of that class. This means that you can call a static method without creating an object of the class.
In above program we print “hello world”. We use “System.out.println(“hello world”)” where System is a predefine class. out is a static member of the System class. Then under out we use “println” to print the line.
Output of above program
class HelloWorld {
public static void main(String args[])
{
System.out.println("hello world");
}
}
In above program we print “hello world” using java language. Now closer look at our program. In first line we declare “HelloWorld” as a class. Then we create “{}”, now whatever we write in side, that is the component of class body or class definition.public static void main(String args[])
{
System.out.println("hello world");
}
}
Next we declare a main() method. From this line program will start executing. “public” is a access specifier. In main() method we declares a parameter named args which is a String. “void” before main() declare that main() does not return anything. static means that the method is associated with the class, not a specific instance of that class. This means that you can call a static method without creating an object of the class.
In above program we print “hello world”. We use “System.out.println(“hello world”)” where System is a predefine class. out is a static member of the System class. Then under out we use “println” to print the line.
Output of above program
hello world


0 comments:
Post a Comment