Chapter one. Introduction to JAVA
(1) Preliminary knowledge
A) Java Language specification
b) Java API
c) Java Edition:java Se,java Ee,java ME
d) Java ENVIRONMENT:JDK,JRE,JVM
e) Java Development Tools:eclipse,myeclipse,netbeans ...
Note:you can also run a Java program by using Java Command.
(2) A Simple Java Program//welcome.java
1 Public class welcome{2 Public Static void main (String [] args) {3 System.out.println ("Welcome to Java.") ); 4 }5 }
NOTE:A) Java Source Programs is case sensitive.if The semicolon is missing.a brace was missing.a quotation mark is missing. Or String is Misspelled.thus the Java Compiler would report syntax error.
b) Procedure:edit (. java) →compile (. Class) →execute (?)
(3) A Simple Java GUI program//welcomeinmessagedialogbox.java
1 Import Javax.swing.JOptionPane; 2 Public class Welcomeinmessagedialogbox {3 Public Static void main (String [] args) {4 Joptionpane.showmessagedialog (null, "Welcome to Java.") ); 5 }6 }
Note:if you want to learn further,please refer to JAVA Api.thus your can make more beautiful GUI program.
Chapter. Elementary Programming
(1) Let us strat from programs Area.java and Areaconsoleinput.java
1 Public classArea {2 Public Static voidmain (String [] args) {3 DoubleRadius=20;4 DoubleArea ;5 6area=radius*radius*3.141596;7 8System.out.println ("The area for the Circle is" +Area );9 }Ten}
1 ImportJava.util.Scanner;2 3 Public classAreaconsoleinput {4 Public Static voidmain (String [] args) {5 Doubleradius;6 DoubleArea ;7 8Scanner input=NewScanner (system.in);9radius=input.nextdouble ();Tenarea=radius*radius*3.141596; One ASystem.out.println ("The area for the Circle is" +Area ); - } -}
(2) Identifies
Note:some rules must is obeyed for identifies.
A) It consists of letters,digits,underscores and dollar signs.
b) It must start with a letter, an underscore or a dollar sign.rather than a digit.
c) It can ' t be a reserved word in Java specification and Java API.
d) It can be of any length or language. Chinese is okay.however it's case sensitive.
(3) Variables
Note:by convention,variable name is in lowercase. If A name consists of several words,concatenate all of them and capitalize the first letter of each word except the first. Furthermore,we can declare a variable and initialize it in one step.
(4) Assignment Statements and Assignment Expressions
Note:firstly,we must distinguish it from equation in mathematics. Then,an assignment statement is essentially a expression that evaluates to the value to being assigned to the variable on th e Left-Hand side of assignment operator. Finally,the data type of the variable on the left must is compatible with the data type of the value on the right.
(5) Constants
note:a keyword Final is used to declaring a constant in Java.and constants often is named uppercase.
(6) Numerical Data Types and Operations
Note:we must keep the memory space for variables of different data types and their range
Please look the following examples.
1 Public classTestintrange {2 Public Static voidmain (String [] args) {3 inta=2147483647+1;//The value of a is-21474836484 intB=-2147483648-1;//The value of B is 21474836475System.out.println ("The value of A is" +a);6System.out.println ("The value of B is" +b);7 }8}
Standard arithmetic Operators:addition,substraction,multiplication,division,and remainder.
(7) Shorthand Operators
(8) Numeric Type Conversions
(9) String
(10) Programming Styles and documentation.
A) naming Styles:use lowercase for variables.
Concatenate all of them and capitalize the first letter of each word except the first for method
Capitalize the first letter of each word in a class name
Capitalize every letter in a constant.
b) Statement Styles:approximate Space and Indentation.keep block Styles.
c) Comment Styles:add some Comment in your program.
Java Language Programming Design (one)