Java Basics Syntax:-A java program is a collection of objects that communicate
via invoking each other methods.
Java Program:-
public class First
{
public static void main(String
[]args )
{
System.out.println(“Welcome You”); //print
Welcome You
}
}
Lets looks how to save the file, compile and run the
program. Please follow some step which define below:-
1. Firstly, open notepad in your computer and add the code in notepad.
2. In second step to save the file as First.java ( i.e First is file name which same as your class name define in program and save with .java extension)
3. Open your command prompt window and go to the directory where you save the file.
4. Type:- c:\> javac First.java and press enter. If it is not show any error in window, it compile successfully.
5. Type :- c:\>java First and press enter to run your program.
6. It show an output, Welcome You in command prompt window.
1. Firstly, open notepad in your computer and add the code in notepad.
2. In second step to save the file as First.java ( i.e First is file name which same as your class name define in program and save with .java extension)
3. Open your command prompt window and go to the directory where you save the file.
4. Type:- c:\> javac First.java and press enter. If it is not show any error in window, it compile successfully.
5. Type :- c:\>java First and press enter to run your program.
6. It show an output, Welcome You in command prompt window.
In above Java program, Keep some following important points
in your mind:-
1. Case Sensitivity:- Java is a case sensitive which means identifier First and first would have different meaning in java.
2. Class Name:- According to conventional rule, first letter of class name should be in upper letter.
1. Case Sensitivity:- Java is a case sensitive which means identifier First and first would have different meaning in java.
2. Class Name:- According to conventional rule, first letter of class name should be in upper letter.
For Example:- class First
3. Method Names :- All method first rule should be in lower case and if you use several words in the name of method, then inner word first letter should be in upper case.
For Example:- public void showPicture( )
4. Program File Name:- Program file name should exactly the class name when you saving file with .java extension in your computer.
For Example:- Assume that your class name is First, then your program file name should exactly First.java
5. Public static void main(String []args) :- java program processing starts from main() method which is mandatory in your java program.
3. Method Names :- All method first rule should be in lower case and if you use several words in the name of method, then inner word first letter should be in upper case.
For Example:- public void showPicture( )
4. Program File Name:- Program file name should exactly the class name when you saving file with .java extension in your computer.
For Example:- Assume that your class name is First, then your program file name should exactly First.java
5. Public static void main(String []args) :- java program processing starts from main() method which is mandatory in your java program.
No comments:
Post a Comment