4-java Syntax 1 (not completed)

Source: Internet
Author: User

The following contents are derived from the Mu-class network data Collation.

1  package com.imooc; 2 3  public class helloworld{4publicstaticvoid  main (string[] Args) { 5 System.out.println ("hello imooc"); 6 }7 }   

one: keywords in JAVA

  The keywords in Java are case-sensitive, the following are common keywords, without rote, practice makes Perfect.

  

two: JAVA Identifiers

identifiers are used to give A named symbol of a variable, class, method, etc. in a Java program. As in the above program, Com.imooc and HelloWorld are identifiers .

There are several rules to follow when using identifiers:

  1.   Span style= "font-family: arial" > identifier can _ $ ) but cannot contain @ % 123name 

  2. identifiers cannot be java keywords and reserved words ( java reserved keywords, which may be used as keywords in later versions of the upgrade), but can contain keywords and reserved words.

For example, void may not be used as an identifier, but myvoid can

  3. identifiers are strictly case -sensitive. so nirvana, be sure to distinguish between Chu Imooc and IMOOC is two different identifiers oh!

   4. The name of the identifier should best reflect its role, to be known .

 Three: variables

Simply put, we can think of variables as a box that can store items such as keys, cell phones, and drinks in this box, or we can replace them with new items that we want to store when we need them.

  

in Java , we describe variables by three elements: variable type, variable name , and variable value .

If we compare a variable to a hotel room, the data to be stored is like the guest who wants to stay, we can arrange it according to Guest's request " Standard room " or " Presidential Suite ", and you can quickly find the guest information based on the name of the ROOM. in the same vein, in a Java program, We can also save it in a variable space of the specified type according to the format of the data we need to save, and quickly locate it with the variable name!

  

for example, We define a variable love , which is used to hold a string "imooc", in which only the love variable is found. You can find the "imooc"stored in it! Of course, We can also Change the value of love into a new string "i love imooc" !

  

Operation Result:

  

four: How to name JAVA Variables

As the hotel will give each room a personalized name, the variables in the program also need to use a reasonable name for the management --- variable name!

It is important to note that the name of the hotel room can be a number, such as "802", can also be interesting names, such as " peony "," president of the United States " , " water Curtain Cave " , But when you give the variable a name, you must conform to certain rules , as shown below:

  

The following variables are named in accordance with the Specification:

  

But take a look at the following code, you know Ha:

  

The habit of good siege master:

    1. When the variable name consists of multiple words, The first letter is lowercase , and then the first letter of the word is capitalized , commonly known as the Camel-named method (also called the hump nomenclature), such as MyAge

2, variable name, as short as possible and can clearly express the role of variables, to do See the meaning stuname  save " Span style= "font-family: song body" > student name information

  PS: There is no limit to the length of the Java variable name , but the Java language is case-sensitive , so Price and price are two completely different variables oh!

  JAVA variable usage rules:

have to accept the variable Little Temper :

    1. variables in Java need to be declared and then used

      

    2.When variables are used, they can be initialized at the same time as the variables are Declared.

      ,

You can also assign a value after declaring it first

      

    3. Only one value can be assigned at a time in a variable, but multiple times may be modified

      

    4. the variables defined in the main method must be assigned before the output

      

    5, although there is no error in the syntax, but in the actual development, the variable name is not recommended to use chinese, easy to create security risks, such as the late Cross-platform operation garbled and so on

      

five: JAVA Data Types

in general, in order to facilitate the storage of goods, we will specify the type of items each box can store, like in the " Smelly socks box " we will not put " Bread " the!" similarly, The storage of variables also pay attention to " categorize "!

The Java language is a strongly typed language. The popular point is that the data stored in Java is typed and must be determined at compile Time. There are two kinds of data types in Java:

    

in the Java domain , the basic data type variables are stored in the data itself , whereas the reference type variables are stored The spatial address of the data . frankly, the basic data type variables are stored directly in the drawer, and the reference data type variable is stored in the drawer key, key and drawer one by one corresponding.

The common basic data Types Are:

    

You may have noticed:

  

note: The difference between the float type and the double type, and the char type and String type, are /c9>wiki has the relevant summary, the small partners can go to see Oh ~ ~

   String is a common Reference Data Type , which is used to represent a string. In the development of programs, many operations are done using strings, such as user names, passwords, e-mail addresses, etc. in the System.

4-java Syntax 1 (not completed)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.