It is the trend to write the program to print "Hello World" while starting with any language. We will also do the same. Below is the program and I will also explain useful things used in program.
class Hello{
public static void main(Strings[] args){
System.out.println("Hello World!!!");
}
}
- Open any text editor and write the above program. Note that some are in capital letters.
- Now save the file with name Hello.java
- Open command prompt and browse the location where the file is located.
- For eg: If the file is located in c:/javatut/ then goto the same folder location in cmd.
- Now type javac Hello.java
- This command will compile your java file and creates class file.
- Now type java Hello
- If the compilation worked then you will get the output.
Some explanations
- The first statement defines the main class which is required and the class name should be in initial capital letter.
- The second statement defines the main function or method of the class. The first letter of String is capitalized as it is the class name.
- The third statement is used to display output. First letter of System is capitalized and the println statement creates new line after the output. You can also sumply use print only.
No comments:
Post a Comment