[Java tutorial 04] basic Java syntax, 04 java

Source: Internet
Author: User
Tags modifiers

[Java tutorial 04] basic Java syntax, 04 java

In the previous article, we ran a simple java program, but did not explain the content and meaning of the Code. Learning, we need to know it, but to know it, so this article will explain the basic syntax of the java program. After learning this article, you will look back.
In the previous article, you will find that it is a piece of cake. Now, let's get started with the theme!

A simple Java application

Next, let's take a look at a recent java application we have seen before. It only sends one Hello, Java! Message to the console window;

123456789 public class HelloJava{   public static void main(String args[]){     System.out.println("Hello,Java!");   } }

Although this program is simple, all Java applications have this structure. We started to study this most basic program.

Basic syntax
  • Case Sensitive: Java is case-sensitive. If a spelling error occurs, such as writing main into Main, the program will not be able to run.
  • Class and Class Name: The keyword class identifies the current code as a class. The keyword class is followed by the class name. HelloJava is the class name. The source code file name must be the same as the public class name (the class modified by public) for all classes, the first letter of the class name should be in upper case and can be followed by any combination of letters and numbers. The length is unlimited, however, the reserved words in Java cannot be used (for example, the class mentioned above and the public mentioned later). If the class name is composed of several words, the first letter of each word should be capitalized, for example, MyFirstJavaClass.
  • Access Control Modifier: The public keyword is the access modifier used to control the access level of other parts of the Code. In addition to public, default, protected, and private, these are also access modifiers. We will explain their usage in future articles.
  • Non-Access Control Modifier: The keyword static is the access modifier, marking the code as static. Other non-Access Control modifiers include final and abstract.
  • Curly braces {}: In Java, brackets are used to divide various parts of a program (usually called blocks ). Code for any method in Java starts with "{" and ends.
  • Method Name: All method names must start with a lowercase letter. If the method name contains several words, the first letter of each word is capitalized. In the above Code, main is the method name.Public static void main (String [] args)Method, calledMain method entry.
  • Return Value Type Declaration: Different Type values need to be returned after a method is executed. The return type of the main method is void, which indicates that no return value is returned. This section will be detailed in the method described later, now let's take a look.

After learning the basic syntax of Java, can you understand what the above Code means? Then I will describe it to you to see if your mind is the same.
The above Code describes a class named HelloJava, which contains a main methodSystem. out. println ("Hello, Java !");Is a Java statement that must end with a semicolon. This statement provides the function of outputting a text line to the console.

Note

Like other programming languages, Java also supports single-line and multi-line annotations. The characters in the comment will be ignored by the Java compiler.

In Java, there are three ways to write comments. The most common method is to use //. The comment content starts from // and ends with the end of the line. When the comment content is long, you can use/* and */to enclose a long comment. The third annotation can be used to automatically generate documents. This annotation starts with/** and ends.

12345678910 public class HelloJava{   /** This is the first Java program    * It will print Hello World    * This is an example of multi-line document comments.    */   public static void main(String args[]){          /* This is also an example of a single line comment */     System.out.println("Hello,Java!");// This is an example of a single line comment   }}

Reprinted, please note: Dumeng Bell» [Java Review 04] basic Java syntax

Related Article

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.