This is Eclipse environment, maybe little difference but it is eclipse also. What is the difference? I'm using ADT of Eclipse. ADT means Android Development Tools. I downloaded it from android developer website, it's a package with Android SDK. ADT version of Eclipse is similar to original Eclipse, so don't worry. If any problem, can ask me ;) OK, First, we need create a project. Right the area of Package Explorer --> New --> Java Project.

Then enter the project name you want and click Finish. After Finish, you also need create a java file in your project. Now open the project, right click src folder, turn to the New --> click Class.
After clicked class, Eclipse will show a New Java Class window, you need enter the java class also.
attention: cannot use symbol named. You will discover there have a warning, " The use of the default package is discouraged ". What is package? It like folder. If you don't name Package, Eclipse will generate a package automatically named default.
Moreover, you can tick the public static void main(String[] args) in Which method stubs would you like to create?
Now generated the class file.
Tips: /* */ and // are comment of code, comment will not affect program.
finally we can start to write our first program of java :P
very simple, we just type System.out.println("Hello world"); inside the main
if used " ", it means it is a String, not a variable.
Of course we can use it to print a variable.
Full code: (Print String)
public class helloworld{
public static void main(String[] args){
System.out.println("Hello world");
}
}
Full code: (Print variable)
public class helloworld{
public static void main(String[] args){
String x = "Hello world";
System.out.println(x);
}
}
System.out.print / System.out.println:
also, we can use System.out.print("Hello world");
It have little difference between System.out.println("Hello world");
The difference is System.out.println will create new line after print the words.
OK, code part is end.
So how to run our program?
Save the program and Click the Run button. As the picture circle.
The the result will show the below in Console ;P
Welcome to discuss :)



沒有留言:
發佈留言