Java Basic Syntax

Source: Internet
Author: User

A Java program can be thought of as a collection of a series of objects that work together by invoking each other's methods. The following is a brief introduction to the concepts of classes, objects, methods, and instance variables.

  • Object : An object is an instance of a class that has state and behavior. For example, a dog is an object whose state is: color, name, variety, behavior: wagging the tail, barking, eating, etc.
  • class : A class is a template that describes the behavior and state of a class of objects.
  • method : The method is the behavior, a class can have many methods. Logical operations, data modifications, and all actions are done in a method.
  • instance variables : Each object has a unique instance variable, and the state of the object is determined by the value of these instance variables.
  • Basic syntax

    The following points should be noted when writing Java programs:

    • case-sensitive : Java is case-sensitive, which means that the identifier Hello is different from hello.
    • class name : For all classes, the first letter of the class name should be capitalized. If the class name consists of several words, the first letter of each word should be capitalized, such as Myfirstjavaclass.
    • method Name : All method names should start with a lowercase letter. If the method name contains several words, the first letter of each subsequent word is capitalized.
    • source file Name: The source file name must be the same as the class name. When saving the file, you should use the class name to save the filename (remember that Java is case-sensitive), and the suffix of the file name is. java. (a compilation error is caused if the file name and the class name are not the same).
    • Main Method Entry : All Java programs are executed by the public static void main (String []args) method.
    • Java identifiers

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

      For the Java identifiers, there are a few things to note:

      • All identifiers should start with a letter (A-Z or a-Z), a dollar symbol ($), or an underscore (_).
      • The first character can be a letter (A-Z or a-Z), a dollar symbol ($), an underscore (_), or any character combination of a number
      • Keyword cannot be used as an identifier
      • Identifiers are case-sensitive
      • Examples of legal identifiers: Age, $salary, _value, __1_value
      • Examples of illegal identifiers: 123abc,-salary
      • Java modifier

        Like other languages, 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

        In a later chapter we'll go into the Java modifier in more detail.

      • There are several types of variables in Java variable java.
        • Local variables
        • class variables (static variables)
        • Member variables (non-static variables)
      • OK, today's share is here, need to know more friends comments below, 666!!!

Java Basic Syntax

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.