Basic syntax of Java Basics (i.)

Source: Internet
Author: User

" Preface "

Java syntax first from the basic grammar, the Java language is composed of classes and objects , its objects and classes are composed of methods and variables , and methods, but also contains the statement and An expression .

    • Object : (almost) Everything is an object, such as: A panda, his appearance, the color, he is eating, drinking, sleeping, playing
    • class : If everything is an object, then what determines the appearance and behavior of a certain class of objects? A class is a template that describes the behavior and state of a class of objects.
    • class helloworld{/* This represents a class followed by a class name */}
    • method : (a method can also be called a member function ) method you can be seen as a behavior, a class can have many methods. Logical operations, data modifications, and all actions are done in a method.
    • variables : Each object has a unique instance variable, and the state of the object is determined by the value of these instance variables.

" First Java program "

 Public class hellowolrd {    /**     * First Java program * /public     Static  void  main (string[] args) {        //  print Hello        World System.out.println ("Hello World");}    }

Say save, compile, run this program

    1. Save this code with Notepad, save the file name to Hellowolrd.java (remember to display the file suffix name)

   

2. Open the DOS window to find your saved location (e.g. my location is D:\HelloWorld)

   

3. Switch the drive letter to your file storage directory

   

4. Enter Javac Helloworld.java carriage return, at this time HelloWorld folder should have more than one Helloworld.class file, this compiles this code

   

   

5. Re-enter Java HelloWorld print out Hello World

   

" basic Syntax "

1. Case -sensitive: case sensitivity, such as HelloWorld and HelloWorld are different

2. class name : The first letter of Java class name must be uppercase, and the class name like Usernamemanage, the first letter of each word should be capitalized, commonly known as "Hump name Law" in the big hump nomenclature (i.e.: Pascal named method)

3. method name : One word is lowercase for example: User, multiple words first lowercase, starting with the second word, each word capitalized for example: usernamemanage (Small hump nomenclature)

4. keywords : All lowercase, for example: public

5. Constants : All caps for example: PI

6. variables : Rules are named as methods

7. Package : All lowercase

"Java identifiers"

All components of Java require a name. Class names, variable names, and method names are called identifiers.

1. Use only letters, numbers, underscores, and dollar characters.

2. You can only start with a letter, underscore, and dollar symbol. That is, you cannot start with a number.

3. Strictly case-sensitive, no length limit. It is not recommended to be too long.

4. Should have a specific meaning, the keyword cannot be used as an identifier.

"java modifier"

Java can use modifiers to decorate methods and properties in a class. There are two main types of modifiers:

    • Access control modifiers: default, public, protected, private
    • Non-access control modifiers: final, abstract, STRICTFP

"java delimiter"
    • With: spaces, parentheses, curly braces, semicolons, and so on.
    • Each statement ends with a semicolon, either one line or multiple lines. Blocks are multiple statements contained within {}, and blocks can be nested. Whitespace is inserted in the middle of the element of the code: one or more spaces, or one or more tab spaces to form multiple blank lines.

"Java Annotations"

Writing program comments is an essential part. To do the standard, explicit, for the future development brought convenience.

 Public classHelloWorld {/**     * @paramargs * First Java program * This is a document comment*/     Public Static voidMain (string[] args) {/** This is a multiline comment*/System.out.println ("Hello World"); //Print Hello World (This is a single-line comment)System.out.println ("Hello World"); }    }

Not to be continued

Basic syntax of Java Basics (i.)

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.