91-9990449935 0120-4256464 |
Simple Program of JavaIn this page, we will learn how to write the simple program of java. We can write a simple hello java program easily after installing the JDK. To create a simple java program, you need to create a class that contains main method. Let's understand the requirement first. Requirement for Hello Java Example
Creating hello java exampleLet's create the hello java program: Test it Nowsave this file as Simple.java
Output:Hello Java Understanding first java programLet's see what is the meaning of class, public, static, void, main, String[], System.out.println().
To write the simple program, open notepad by start menu -> All Programs -> Accessories -> notepad and write simple program as displayed below:
How many ways can we write a java programThere are many ways to write a java program. The modifications that can be done in a java program are given below: 1) By changing sequence of the modifiers, method prototype is not changed. Let's see the simple code of main method. 2) subscript notation in java array can be used after type, before variable or after variable. Let's see the different codes to write the main method. 3) You can provide var-args support to main method by passing 3 ellipses (dots) Let's see the simple code of using var-args in main method. We will learn about var-args later in Java New Features chapter. 4) Having semicolon at the end of class in java is optional. Let's see the simple code. Valid java main method signatureInvalid java main method signatureResolving an error "javac is not recognized as an internal or external command" ?If there occurs a problem like displayed in the below figure, you need to set path. Since DOS doesn't know javac or java, we need to set path. Path is not required in such a case if you save your program inside the jdk/bin folder. But its good approach to set path. Click here for How to set path in java.
Next TopicInternal details of Hello Java Program
|