Before we begin make java code, we must install Java 2 Standard Development Kit. I am using j2sdk1.4.2. You can use the newer one. You may download it from java.sun.com. To learn java installation steps you may browse java.sun.com or other sites.
Now, open editor for java such as JCreator Pro or others. You also may type it in Notepad. Be careful when you type, java is case sensitive. Type code below.- public static void main(String[] args){
- System.out.println("Hello I'm java");
- }
}
class Helloword{
You may type on other way like code below.
- Helloword(){
- System.out.println("Hello I'm java");
- }
- public static void main(String[] args){
- new Helloword();
- }
}
class Helloword{
After you finished, save file as Helloword.java (file name must be same with main class name), then open command prompt, direct to Helloword.java location. Then type "javac Helloword.java" to compile (makes Helloword.class). Then type "java Helloword", to run Helloword.class. If you type rightly, it will be shown like picture below.
I don't explain how to install java. I hope your java runs well.
I wanna explain Helloword.java
- class Helloword{ //make a class Helloword
- Helloword(){ //it's a consructor
- System.out.println("Hello I'm java");//write to console "Hello I'm java"
- }
- public static void main(String[] args){//method main (must be exist in main class)
- new Helloword();//call Helloword.class
- }
}
Notes:
Sign // is single line comment, for multi line comment use /* ........ */. Comments wouldn't be compiled.