Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Learn big data-Java basic Grammar from 0 (2)

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

We learn big data technology from scratch, from the foundation of java, to Linux technology, then to the Hadoop, Spark, Storm technology of big data technology, and finally to the construction of big data enterprise platform, step by step, from point to face! I hope Technology Bull can come to guide the study.

In the previous section, we learned about the history and basic operation of Java. In this section, we begin to learn the basic syntax of the Java language, which will focus on the following knowledge points:

Keyword

Identifier

Annotation

Constants and variables

Operator

Statement

Function

Array

PS: this section starts with the first four knowledge points.

1. Keywords

An overview of keywords

Words given a specific meaning by the Java language

Characteristics of keywords

The letters that make up the keywords are all lowercase

Keyword considerations

Goto and const exist as reserved words and are not currently used

Advanced notepad like Notepad++ has special color markings for keywords, which is very intuitive.

Class,public,static,void are all keywords, [more keywords] https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

Https://baike.baidu.com/item/java%E5%85%B3%E9%94%AE%E5%AD%97/5808816?fr=aladdin

2. Identifier

(1) Overview of identifiers:

It is the sequence of characters used to name classes, interfaces, methods, variables, etc.

(2) main composition rules:

English upper and lowercase letters

Numeric character

$and _

(3) Note:

Cannot start with a number

Cannot use keywords in Java

Java language is strictly case-sensitive

(4) Common naming rules (it is recommended to follow the principle of knowing the meaning by name):

To define a student class

Class student {}

The main naming rules are as follows:

a. Package:

It is actually a folder, which is used to distinguish the same class name, all lowercase.

Single stage: apple

Multi-level: abc.apple

b. Class or interface:

One word: the first letter of a word must be capitalized

For example: Student, Dog

Multiple words: the first letter of each word must be capitalized

For example: HelloWorld,StudentName

c. Method or variable:

One word: the first letter of the word is lowercase

For example: main,age

Multiple words: starting with the second word, the first letter of each word is capitalized

Example: studentAge,showAllNames ()

d. Constant:

One word: all uppercase

For example: PI

Multiple words: each letter is capitalized, separated by _

For example: PERSON_NAME

3. Notes

In Java development, we need to write comments for the code.

(1) Overview of notes:

Text used to explain the program

(2) the format of annotation classification in Java:

a. Single-line comment

Format: / / Annotation text

b. Multiline comments:

Format: / * Annotation text * /

c. Documentation Notes:

Format: / * Annotation text * /

(3) write an annotated version of HelloWorld case

[note] annotations are good programming habits that a programmer must have. It is recommended that beginners write programs to develop the following habits:

Write comments first and then write code, sort out your ideas through comments, and then reflect them with code.

Because the code is just a form of thought.

The specification is as follows: ① requirements ② analysis ③ implementation ④ code implementation

(4) the function of notes

A: explain the program and improve the readability of the code

B: it can help us debug the program. Later, we will explain a more high-end debugging tool.

4. Constant

(1) Overview of constants

A constant is a quantity whose value cannot be changed while the program is running.

(2) Classification of constants in Java

a. Literal constant

b. Custom constant (further explained later)

String constant: content enclosed in double quotation marks

Eg: "Hello", "world", "HelloWorld"

Integer constants: all integers

Eg:12,23

Decimal constants: all decimals

Eg:1234.5678

Character constant: content enclosed in single quotation marks

Eg:'a','A','0'

Boolean constant: special, only true and false

Empty constant: null, (more on this later)

(3) there are four representations for integer constants in Java:

a. The binary system consists of 0Pol 1. Start with 0b

b. The octal system is made up of 0 and 1pm. 7. Start with 0

c. The decimal system is made up of 01pm 2, .9. Integer defaults to decimal

d. The hexadecimal system consists of 0prime1pr 2, .9, a recorder brecorder c recorder e recorder f (uppercase and lowercase). Start with 0x

(4) Let's create a case ConstantDemo:

The execution result of the program is as follows:

5. Binary conversion

Summary of binary system: carry system, which is a carry method prescribed by people. for any kind of system-X system, it means that the operation on a certain position is carried by every X. Binary is one for every binary, octal is one for every octal, decimal is one for decimal, and hexadecimal is one for hexadecimal.

(1) other binary to decimal

Coefficient: the value on each bit

Cardinality: the cardinality of base X is X.

Weight: for the data on each bit, start from the right and number from 0, and the corresponding number is the weight of the data.

Result: the sum of coefficient * cardinality ^ power

(2) Decimal to other base systems

Take the remainder except the cardinality until the quotient is 0 and the remainder is reversed.

(3) Fast conversion method of binary conversion

a. Conversion between decimal and binary

128 64 32 16 8 4 2 1 yards

b. Conversion from binary to octal and hexadecimal

(4) signed data representation

