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

What are the java data types and operators

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the knowledge of "what are the java data types and operators?". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Catalogue

Data type

Boolean type

String type String

Concatenation character'+'

Escape character

Operator

add , subtract , multiply and divide

Modular operation

Incremental assignment operator

Self-increasing operator and self-built operator

Assignment operator

Judgment operator

Logical discriminator

Bitwise operator

Shift operation

Conditional operator

Operator precedence

Data type

Boolean type

There are also two bool types in Java: true (true) and false (false)

Unlike C language, in C language, we can put a number in the bool type. 0 is false and non-0 is true.

Int fun () {return 1;} bool a = fun ()

In Java, the bool type has no specific value, and if you follow the C language above, you will make an error. True is true,false and false, and there are no other values.

System.out.println (true); System.out.println (false)

The output is as follows:

True

False

The size of the bool type is not specified in the JVM specification, but in some books, the bool type is 1 byte and in some books it is 1 bit.

String type String

In Java, there is no pointer, but there is a separate string type String

String is also called reference type

String str = "abcde"; System.out.println (str); concatenation character'+'

System.out.println ("hello" + "world")

Execution result

Helloworld

+ you can concatenate two strings

But the execution result of the following code is different.

System.out.println ("hello" + 10 + 20); System.out.println (10 + 20 + "hello"); System.out.println ("hello" + (10 + 20)); System.out.println (10 + "" + 20 + "hello")

The implementation results are as follows:

Hello1020//10 and 20 are concatenated into strings

The sum of 30hello//10 and 20 is changed to 30.

Hello30// brackets are enclosed and added to become a string

1020hello

/ / becomes a string because there is an empty string between 10 and 20 so that 10 and 20 are not added

Escape character

Escape character''is the same as C language.

Will match the next word for another character.

For example, we are familiar with the\ nline change.

If you want to print\ n, you can use double escape

System.out,println ("\\ n")

The output is as follows:

\ n

Operator

add , subtract , multiply and divide

+, -, *, /, are our most common operators, these operators are what you think, but the only thing to pay attention to is the''sign, the divisor should not be 0, and if it comes to decimal calculation, it is recommended to use double, because in the computer language 1 and 2 are shaping, the result will only be shaping.

Modular operation

The function of'% 'modular operation is to find the remainder

Int a = 5% 2

In the above code, the value of an is 1, because 5 Universe 2 = = 2 over 1, so an equals 1.

Incremental assignment operator

Incremental assignment operator, + =,-=, * =, / =, etc.

Like the mixed operator in C language

Axiomatic 3 a = axi3

And in Java, incremental assignments come with forced type conversions.

Short a = 2nint s = (int) a forced type conversion is required / int b = 0ntint s = (self-built operator) is not needed, because the self-increment operator and self-built operator are automatically converted

+ + and -, which are equivalent to averse 1 and aMuth1.

The self-increment operator is divided into prefix and postposition.

For example:

Int a = 0% int b = a match 1% int c / equivalent to int b = a * a = a * 1 * int c =-- a *

The'='is the assignment operator, which assigns the value on the right to the left

Judgment operator

The judgment operators are =,! =, =.

It is an bool expression and the result is of type bool

Int aplink 0; boolean c = false;c = acronym true;c 0 is true, c = true;c = aplink 0 is false, c = false;c = a > 0, a > 0 is true, c = true;c = a > a >

Shift the left operator, shift its binary bit to the left by x units, and fill in the deficiency by 0

0101 0101 > 2 (move two places to the right)

The result is 111101 01

Move the unsigned right, move its binary bit to the right by X units, whether it is negative or positive, or make up for all the deficiencies.

1101 0101 > 2 (unsigned move two digits to the right)

The result is 001101 01

PS: no unsigned left shift

Conditional operator

The conditional operator is the ternary operator.

Expression 1? Expression 2: expression 3

Expression 1 ~ 2 ~ 3 must be a bool expression

Returns expression 2 if expression 1 is true, and expression 3 if expression 1 is false.

Operator precedence

Operators have precedence, but most of the time you don't have to delve into it. You can use parentheses to evaluate internal expressions first, and use parentheses flexibly to prevent problems caused by operator precedence.

That's all for "what are the java data types and operators?" Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Development

Wechat

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

12
Report