Java Initial phase

Source: Internet
Author: User

Initial contact feeling Java and C language have a lot of similarities.

Java Origins:

The father of Java: James Gosling

Official release date: May 23, 1995

It features: Simple, object-oriented, portable, multi-threading, dynamic

It is compiled as: bytecode, with the suffix name:. class

Two components of its platform: Java Virtual machine (JVM); Java application Programming Interface (JAVAAPI)

Look at this helloword Java program source code:

1  Public class helloword{    // class 2publicstaticvoid main (string[] args) {       // entrance method 3  System.out.println ("Hello, Word");    // Output 4 5   } 6 }   

Java identifiersNaming rules for:
1) identifiers by letters, numbers, underscores"_", dollar sign"$" or renminbi symbol"¥", and the first letter cannot be a number.
2) cannot put keywords and reserved wordsAs an identifier.
3) identifiers do not have a length limit.
4) The identifier is case sensitive.

Java programming specification:
1) class name and interface name: capitalized The remaining letters are lowercase. such as Samdoc
2) method name and variable name: first letter lowercase, the remaining letters capitalized.
such as Botheyesofdoll.
3) package name: all lowercase letters. For example, Com.abc.dollapp.
4) Constant name: in uppercase, the words are separated by an underscore "_".

  such as Default_color_dol

5) See the meaning of the name

Java data type :

1) Basic types: Shaping (byte,short,int,long), floating-point (fioat,double), char (char), Boolean (Boolean[true,false])

2) Reference type: Class, Interface (interface), array

Java in various formats :

1) Generate random number (0-99):

1  Public class number{2      Public Static void Main (string[] args) {3         int random= (int) (Math.random () *100); // receive random number generated by 4         SYSTEM.OUT.PRINTLN (random); // Output 5     }            6  }    

2) Receive input:

1 ImportJava.util.Scanner;2 3   Public classnumber{4       Public Static voidMain (string[] args) {5Scanner input=NewScanner (system.in);6System.out.print ("Enter a number:");7          intNum=input.nextint ();//Receive input8System.out.println ("The number you entered is:" +num);9      }            Ten}

3) Compare strings for equality: if ("string". Equals (variable name))
4) The minimum value representation of integers: integer.min_value

5) Constant: Final data type constant name = value; constant name usually uppercase

Java Selection statement:

1) SELECT statement (if statement, If/else statement, switch statement)

If statement

if (Boolean expression) {

Statement executed if the Boolean expression is True

}

If/else statements

if (Boolean expression) {

Statement executed if the Boolean expression is True

}

Else {

Executes when the Boolean expression is False

}

Switch statement

  Switch Variable {

Case Value:

Statement

Break

Case Value:

Can have a lot of statements

Break

Default

Statement

}

2) Loop statement (while, Do/while, for)

While loop

while (Boolean expression) {

Statement

}

Do/while Cycle

Do {

Statement

}while (Boolean expression)

For loop

   for (Initialize; Boolean expression; update) {

Statement

}

3) Jump statement: break; end the loop at the level, continue end the cycle

About packages (Maintenance management classes):

The package declaration must be the first executable statement in the source file, named with an inverted organization domain name

Fully qualified name: Pkg. Package name. Class Name

Java class:

1) Access modifiers: Public shared, protected protected, private private

2) Two representations of the method:

1  Public // has a return value 2     return // method Body (function code block to be implemented) 3 }

   Public void // no return value     // method Body  }

3) member variable: written outside the method (the system default initial value string is a null number of 0 and can be used in all methods)
Local variables: Written in the method can only be used in this method

Java objects:

1) Create object: The original class name. Object name =new. Original class name

Call object's properties: Object name. property name

method to invoke object: Object name. Method name ([argument list])

2) The class is the type of the object, and the object is an instance of the class

     

Java Initial phase

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.