1. First the most classic Hello world!
Public class Hello { publicstaticvoid main (String args[]) { System.out.println ( "Hello world!" ); }}
Hello world!
The difference between 2.print and println
Public class Hello { publicstaticvoid main (String args[]) { System.out.print ( "Hello world!" ); System.out.println ("Hello world!" ); System.out.println ("Hello world!" ); }}
Hello World!hello world! Helloworld!
Apparently println ended up with a newline and print no, so it's better to use println.
Usage of 3.PRINTLN
Public class Hello { publicstaticvoid main (String args[]) { int x= 2; SYSTEM.OUT.PRINTLN (x+ "*" +x+ "=" + (x*x));} }
2*2=4
The number to be output here is connected with the "+" number.
4. Declaration of Constants
Public class Hello { staticfinalint year=365; Public Static void Main (String args[]) { System.out.println ("Two years equals" +2*year+ "Day");} }
Two years equals 730 days.
Public class Hello { publicstaticvoid main (String args[]) { final int year=365; System.out.println ("Two years equals" +2*year+ "Day");} }
Two years equals 730 days.
Constant assignment Syntax final+ data type + variable name = variable value, when constant is used for a member variable of a class, you must assign a value to the constant.
5. Declaration of variables
Public class Hello { publicstaticvoid main (String args[]) { int Num=3; Char ch= ' a '; SYSTEM.OUT.PRINTLN (num+ "is an integer"); SYSTEM.OUT.PRINTLN (Ch+ "is character");} }
3 is the integer A is the character
These programs are extracted from the Java book, the code in the book itself with the compiler run again, for beginners like me very good.
A few getting started applets for Java