Understanding:
At the very beginning, I should understand clearly this every program can be understood as a progress so make a record O F some inputs in order to calculate and then output the result.
And the most important thing to learn Java are the ability to read codes.
Then let me begin to learn java! O (* ̄▽ ̄*) o
The first Java program, of course, is "Hello world!":( Ide:eclipse)
The codes:
Package Hello;public class Hello {public static void main (string[] args) {//TODO auto-generated method StubSystem.out.pri Ntln ("Hello world!");}}
Let me show the catalogue:
We can see our Hello.java program are in the package "Hello", (up to now, I don ' t know why there is a package, however, I C An learn so later) It can also throw the package in this program.
Let me add something into this easy program in order to make it more fantastic--the the "Yesman" program.
The codes:
Package Hello;import Java.util.Scanner; Here is the call to import, similar to the include public class in C, {public static void main (string[] args) {//TODO auto-generated method StubSystem.out.println ("Hello world!"); Scanner in = new Scanner (system.in); Input Statement System.out.println (In.nextline ()); Enter a whole line}}
The Output:
We can learn something basic about string from ' Yesman ' program:
System. out. println ("2+3=" +5); ===> 2+3=5
System. out. println ("2+3=" +2+3); ===> 2+3=23
System. out. println ("2+3=" + (2+3)); ===> 2+3=5 (string + numeric ===> all as strings)
System. out. println (2+3+ "=2+3=" + (2+3)); ===> 5=2+3=5 (arithmetic + string + operation) ===> first computed as String output)
System. out. println (2+3+ "=2+3=" +2+3); ===> 5=2+3=23
And we can learn how to define variables from the This program:
Package Hello;import Java.util.scanner;public class Hello {public static void main (string[] args) {//TODO auto-generated Method Stubscanner in = new Scanner (system.in); int price;price = In.nextint (); System.out.println ("100-" +price+ "=" + (100-price));}}
The Output:
Define constants: final int amount = 100; (final is a constant keyword)
define float number:double variables;
Change double type to int type: (cast double to int type) (int) meter; (meter previously a double type)
Attention:
We often use this sentence to judge and doubles are Equal:Math.abs (F1-F2) < 0.00001;
Java variables 01