Home > Java > javaTutorial > How to call class library in Java?

How to call class library in Java?

little bottle
Release: 2019-04-28 11:39:31
Original
3890 people have browsed it

In this article, the editor will talk to you about how to use Java class libraries. This is something that friends who have just started learning Java must know. Let’s learn about it quickly. I hope it will be helpful to you.

Java has a powerful class library, so we can be comfortable when programming in Java. Java class libraries are those Java classes that come with the system. In the Java system, the classes defined by the system can be divided into different collections according to the different functions implemented. Each collection is called a package, and all packages collectively are called a class library. According to different functions, each package of the Java class library has several classes and interfaces with specific functions and interrelationships.

For example, the java.lang package contains system classes essential for running Java programs, including basic data types, basic mathematical methods, string processing, threads, exception handling, etc.; and java. The awt package includes a class library for building graphical user interfaces (GUIs) in the Java language.

There are three ways to use the system-defined classes in the class library:

1. One is to use the system class directly, such as when outputting strings to the system standard output device in the character interface. The method System.out.println() is the static attribute out method of the system class System;

2. Another way is to inherit the system class and create a subclass of the system class in the user program, for example, each The main class of each Java Applet is a subclass of the Applet class in the java.applet package;

3. The last way is to create system class objects, such as graphical interface programs that need to accept user input. , you can create an object of the system class TextField class to complete this task.

No matter which method is used, the prerequisite for using system classes is that this system class should be visible to the user program. For this purpose, the user program needs to use the import statement to introduce the system class it uses or the package where the system class is located. For example, for a program that uses a graphical user interface, you should use the statement:

import iava.awt.*;
import java.awt.event.*;
//引入java.awt包和java.awt.event包。
Copy after login

The programs in the class library package are all programs in bytecode form. Using the import statement to introduce a package into the program is equivalent to compiling In the process, the bytecodes of all system classes in the package are added to the user's Java program, so that the user's Java program can use these system classes and various functions in them.

Related tutorials: Java video tutorial

The above is the detailed content of How to call class library in Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template