Practical Class (1) Introduction

1. Enumeration type

Definition: An enumeration refers to a type consisting of a fixed set of constants.

example:

No penguins for Özil Insert picture here Taxi express description

insert image description here
insert image description here
Summary of the advantages of enumeration:
1. Enumeration can make the code easier to maintain.
2. Enumeration is easier to input during programming. Using enumeration assignment, you only need to enter the enumeration name to call out the corresponding value.

二、JAVA API

Commonly used Java APIs
java.lang
Enum, wrapper class, Math, String, StringBuffer, System...
java.util
java.io
java.sql
1. Wrapper class:
Definition: The wrapper class converts basic type data into objects.
Each primitive type has a corresponding wrapper class in the java.lang package.

basic data type Packaging
byte Byte
boolean Boolean
short Short
char Character
int Integer
long Long
float Float
double Double

Packaging use:

  1. The wrapper class exists as a class corresponding to the basic data type, which is convenient for object manipulation.
  2. Wrapper classes contain the relevant properties for each primitive data type.

2. Conversion of wrapper class and basic class data type
2.1 Conversion of basic data type to wrapper class
In Java, there are usually two ways to create a wrapper class object for basic data type data:

2.1.1 Use the constructor of the wrapper class. .
The packaging class construction method has two forms
: public Type (type value) and
public Type (String value).
Among them, Type represents the packaging class, and the parameter type is the basic data type.
To create a wrapper class object of type Integer, the code can be written like this.
Integer intValue=new Integer(21); or
Integer intValue=new Integer("21");

2.1.2 Use the valueOf() method of the wrapper class
to create a wrapper class object of type Integer:
Integer intValue=Integer .valueOf("21");

2.2 Automatic conversion of basic types and packaging types

Boxing: conversion of a primitive type to an object of a wrapper class
Unboxing: conversion of a wrapper class object to a value of a primitive type

Basic type conversion -----> wrapper class
int and Integer conversion
Insert image description here
boolean and Boolean conversion
insert image description here
string ------> basic type
insert image description here
basic type ------> string
insert image description here

3. Math class

The java.lang.Math class provides common mathematical operation methods and two static constants E (the base of natural logarithm) and PI (pi)
Math.floor ------- take the value down
Math.PI -- -----Circle ratio
Math.abs(-3.5); //return 3.5 (take the absolute value)
Math.max(2.5, 90.5);//return 90.5
(to be continued)

Guess you like

Origin blog.csdn.net/weixin_47139540/article/details/106814066