


[Java Getting Started Notes] Java Language Basics (1): Comments, Identifiers and Keywords
Annotations
What are annotations?
Comments are explanatory text for a certain piece of code, a certain method, or a certain class when we write code to facilitate everyone's reading of the code. The commented content will not be compiled or executed.
Java comments are divided into three types: single-line comments, multi-line comments, and document comments.
Single-line comments and multi-line comments
Single-line comments comment on a line of text or code in the program. In Java, use "//" for single-line comments. Multi-line comments can comment multiple lines of code at one time. In Java, "/*" is used to indicate the beginning of a multi-line comment, and "*/" is used to indicate the end of a multi-line comment.
Example:
public class CommentTest{ public static void main(String[] args){ //这是单行注释 /* 多行注释第一行 第二行 */ //System.out.PRintln("被注释的代码不会编译和运行"); System.out.println("未被注释的代码"); } }
Eclipse comment shortcut key: Ctrl+/ single-line comment and uncomment; Ctrl+Shift+/ to add /* */ comments; Ctrl+Shift+ to eliminate /* */ comments
Documentation comments
Comments added using documentation comments can be used to generate API documentation through the documentation generation tool javadoc, which is only processed by the javadoc tool Comments in front of classes, interfaces, methods, Fields, constructors and internal classes modified with public and protected in the document source text.
Documentation comments end with "/**"Start with "*/". The middle part is the documentation comment, which will be generated into the API documentation.
Example:
/** * 这是一个文档注释的测试类 * @author ping * */public class Test { /** 这是一个Filed */ public int i; /** * 这是程序的main方法 * @param args */ public static void main(String[] args) { } }
Regarding generating Java API documentation, you can refer to the following two articles:
Use the javadoc command to generate api help documentation
How to generate javadoc with eclipse
Identifiers and keywords
Separators
In Java Delimiters include semicolons (;), braces ({}), square brackets ([]), parentheses (()), spaces, and dots (.). All symbols are English symbols. This is when writing Pay special attention when coding.
Semicolon: In Java, a newline cannot represent the end of a statement. Only a semicolon represents the end of a statement. Therefore, it is theoretically possible to write multiple statements in one line, but this is not recommended as it will affect the readability of the code. Makes the code look cluttered.
Braces: A pair of curly braces represents a statement block and needs to appear in pairs.
Square brackets: used for arrays, used when defining arrays and accessing array elements. They also need to be used in pairs.
Parentheses: Used to include formal parameters when defining methods, calling methods and constructors, requiring parentheses.
Space: Used to separate multiple parts of a statement.
Dots: Used as members of objects and classes.
Identifiers
Identifiers are symbols used to name classes, methods, and variables in a program. Java identifiers have the following characteristics:
Case-sensitive.
Must start with a character, underscore, and dollar sign, and can be followed by four elements: characters, underscore, dollar sign, and numbers. Characters are not limited to English characters, but can be characters from various countries such as Chinese characters.
Cannot contain special symbols other than underscores and spaces.
cannot be a keyword in Java.
public class Test{ //Test is an identifier
public static void main(String[] args){ //main args is also an identifierint a = 1;
int A = 1; //a and A are Two different identifiers int $i = 2; //The identifier is correct int 123 = 123; //The identifier is wrong int i123 = 123; //The identifier is correct int i_1 = 1; //The identifier is correct int i.1 = 1; //Error int class = 2; //class is a keyword, error}
}
Keywords
Java contains a total of 48 keywords and two reserved words (goto/const).
The above is [Java Introduction Notes] Java Language Basics (1): Comments, identifiers and keywords. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Start Spring using IntelliJIDEAUltimate version...

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Java...

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools