Implementation of java program involve the following steps:-
- Creating the program
- Compiling the program
- Run the program
- Creating the program:-To create the java program your can use text editor(like Notepad in windows).Open your text editor which you are going to use and type the following code in that:-
- Explanation:-
- Class Declaration:-The first line
class MN
This line declares a class .It is the first step to object-oriented programming.We know that Java is Object Oriented Programming ,so everything is is inside the class (class Name is MN here ).The keyword class is used to declare a class. - Opening Brace:-the braces { } are used to group the class definition.
class MN { }
- Main line-The line
public static void main(String args[])
public The keyword public is a access specifier that declares the main method accessible to outer classes this is because the Java program execution is started by the Operating System so main method is accessible to the Operating system. static The keyword static declares the main() method as one that belog to the entire class not a part of the object of the class,main method is declared as static so that Java interpreter can use the main method before any object is created of that (here MN) class in which the main is written. void The type modifier void states that the main() method will not return any value to the Operating system String args[] This is a parameter that is passed to the main() method ,at this movement just remember that it will hold the values that we will pass to the program when we will run the program - Output Line-The line
System.out.println("Hello and Welcome to java programming");
- Compiling the program:- Now Open the cmd prompt in your system ,goto the disk place where you have stored the program(like in the picture I have stored it on the Desktop and type javac MN (MN is the class Name that I have written in the code )
- Run the program:- Now Open the cmd prompt in your system and type the code (after javac MN) java MN:-
class MN { public static void main(String arg[]) { System.out.println("Hello and Welcome to java programming"); } }
You will Get the message "Hello and Welcome to java programming" that is written in the program.
No comments:
Post a Comment