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

How to use Object class and System class in Java language

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to use Object class and System class in Java language". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the Object class and System class in the Java language.

Object is the base class of all java classes, the top of the inheritance structure of the entire class, and the most abstract class. People use toString (), equals (), hashCode (), waite (), notify (), getClass () and other methods every day, and they may not realize that they are Object methods, nor do they look at the other methods of Object and think about why they should be put into Object.

Introduction to Java Object classes-superclasses of all classes

Object is a special class in the Java class library and the parent class of all classes. That is, J ava allows any type of object to be assigned to a variable of type Object. When a class is defined, if no inherited parent class is specified, the default parent class is the Object class. Therefore, the following two classes have the same meaning.

Public class MyClass {... }

Equivalent to

Public class MyClass extends Object {... }

1.1. Common methods

Because all Java classes are subclasses of the Object class, any Java object can call the methods of the Object class. Common methods:

Object clone () creates a new object that is the same as the class of the object

Boolean equals (Object) compares whether two objects are equal

Void finalize () when the garbage collector determines that there are no more references to the object, the object garbage collector calls this method

Class getClass () returns an instance class of an object at runtime

Int hashCode () returns the hash code value of the object

Void notify () activates a thread waiting on the object's monitor

Void notifyAll () activates all threads waiting on the object's monitor

String toString () returns a string representation of the object

Void wait () causes the current thread to wait before another thread calls the notify () method or the notifyAll () method of this object

2. Detailed explanation of Java System class

The System class is located in the java.lang package and represents the running platform of the current Java program. Many system-level properties and control methods are placed inside the class. Because the constructor of the class is private, the object of the class cannot be created, that is, the class cannot be instantiated.

The System class provides class variables and class methods that allow you to call them directly through the System class.

The System class has three static member variables, PrintStream out, InputStream in, and PrintStream err.

2.1.The PrintStream out standard output stream

This stream is open and ready to receive output data. Typically, this stream corresponds to the display output or another output destination specified by the host environment or the user.

For example, a typical way to write a row of output data is:

System.out.println (data)

Among them, the println method belongs to the stream class PrintStream method, not the method in System.

2.2.The InputStream in standard input stream

This stream is open and ready to provide input data. Typically, this stream corresponds to keyboard input or another input source specified by the host environment or user.

2.3.The error output stream of PrintStream err standard

The syntax is similar to System.out in that you do not need to provide parameters to output error messages. It can also be used to output other information specified by the user, including the value of the variable.

At this point, I believe you have a deeper understanding of "how to use Object classes and System classes in the Java language". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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: 227

*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

Internet Technology

Wechat

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

12
Report