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 > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the basic grammar of Java". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the basic grammar of Java"?
Prepare for work Dos command
Configure environment variables
Understand the difference between jdk, jre, and jvm
Environment variable configuration: JAVA_HOME in Path is the installation directory of jdk, add% JAVA_HOME%\ bin to Path
API source code read [src.zip]
Some html syntax is used in the source code
Start-- JAVA basic grammar notes
Multiline comments / * /
Documentation Notes / * * /-- javadoc generate help documentation
Identifier-keyword
Any place where you can name yourself is called an identifier. For example: variable name, method name, class name, interface name, package name
Naming rules:
Consists of 26 uppercase and lowercase letters, 0-9, _ or $
Numbers cannot begin.
Keywords and reserved words cannot be used, but can contain keywords and reserved words.
In Java, it is strictly case-sensitive and unlimited in length.
Identifiers cannot contain spaces.
Command specification:
Variable, method-- myVariable, myMethod (xxYyZz)
Class, interface-MyClass (uppercase), MyInterface (XxYyZz)
Package-packet (xxyyzz)
Constants are all capitalized and words are separated by "_"-DEFAULT_SIZE (XX_YY_ZZ)
Variable
Strongly typed language
Data type, variable name, stored value type varName [= value]
Data type basic data type
Type Bytes Integer byte1
Short2
Int (default) 4
Long8 floating point number float4
Double (default) 8-character char2 Boolean Boolean 1 bit
Note:
The number of char bytes in java, which is 2 bytes, different from c (one byte)''has and only one character
With regard to the "default" problem, for example, 233 does not write a suffix and is stored on the computer according to int (4 bytes), but if it is written as 233L, it is stored according to long (8 bytes), and the more commonly used one is float, which is also followed by the suffix f, which is different from the default float type.
Financial computing, using BigDecimal
Escape character'\ u0000'
5.char can declare a character, or it can represent an escape character ('\ n'), or it can directly use the unicode value to represent a character-type constant ('\ u0043')
Write as\ n so that there is no escape.
6. Character set, there is garbled (conversion stream of IO stream)
ASCII → Unicode (specific landing is UTF-8)
When writing a file to determine the encoding type, such as ANSI (that is, GBK), the file form that exists on disk is in GBK form, only then can it be read normally in cmd (support GBK), but if the save form is changed to UTF-8, it will appear "garbled".
Type transformation
Only 7 data types (excluding boolean) have type conversions discussed here.
Automatic type conversion-low to high
In particular, byte,short,char are not converted to each other, and they are first converted to int type byte + byte → int byte + short → int in the calculation.
Regulation: Java is doing the operation. If the Operand is within the range of int, all operations will be performed according to int.
Forced type conversion-from high to low
Note: in basic data types, low represents fewer bytes, and in classes, low represents subclasses.
Long l = 123232L
Float f = 33.223F
Reference data type type occurrence form class class-- String interface interface array int [] arrays
Key point: String type variable
"" null is acceptable (char is not allowed)
String str1 = 123 (wrong) String str1 = 123 + "" (correct)
String can operate with 8 basic types (including boolean), and the operation can only be a join symbol: +
When concatenating the value of any basic data type with a string (String), the value of the basic data type is automatically converted to the String type
Connect to boolean, directly connect to true or false
/ / practice 1char c = 'averse; / / 97 A:65int num = 10 string str = "hello"; System.out.println (c + num + str); → 107helloSystem.out.println (c + str + num); → ahello10System.out.println (c + (num + str)); → a10helloSystem.out.println (str + num + c); → hello10a// exercise 2 / print * * System.out.println (' * +'\ tasking +'*') Char + char-- > int (93) System.out.println ('*'+ "\ t" +'*'); char + String-> String (* *) System.out.println ('*'+\ tasking + "*"); (51 *) System.out.println ('*'+ ('\ tasking + "*")); (* *)
Practice
Operator
Arithmetic operator
Assignment operator
Comparison operator (distinguish between = and =)
Logical operator (& and & relation)
Bit operator
Three-digit operator
Format: X? Y: Z = = > if x is true, take y; if false, take z
Double num = remainn)? "m big": ((m big n)? "m and n are equal": "n big")
Compare the maximum of three numbers
Int max1 = (N1 > N2)? N1: N2 int max2 = (max1 > n3)? Max1: n3
Note:
Priority: logic non-> logic and > logic or
Symbol +, there are some skills to use.
"" +'a complete string addition'
However, it becomes the number 97.
Process control
Sequential structure
Select structure
The switch statement starts at the matching case tag based on the value of the expression and executes all the way to the break statement or the end of the switch statement. If the value of the expression does not match any of the case values, enter the default statement if there is a default statement.
Loop structure continue: launch this loop and continue to execute the next loop
Enhanced for cycle foreach
Scanner user interaction System.in
Thank you for your reading, the above is the content of "what is the basic grammar of Java". After the study of this article, I believe you have a deeper understanding of what the basic grammar of Java has, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.