


[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)!

JavaachievesplatformindependencethroughtheJavaVirtualMachine(JVM),allowingcodetorunondifferentoperatingsystemswithoutmodification.TheJVMcompilesJavacodeintoplatform-independentbytecode,whichittheninterpretsandexecutesonthespecificOS,abstractingawayOS

Javaispowerfulduetoitsplatformindependence,object-orientednature,richstandardlibrary,performancecapabilities,andstrongsecurityfeatures.1)PlatformindependenceallowsapplicationstorunonanydevicesupportingJava.2)Object-orientedprogrammingpromotesmodulara

The top Java functions include: 1) object-oriented programming, supporting polymorphism, improving code flexibility and maintainability; 2) exception handling mechanism, improving code robustness through try-catch-finally blocks; 3) garbage collection, simplifying memory management; 4) generics, enhancing type safety; 5) ambda expressions and functional programming to make the code more concise and expressive; 6) rich standard libraries, providing optimized data structures and algorithms.

JavaisnotentirelyplatformindependentduetoJVMvariationsandnativecodeintegration,butitlargelyupholdsitsWORApromise.1)JavacompilestobytecoderunbytheJVM,allowingcross-platformexecution.2)However,eachplatformrequiresaspecificJVM,anddifferencesinJVMimpleme

TheJavaVirtualMachine(JVM)isanabstractcomputingmachinecrucialforJavaexecutionasitrunsJavabytecode,enablingthe"writeonce,runanywhere"capability.TheJVM'skeycomponentsinclude:1)ClassLoader,whichloads,links,andinitializesclasses;2)RuntimeDataAr

Javaremainsagoodlanguageduetoitscontinuousevolutionandrobustecosystem.1)Lambdaexpressionsenhancecodereadabilityandenablefunctionalprogramming.2)Streamsallowforefficientdataprocessing,particularlywithlargedatasets.3)ThemodularsystemintroducedinJava9im

Javaisgreatduetoitsplatformindependence,robustOOPsupport,extensivelibraries,andstrongcommunity.1)PlatformindependenceviaJVMallowscodetorunonvariousplatforms.2)OOPfeatureslikeencapsulation,inheritance,andpolymorphismenablemodularandscalablecode.3)Rich

The five major features of Java are polymorphism, Lambda expressions, StreamsAPI, generics and exception handling. 1. Polymorphism allows objects of different classes to be used as objects of common base classes. 2. Lambda expressions make the code more concise, especially suitable for handling collections and streams. 3.StreamsAPI efficiently processes large data sets and supports declarative operations. 4. Generics provide type safety and reusability, and type errors are caught during compilation. 5. Exception handling helps handle errors elegantly and write reliable software.


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

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!
