码迷,mamicode.com
首页 > 编程语言 > 详细

Java Language Programming Design (One)

时间:2015-03-14 06:05:48      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

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 are case sensitive.if the semicolon is missing.a brace is missing.a quotation mark is missing.or String is misspelled.thus the Java Compiler will 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 you can make more beautiful GUI program.

Chapter Two.      Elementary Programming

(1)Let us strat from two  programs Area.java and AreaConsoleInput.java

 1 public class Area {
 2     public static void main(String [] args){
 3         double radius=20;
 4         double Area;
 5         
 6         Area=radius*radius*3.141596;
 7         
 8         System.out.println("The area for the Circle is "+Area);
 9     }
10 }
 1 import java.util.Scanner;
 2 
 3 public class AreaConsoleInput {
 4     public static void main(String [] args){
 5         double radius;
 6         double Area;
 7         
 8         Scanner Input=new Scanner(System.in);
 9         radius=Input.nextDouble();
10         Area=radius*radius*3.141596;
11         
12         System.out.println("The area for the Circle is "+Area);
13     }
14 }

(2)Identifies

Note:Some rules must be 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 is case sensitive.

(3)Variables

Note:By convention,variable name are 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 an expression that evaluates to the value to be assigned to the variable on the left-hand side of assignment operator.Finally,the data type of the variable on the left must be 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 are named uppercase.

(6)Numerical Data Types and Operations

Note:we must keep the memory space for variables of different data types and their range in our mind.

please look the following examples.

1 public class TestIntRange {
2     public static void main(String [] args){
3         int a=2147483647+1; //The value of a is -2147483648
4         int b=-2147483648-1; //The value of b is 2147483647
5         System.out.println("The value of a is "+a);
6         System.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)

标签:

原文地址:http://www.cnblogs.com/IdeaSpark-01/p/4336791.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!