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

Chapter 3 Fundamental Programming Structures in Java

时间:2014-09-21 14:43:00      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   io   java   ar   for   div   

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

10. 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(区分大小写的).If you made any mistake in capitalization(such as typing Main instead of main), the program will not run.

  The keyword public is called an access modifier(访问控制修饰符). these modifiers control the level of access other parts of program have to this code

  The keyword class reminds you that 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 appended.

  We are 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 virtual machine always starts execution with the code in the main method in the class you indicate.

 

2. Comments

 

3. Data Types

  In Java, you use 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 are sequences(序列) of 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

标签:des   style   blog   color   io   java   ar   for   div   

原文地址:http://www.cnblogs.com/iMirror/p/3984469.html

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