java (Hello World) variables and constants Notes

A .java entry procedures

Java brief language

Features on java language:
(1) simplicity
and c ++ compared, no java file header, pointer, etc. operator overloading, java language equivalent of a purer version c ++.
(2) object-
java is a pure object-language.
(3) distributed
java develop a library of routines for processing Http / Ftp like Txp / Ip protocol.
java objects on the network can be opened by the url accessible, convenient program as its local access
(4) robustness
java put a lot of effort, we can detect problems early, late dynamic testing, and eliminates the tendency to have an error state, and c ++ difference is that the possibility of using a pointer model memory and corrupted data can be eliminated.
(5) security
java for networking / distributed environment, put a lot of effort in terms of security, anti-virus can be constructed using java stack heap overflow prohibition run their own space prohibit unauthorized read and write files.
(6) portability
across platforms: the JVM role: to interpreted bytecode files. Interpreted differently, which can play a role in cross-platform based on different platforms, the "compile once, run anywhere."

 

Hello World program entry

/ * 
   Note: 
      back 1.class class name to the file name and our consistent 
      2. All punctuation writing programs must be in English 
      3. Do not write the main method mian method 
      String methods first 4.main in parentheses capitalized 
* / 

// is the name of a class 
public  class Demo01HelloWorld {
     / * 
        main method is the entry program is run from the main method entered 
    
    * / 
    public  static  void main (String [] args) {
         // is an output statement ( print statements), write what would parentheses what output 
        System.out.println ( "the Hello World" ); 
    } 
}

II. Single line comment (a plurality of rows can be nested) and a multi-line comments (not nested)

What is a comment?

The interpretation of the code description is not involved in running code

1. Single-line comments

class the Hello // This is declaration of a class, the class name is the Hello // single line comment can be nested 
{
     public  static  void main (String [] args) // This is the main method, a program entry is 
    { 
        the System.out. println ( "the Hello World!"); // this is the output statement, the console will output a word. 
    } 
}

2. Multi-line comments

/ * 
Lee West by the Yellow Crane Tower, 
the fireworks in Yangzhou. 
This is a multi-line comments can not be nested. 
* /

3. Documentation Comments

/ ** 
 * This is the documentation comments, this format is for convenience of automatic program generation javadoc document. 
 * /

Introduce some javadoc tags

Special:  

(1) javadoc generated documentation for public comment class

(2) javadoc only on public, protected, or a modified method properties

Format (3) javadoc Notes: * number of leading and HTML tags

(4) javadoc Note alone prior to classes, attributes, methods

The following illustrate application of the third main comments:

(1) First, write .java file

(2) execute the following command line in dos:

javadoc * .java // according to the corresponding Java source code and its description statements to generate HTML documents

// javadoc tag: @ is the beginning of, for javadoc, special mark.

(3) will have a doc folder in the current directory, there are a series of .html file

Attach Code:

[Java] Plain View Copy

 <span style = "font-size: 18px;"> * / / ** 
 * content javadoc comment * / public class the Hello { / ** comments on the property * / public String name; / * * this is the main method of the program is the entry 
     * @param args user input parameters * / public static void main (String [] args) { 
        System.out.println ( "the Hello World!" ); 
        F1 (); 
    } / * * this is the first method, its role is ... * / public static void F1 () { 
        System.out.println ( "F1 ()!" );


 

 

    

    

    


     

      




    

      


    } 

} </ Span> 

[Java] Plain View Copy

 <span style = "font-size: 18px;"> Import java.io.IOException; 

/ ** Javadoc annotation content 

 * @Since 1.0 

 * @version 1.1 

 * @author Blue jey 

 * <br> link to another document { @link the Hello}, these 

 * See the Hello 

 * / 

public  class the HelloWorld { 

    / ** non-public, notes on the protected attribute is not generated * / 

    public String name; 

    / ** this is a main method, a program entry 

     * @param args parameter input by the user, is an array 

     * @throwsMethod IOException main exception io 

     * / 

    public  static  void main (String args []) throws IOException { 

        System.out.println ( "Hello World!" ); 

        F1 (); 

        F2 ( . 1 ); 

    } 

    / ** This is the first a method that functions .... 

     * the @deprecated from version 1.2, this method is not recommended to use 

     * / 

    public  static  void F1 () { 

        System.out.println ( "FL ()!" ); 

    } 

    / * * this is the second method, its role is .... 

     * @return returns whether the OK 

     * @param i input parameter i

     *@see Hello

     *@throws IOException io异常 

     */

    public static String f2(int i)throws IOException{

        System.out.println("f1()!");

        return "OK";

    }

} </span>  

note:

