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 basic data types of JAVA

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

What this article shares with you is about the basic data types of JAVA. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Let's take a look at it.

1: keyword (master)

(1) words with specific meanings given by Java language

(2) characteristics:

All lowercase.

(3) Note:

A:goto and const exist as reserved words.

B: advanced notepad like Notepad++ will have special color markings for keywords

2: identifier (master)

(1) A sequence of characters that give names to classes, interfaces, methods, variables, etc.

(2) composition rules:

A: uppercase and lowercase letters

B: number

CRV $and _

(3) Note:

A: you can't start with a number

B: cannot be a keyword in java

C: case sensitive

(4) Common naming rules (see name)

A: all lowercase packages

Single-level package: lowercase

For example: liuyi,com

Multi-level package: lowercase, and use. Separate

For example: cn.itcast,com.baidu

B: class or interface

One word: first letter capitalized

For example: Student,Demo

Multiple words: the first letter of each word is capitalized

For example: HelloWorld,StudentName

C: methods or variables

One word: lowercase initials

For example: name,main

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

Example: studentAge,showAllNames ()

D: constant

All uppercase

One word: uppercase

For example: PI

Multiple words: uppercase and separated by _

For example: STUDENT_MAX_AGE

3: comments (master)

(1) it is the text that explains the program.

(2) Classification:

A: single-line comments / /

B: multiline comments / * /

C: documentation notes (later) / *

(3) write an annotated version of the HelloWorld case.

Later, we are going to write a program process.

Demand:

Analysis:

Achieve:

The code reflects:

(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 (master)

(1) the amount by which the value does not change during the execution of the program

(2) Classification:

A: literal constant

B: custom constants (later)

(3) literal constant

A: string constant "hello"

B: integer constant 125.23

C: decimal constant 12.345

D: the character constant 'axiomagery'

E: Boolean constant true,false

F: empty constant null (later)

(4) there are four representations for integer constants in Java.

A: the binary system consists of 0Pol 1. It starts with 0b.

B: the octal is made up of 0pl. 7. Start with 0.

C: the decimal system consists of 0pm 1pm .9. Integers default to decimal.

D: the hexadecimal system is made up of 0meme 1pm .9pm a recorder, b recorder, c recorder, d recorde f (both uppercase and lowercase). It starts with 0x.

5: binary conversion (understanding)

(1) other binary to decimal

Coefficient: the value on each bit

Cardinality: the cardinality of the x base is x

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

Result: the sum of the coefficient * cardinality ^ power.

(2) Decimal to other base systems

Except the base takes the remainder until the quotient is 0, the remainder is reversed.

(3) Fast conversion method of binary conversion

A: conversion between decimal and binary

8421 yards.

B: binary to octal, hexadecimal conversion

6: variables (mastery)

(1) the amount by which the value of the program can be changed within a certain range during the execution of the program

(2) the definition format of variables:

A: data type variable name = initialization value

B: data type variable name

Variable name = initialization value

7: data type (master)

(1) Java is a strongly typed language that provides a corresponding data type for each type of data.

(2) Classification:

A: basic data types: 4 categories and 8 kinds

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

(3) basic data types

A: integer occupancy of bytes

Byte 1

Short 2

Int 4

Long 8

B: floating point number

Float 4

Double 8

C: character

Char 2

D: Boolean

Boolean 1

Note:

Integer defaults to int and floating point defaults to double.

Add L or l to long integers.

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

8: data type conversion (master)

(1) boolean type does not participate in conversion

(2) default conversion

A: from small to big

Int-long-float-double

The int type is directly converted to participate in the operation without converting each other.

(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) thinking questions and interview questions:

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

Float F1 = 12.345f

Float f2 = (float) 12.345

B: is there anything wrong with the following procedure? 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

'a' 97

'A' 65

'0' 48

System.out.println ('a')

System.out.println ('a' + 1)

E: string participating in operation

This is actually a string connection.

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

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

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

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

These are the basic data types of JAVA, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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