Java. lang

Source: Internet
Author: User
Tags processing text

Java. lang
1. Common basic jar packages

As a java language user, we can feel the advantages of the java language (platform independence, object-oriented, multithreading, efficient and scalable ), in addition, it has many implemented class libraries that can be directly used by us. These class libraries are provided in the form of jar packages and can also be used as Java APIs, it implements a variety of common operations for programmers and brings a lot of convenience for programmers to compile java program code.

As a beginner, I think it is necessary to master and apply the java basic library. Therefore, I summarized some basic knowledge points when I was a beginner in java. The main APIs provided by the Java2 standard are shown in the following table.

Package name

Overview

Java. applet

Provides the classes required to create an applet.

Java. awt

Contains all the classes used to create user interfaces and draw images.

Java. io

Provides input and output-related classes.

Java. beans

Contains classes related to developing javaBeans

Java. lang

Provides basic classes for java programming.

Java.net

Provides classes related to network operations.

Java. nio

Class that provides a buffer for Input and Output

Java. text

Provides classes and interfaces for processing text, dates, numbers, and messages.

Java. util

Provides various tools such as processing date, time, and random number generation.

Javax.net

Provides network application classes and network application extensions.

Java. swing

Provides a set of java-only component classes with the same features as AWT.

2. java. lang Package

Java. lang package is the basis of all other class libraries in the java language system. It has been embedded in the java Virtual Machine and created as an object. Therefore, we are using java. you can directly use java. all classes in the lang Package and directly reference the open, variable, and Operation Method in a class.

Class Name

Function

Boolean

It encapsulates values of the boolean Type and some methods to operate on this type.

Byte

Encapsulates the value of the byte type and some methods to operate on this type.

Character

It encapsulates values of the char type and some methods for this type.

Double

It encapsulates values of the double type and some methods for this type.

Float

It encapsulates the float type value and some methods to operate on this type.

Integer

It encapsulates the int type value and some methods to operate on this type.

Long

Encapsulates the value of the long type and some methods to operate on this type.

Short

It encapsulates values of the short Type and some methods to operate on this type.

String

Encapsulates the operation methods related to the string type.

Void

Indicates the declaration of the void keyword in Java. This class cannot be used as an instance.

Class

Describes the status of classes and interfaces in a running java application.

ClassLoader

Objects used to load classes

Enum

Used to define enumeration types

Math

Used for basic mathematical operations

Number

Abstract class is the parent class of the basic data type class

Object

Is the root class of all java classes

Package

Encapsulates java package implementation and standard version information

Runtime

The Runtime Class Object connects java applications to their Runtime environments.

StrictMath

Used to implement basic mathematical operations

StringBuffer

Variable string operations

StringBuilder

Create variable string objects

System

Encapsulated some methods related to the Java Virtual Machine System

Thread

Create and control threads

ThreadGroup

Create and control thread groups

Throwable

Defines the parent class of all errors or exceptions in java

Process

Define a process object and start the process object using the exec method in the Runtime class.

The main interfaces defined in the java. lang Package and their corresponding functions are described as follows:

Interface

Function

Appendable

Used to append a string

Cloneable

Used to copy class objects

Runnable

Used to implement the thread function of class objects

Comparable

Used to sort class objects

3. Object Class description

The Object class is the parent class of all classes in the java system. That is, the class objects created in the java program are derived from the object class, all implement or inherit the methods in the object class.

The Jar package contains constants, variables, and methods. When a class object is created, constants and variables in the object can be directly referenced, when calling a method in an object, you must specify the input parameters of the method and provide the data and return values that conform to the parameter type for the method. You must also know whether the method will generate an exception during calling, if an exception may occur in a method, use the try-catch statement structure to capture and handle the exception, or use the java keyword throws to throw the exception.

4. Basic Java Data Types

The basic data types specified in Java include boolean, byte, character, double, float, integer, long, and short. You can declare constants and variables of the basic data type. However, java is a pure object-oriented programming language. lang defines the corresponding classes for these basic data types (encapsulates the variable types of basic data types, constants related to variables, and related operation methods ), in this way, these basic types of values or variables can be processed as objects.

The java. lang package also defines the Number abstract data type, specifically for operations on pure numeric objects. Operations on pure numeric objects in basic data types include integer and floating point types. It can be seen that the Number class is a direct parent class of the integer and floating point types. In the number class, it defines operation methods and abstract methods suitable for pure numbers of different data types.

(Note: The character class encapsulates the values of the char type and related operation methods. All the characters are encoded in Unicode standard)

5. String & StringBuffer

Java. lang also provides a String class to process strings. The String class is used to process "immutable" strings. The StringBuffer class is also used to process "mutable" strings. Stirng and StringBuffer classes are declared as final types, so they cannot be used as parent classes and are inherited.

(1) String class

The String class is used to create a String object. Its value is treated as a constant after it is created. The String class also contains String-type values and related operation methods. All operation methods in the String class are for the created String object, and the String object is created through the String class constructor.

(2) StringBuffer class

The StringBuffer class is a string buffer class used to create variable-length string objects. The variable-length class indicates that the length and content of a string can be changed by calling some methods, for example, a New String object is formed by appending a new string sequence to the original string, or inserting a new character sequence to a position in the original string.

The StringBuffer class creates string objects based on the implementation of the new buffer zone. It stores string character sequences in the buffer zone. Because the buffer zone has a certain capacity, when the string length changes, if the buffer capacity is exceeded, that is, when the buffer overflow occurs, the java running system automatically expands the buffer capacity created by the StringBuffer object, ensuring the security of string operations.

6. Math class

Math class encapsulates various data types of arithmetic operations, including exponent, logarithm, square root, trigonometric function, and so on. All constants and methods in the math class are defined as static, so all members can be directly referenced.

7. Runtime class

The Runtime class encapsulates some methods related to the java Virtual Machine. When the java Virtual Machine starts every java application, it creates a runtime object, which ensures the connection between the java application and its Runtime environment, after a runtime object is created, you can directly call the methods defined in the runtime class in a java application (for example, operations such as obtaining the running information of the current program, exiting the program, and disabling the java Virtual Machine ).

8. System class

The System class encapsulates some constants related to the Computer Input/Output System and the operation methods related to the Java Virtual Machine. After the java Virtual Machine is started, the system object is created. The system object cannot be created in java applications. All constants and methods in the System class are defined as static. Therefore, you can directly call the constants and methods defined in the system class in java applications.

9. Summary

There are many available class libraries provided by the java language, which bring a lot of convenience to programmers. You need to view the help documentation and instructions for specific use and determine the function. The focus is on the input parameters, return values, and exceptions of an operation method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.