If the source file is useful to @ version, @ author tags when you execute javadoc command to add -version -author 

javadoc -version -author -d doc *.java

(Which is used by -version version information to extract the source files for -author of information extraction in the source file)

 

III. Keyword

What is the key?

Java has a special meaning of its own definition of the word (lower case)

How to distinguish?

Advanced Notepad is not the same color

IV. About packages. Method interface. Constant naming

Package (actually a folder to solve the same problem class name)
naming convention:
package name all lower case requirements, usually the company domain name written backwards.
Company domain: www.qingmu.com
package name: com.qingmu
action package: in fact, the folder for the same class name to address the problem.

标识符:

什么是标识符?

写程序的时候,自己定义的名字

 

类或者接口
命名规则为: 一个单词时候,首字母大写,多个单词时候,要求每个单词的首字母大写(驼峰)。

方法或者变量
命名规则: 一个单词时候,每个字母都是小写,多个单词时候,从第二个单词开始首字母大写。
但是变量现在可以使用全是小写.

常量
命名规则: 一个单词时候,所有字母大写,多个单词时候,每个单词都是大写,但是用_连接。
举例: MAX
MAX_VALUE

五.常量

常量:
概述:在代码运行的过程中,值不会改变的量

分类:
整数常量: 所有的整数 1,2,3,4,5,6,7 -1 -2
小数常量: 带有小数点 1.2,3.5,5.7,-1.5
字符常量: 带单引号 '字符' 单引号中只能出现一个字符 'a' '1' 'A' '0' '中' ('中1' 'AA' '')
字符串常量:带双引号 "内容" 双引号中可以写0个或者更多个字符串内容 "" "学习" "1" "haha" "hehe" "hiahia"
布尔常量: true false
空常量:null 代表啥都没有 不能直接使用

public class Demo02ChangLiang{
    public static void main(String[] args){
        //整数常量
        System.out.println(-1);
        //小数常量
        System.out.println(1.2);
        //字符常量
        System.out.println('1');
        //System.out.println('a1');
        //System.out.println('');
        
        //字符串常量
        System.out.println("java很好学");
        System.out.println("");
        
        //布尔常量
        System.out.println(true);
        
        //空常量
        //System.out.println(null);不能直接使用
    }
}

六.变量

变量:
概述:在代码的执行过程中,值能够改变的量

数据类型:
基本数据类型:4类8种
整型:byte short int long
浮点型:float double
字符型:char
布尔型:boolean

引用数据类型
类 数组 接口


注意:
整数的默认类型是int 小数的默认类型是double

定义格式:
数据类型 变量名;
变量名 = 值;

数据类型 变量名 = 值;

扩展:字符串不是基本数据类型,但是定义格式可以和基本数据类型的格式一样
String s = "abc";

public class Demo03Var{
    public static void main(String[] args){
        //定义一个byte类型的
        byte num1;
        num1 = 10;
        num1 = 20;
        System.out.println(num1);
        
        //short
        short num2 = 30;
        num2 = 50;
        System.out.println(num2);
        
        //int
        int num3 = 90;
        System.out.println(num3);
        
        //long
        long num4 = 100L;
        System.out.println(num4);
        
        //float
        float num5 = 2.5F;
        System.out.println(num5);
        
        //double
        double num6 = 2.6;
        System.out.println(num6);
        
        //char
        char num7 = 'a';
        System.out.println(num7);
        
        //boolean
        boolean num8 = true;
        System.out.println(num8);
        
        boolean num9 = false;
        
        num9 = num8;//num8是true  将num8的true给了变量num9
        System.out.println(num9);
        
        //String
        String s = "柳岩~~~";
        System.out.println(s);
        System.out.println("---------------");
        
        int x,y,z;
        x = 10;
        y = 20;
        z = 30;
        System.out.println(x);
        System.out.println(y);
        System.out.println(z);
        System.out.println("---------------");
        int i = 10,j = 20,t = 40;
        System.out.println(i);
        System.out.println(j);
        System.out.println(t);
        
    }
}

变量的注意事项:
1.变量没有初始化(第一次赋值),不能直接使用
2.在一个大括号中不能出现相同名字的变量
3.变量没有定义,不能使用
4.不同的作用域中的变量(一对大括号),尽量不要相互使用

public class Demo04VarNotice{
    public static void main(String[] args){
        //int i;
        //System.out.println(i);
        int i = 10;
        //int i = 20;
        System.out.println(i);
        //System.out.println(j);
        
        {
            
            int x = 100;
            System.out.println(x);
            System.out.println(i);
        }
        //System.out.println(x);
    }
}

 

Guess you like

Origin www.cnblogs.com/qingmuchuanqi48/p/11184526.html