Java Basic syntax

Source: Internet
Author: User

A Java program can be thought of as a collection of a series of objects that can work together by invoking each other's methods.

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 state and behavior of a class of objects.

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.

A simple Java program that prints a string.

1  Public classHelloWorld {2      //It will print the string Hello world3      4      Public Static voidMain (String []args)5      {6System.out.println ("Hello World"); 7         //Print Hello World8      }9}

Note objects when editing a Java program:

1. Case: Java is case-sensitive, which means that the identifier Hello and hello are not the same.

2. Class name: For all classes, the first letter of the class name should be capitalized. If the class name consists of multiple words, the first letter of each word should be capitalized, such as MyName.

3. All method names should start with a lowercase letter. If the method contains more than one word, it should be capitalized in the first letter.

4. Original file name: The source file name should be the same as the type 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.

5. Main Method Portal: All Java programs are executed by the public static void main (String [] args) method.

Java variables:

Local variables

class variables (static variables)

Member variables (non-static variables)

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.