HelloWorld2 program analysis
// HelloWorld2.java - simple variable declarationsclass HelloWorld2 {public static void main (String [] args) {String word1; // declare a String variable String word2, sentence; // declare two more word1 = "Hello,"; word2 = "World!"; Sentence = word1.concat (word2); system.out.println (senence);}}
The equal sign (=) is an assignment operator that saves the value in the variable. Concatenation initialization statement can merge:
// HelloWorld3.java - Simple Variable DeclarationsClass HelloWorld3 {Public Static Void Main (String [] args) {string Word1 = "Hello," Word2 = "World!", SENTENCE = Word1.concat (Word2); System.out. Println (Sentence);}}
Each ";" represents the end of a statement, so saying the above program.
String Word1 = "Hello,", Word2 = "World!", SENTENCE = Word1.concat (Word2);
Still a statement, just two lines of writing. Writing habits are generally two grids backward (when indentation is 4 spaces). Comparison of strings, identifiers and variables
//StringVsId.java - contrast strings and identifiersclass StringVsId {public static void main (String [] args) {String hello =; String stringVary; stringVary = hello; System.out.println (stringVary); stringVary "Hello, world!" = "Hello"; System.out.Println (StringVary);}}
Nothing is well explained, the repeated assignment of the same variable (StringVary).