Introduction to Java - Basic Grammar (02)

Java environment configuration

To program java, you must first configure the java environment required for java to run. There are also many tutorials on the Internet, so I won’t go into details here.

Integrated development environment installation:

Both eclipse and IntelliJ IDEA are available

eclipse: free , small installation package, insufficient code prompts and completions are not smart enough, plug-ins are not very practical, and it is concluded that debugging is also very convenient and intelligent. Students can apply to use the qualification for free.

IntelliJ IDEA (cracked version is available), more powerful and smarter than eclipse.

Java syntax

A Java program is like a collection of objects that work together by calling each other's methods.

• Object: An object is an instance of a class with states and behaviors. For example, a dog is an object with states: color, name, breed; behaviors: tail wagging, barking, eating, etc.

• Class: A class is a template that describes the behavior and state of a class of objects.

• Methods: Methods are behaviors, and a class can have many methods.

• Instance variables: Each object has unique instance variables, and the state of the object is determined by the values ​​of these instance variables.

first java program

public class HelloWorld {  
 	 /* 第一个Java程序    
​      *它将输出字符串 Hello World    
   	  */    
​	public static void main(String[] args) {       
​		System.out.println("Hello World"); // 输出 Hello World   
​	} 
}

Without running the software, you can search for Java online and edit Java online tools | Cainiao Tools (runoob.com)

basic grammar

  • Case Sensitive : Java is case sensitive, Hello is different from hello.
  • Class names : 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 HelloWorld .
  • Method names : 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 as the file name, with the suffix  .java .
  • Main method entry : All Java programs  are executed from the public static void main(String[] args)  {  } method.

Java variables

  • Local variables: also known as internal variables, defined in the code block enclosed by curly braces.
  • Class variables (static variables): declared with the static keyword in the class, and must be outside the construction method and statement block.
  • Member variables (non-static variables): You cannot use this, super keywords, and can be used in static methods, non-static methods, and non-static variables.

Java data types

Basic data types: integer (byte, short, int, long such as: 1-1212), floating point type (float, double such as: 1.2), character type char such as: "good", boolean used to represent the true value, Such as: true.

Guess you like

Origin blog.csdn.net/qq_34445909/article/details/122481622