In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the basic grammars for getting started with Java". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the basic grammars for getting started with Java"?
1. Notes
Comments are the interpretation and description of the code, which can improve the readability of the program, so it is very important to add the necessary comment text to the program. There are three types of comments in Java:
(1) single-line comments. Single-line comments are formatted with / /, and the text from / / to the end of this line will be used as comment text.
~ java
/ / this is single-line comment text
~ ~
(2) multiline comments. The format of multiline comments is to enclose a longer comment using / * and * /.
~ java
/ *
This is multiline comment text.
This is multiline comment text.
This is multiline comment text.
, /
Note: multiline comments cannot be used in nests.
~ ~
(3) document notes. The document comments begin with `/ * *` and end with `* /`.
2. Keywords
Keywords are words that are given special meanings by the java language. Keywords are characterized by their letters being all lowercase. Commonly used code editors highlight keywords, such as public, class, static, and so on.
3. Constant
Constant: the amount whose value cannot be changed while the program is running. Constant classification in Java (with the exception of empty constants, all constants can be output directly using output statements):
String constant: multiple characters (which can contain 0, one, or more) enclosed in double quotes, such as "a", "abc", "China", etc.
Integer constant: integer, for example:-10, 0, 88, etc.
Decimal constant: decimal, for example:-5.5, 1.0, 88.88, etc.
Character constant: a character enclosed in single quotation marks, such as'a','5','B', 'medium', etc.
Boolean constant: Boolean value, indicating true or false, with only two values, true and false
Null constant: a special value, null, with a value of null
~ java
Public class Demo {
Public static void main (String [] args) {
System.out.println (10); / / output an integer
System.out.println; / / output a decimal
System.out.println ('a'); / / outputs a character
System.out.println (true); / / output boolean value true
System.out.println ("Welcome to Dark Horse programmer"); / / output string
}
}
~ ~
4. Data type
(1) computer memory unit
We know that computers can be used to store data, but whether it is memory or hard disk, the smallest information unit of a computer storage device is called "bit", also known as "bit", which is usually represented by the lowercase letter "b". The most basic storage unit in a computer is called "byte", which is usually represented by the capital letter "B". The byte is made up of eight consecutive bits. In addition to bytes, there are some commonly used storage units, which are converted as follows:
1B (bytes) = 8bit
1KB = 1024B
1MB = 1024KB
1GB = 1024MB
1TB = 1024GB
(2) data types in Java
Java is a strongly typed language, and the data in Java must be explicitly typed. The data types in Java include basic data types and reference data types.
5. Variables
(1) definition of variables
Variable: the amount by which the value of a program can change while the program is running. In essence, a variable is a small area of memory whose value can vary within a certain range.
(2) the definition format of variables
```java
Data type variable name = initialize value; / / declare variable and assign value
Int age = 18
System.out.println (age)
`
Or
```java
/ / declare first, then assign (you can assign the value before use)
Data type variable name
Variable name = initialization value
Double money
Money = 55.5
System.out.println (money)
`
You can also define multiple variables of the same data type on the same row, separated by commas. However, this method is not recommended to reduce the readability of the program.
```java
Int a = 10, b = 20; / / define variables an and b of type int, separated by commas
System.out.println (a)
System.out.println (b)
Int cjournal d; / declares variables c and d of type int, separated by commas
C = 30
D = 40
System.out.println (c)
System.out.println (d)
`
The use of variables: access through the variable name.
(3) precautions when using variables
A. in the same pair of curly braces, the variable name cannot be repeated.
B. variables must be initialized (assigned) before they are used.
C. When defining variables of type long, you need to add L after the integer (uppercase or lowercase is recommended). Because integers are int by default, integers are too large and may be out of the int range.
D. When defining variables of type float, you need to add F after the decimal (uppercase or lowercase is recommended). Because the default type of floating point number is double, the value range of double is larger than float, and the type is incompatible.
At this point, I believe you have a deeper understanding of "what is the basic grammar for getting started with Java". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.