1. A Simple Java Program
2. Comments
3. Data Types
4. Variables
5. Operators
6. String
7. Input and Output
8. Control Flow
9. Big Numbers
Ten. Arrays
1. A Simple Java Program
1 Public class simple_java{2 Public Static void Main (string[] args) {3 System.out.println ("Hello world!" ); 4 }5
Java is case sensitive (casing-sensitive). If you made any mistake in capitalization (such as typing main instead of main), the program would not run.
The keyword public was called an access modifier (access control modifier). These modifiers control the level of access other parts's program has to this code
The keyword class reminds you, everything in a Java program lives inside a class.
Following the keyword class is the name of the class.
You need to make the file name for the source code the same as the name of the "public class" with the extension. Java AppE nded.
We is using the System.out object and calling its Println method. Java uses the general Syntax:Object.method (parameters)
When you compile this source code, you end up with a file containing the bytecodes for this class. The Java compiler automatically name
The bytecode file Simple_java.class and stores it in the same directory as the source file. Finally, launch the program by issuing the following command:
Java firstsample
To run a compiled program, the Java Vsan always starts execution and the code in the main method in the class you indicate.
2. Comments
3. Data Types
In Java, your use of the keyword final to denote a constant.
' A ' is a char Type with value 65.It is differnet from "a", astring containing a signle character.
Java strings is sequences (sequence) of the Unicode characters.
3.1 Substrings
You can extract a substring from a larger string with the substring method of the string class.
1 1 string greeting = "Hello"; 2 string s = greeting. Substring (0,3);
Creates s string consisting of the characters "Hel"
Chapter 3 fundamental programming structures in Java