In a computer, there are three representations of signed numbers: original code, inverse code and complement code.

Why explain this knowledge point? Because when the computer is in operation, all data operations are calculated by complement.

Original code:

It is the binary set point representation, that is, the highest bit is the symbol bit, "0 is positive," 1 is negative, and the remaining bits represent the size of the value.

Inverse code:

The inverse code of a positive number is the same as its original code: the inverse code of a negative number is a bit-by-bit inversion of its original code, except for symbol bits.

Complement:

The complement of a positive number is the same as its original code, while the complement of a negative number is to add 1 at the end of its inverse code.

For example:

Use the original code, inverse code, and complement to represent + 7, and-7, respectively.

First of all, we get the binary of 7: 111.

Original code:

The highest bit (symbol bit) of the original code of a positive number is 0

The highest bit (symbol bit) of the original code of a negative number is 1

The others are numerical digits.

Symbol bit numerical bit

+ 7 0 0000111

-7 1 0000111 ‍

❈❈

Inverse code:

The inverse code of a positive number is the same as the original code.

The inverse code of a negative number is the same as the symbol bit of the original code, and the numerical bit is reversed, that is, 1 to 0, 0 to 1.

Symbol bit numerical bit

+ 7 0 0000111

-7 1 1111000 ‍

❈❈

Complement:

The complement of a positive number is the same as the original code.

The complement of a negative number is added to the inverse code by 1.

Symbol bit numerical bit

+ 7 0 0000111

-7 1 1111001 ‍

6. Variables

(1) Overview: the amount of value that can change within a certain range during the execution of a program, a container used to store variable data

(2) the characteristics of variables:

a. It has to be a size.

b. Store variable data in a certain format

c. There must be a name.

(3) the composition rules of variables:

a. It must be qualified with a data type

b. In the operation, when it is impossible to take this space to operate, what we really use is the value in this space, so we have to give the space a name (that is, variable name).

c. Even if there is a data type and a variable name, if there is no value, this space is a garbage space, which does not make any sense, so we have named the variable and need to further initialize the value.

(4) the definition format of variables:

a. Data type variable name = initialization value

b. Data type variable name

Variable name = initialization value

7. Data type

(1) Java is a strongly typed language, which provides corresponding data types for each kind of data, and allocates different sizes of memory space in memory.

(2) Classification:

A: basic data types: 4 categories and 8 kinds

B: reference data types: classes, interfaces, arrays.

(3) basic data types

A, number of bytes occupied by integers

Byte 1

Short 2

Int 4

Long 8

B, floating point type

Float 4

Double 8

C, character type

Char 2

D, Boolean type

Boolean 1

Note:

Integer defaults to int type

Floating point number defaults to double

Add L or l to long integers

F or f should be added to single-precision floating-point numbers.

The default value of Boolean is false

Case study:

The execution result of the program is as follows:

Considerations when using variables:

Scope:

The level of curly braces in which the variable is defined, and the scope of which braces is the scope of the variable. Two variables with the same name cannot be defined in the same scope.

Initialization value

Variables cannot be used directly without initialization values

It is recommended that you define only one variable on one line (it will be more readable)

Case (1)

Case of program with the same name:

Execution result:

Cancel the same name, and the correct execution results are as follows:

Case (2)

Variable has no initialization value

Execution result

Variable initialization value:

8. Data type conversion

(1) boolean types do not participate in type conversion

(2) default conversion

A, from small to big

B. Byte,short,char----int-long-float-double

C and byte,short,char are not converted to each other, but directly converted to int type to participate in the operation.

(3) forced conversion

A, from big to small

B. there may be a loss of accuracy, which is generally not recommended.

C, format:

Target data type variable name = (target data type) (converted data)

(4) next, there are two thinking questions for you to think about:

A. is there any difference between the following two ways?

Float F1 = 12.345

Float f2 = (float) 12.345

B. is there anything wrong with the following procedure, and if so, where is it?

Byte b1 = 3

Byte b2 = 4

Byte b3 = b1 + b2

Byte b4 = 3 + 4

C. What is the result of the following operation?

Byte b = (byte) 130

D, characters participate in operation

Is to find the value in ASCII (http://www.asciima.com/ ASCII code viewer)

'a' 97

'A' 65

'0' 48

System.out.println ('a')

System.out.println ('A')

System.out.println ('0')

E: string participating in operation

This is actually a string concatenation.

Tap the code offline to see what the printed result below looks like.

System.out.println ("hello" + 'axioms 1)

System.out.println ('astatine 1 + "hello")

System.out.println ("5x 5 =" + 5x 5)

System.out.println (5'5 "= 5'5")

Here is the corresponding ASCII table

My ability is limited, if there is any deficiency, I hope to correct it.

Thank you for your continued support.

I hope to share it with more people.

Let's learn big data's skills together.

Welcome to exchange

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report