java.lang package

This package is considered the main one. It contains classes that correspond to the basic data types (let’s say the Number class is for numeric data). Let’s take a quick look at some of the classes in this package.

Boolean class. This class corresponds to a boolean (boolean) type. It’s not a very big class. It has two constructors (either a boolean value or a string in the parameters) and contains several methods. Here are some of them:

  • equals will return true if the caller and parameter are equivalent;
  • toString – converts a boolean value to a string;
  • valueOf – Converts a string to a boolean value.

Byte class. A subclass of the Number class. Responsible for the byte data type. It has two constants MIN_VALUE and MAX_VALUE, and two constructors that specify either a numeric value or a string value.

Here are some methods of this class:

  • – byteValue – returns a value with type byte;
  • – doubleValue – returns a value with type double;
  • – equals will return true if the caller and parameter are equivalent;
  • – floatvalue – returns a value with float type;
  • – int Value – returns a value with type int;
  • – longValue – returns a value with type long;
  • – parseByte – there are two methods with the same name: the first one converts the string into a byte value, and the second one too, only using the number system specified by the second parameter;- shortValue – returns a value with type short;
  • – toString – turns the value into a string;
  • – valueOf – turns a string into a numeric data type (the first method – into a decimal number system, the second – similarly using the specified number system).

Character class. For data type char. Contains the constants MIN_VALUE and MAX_VALUE, one constructor, as well as many methods that allow you to find out what this character is (lower case – isLowerCase, upper case – isTitleCase, etc.), and get this character in lower case (toLowerCase), upper case (toUpperCase) etc.

Class Class. Using this class, you can find out the state of a class or interface: on the one hand, which class (to find out its name – getName) the class under study inherits (getSuperclass) or which interfaces it extends (get Interfaces), and on the other hand, which class members it has (getFields for fields, getMethods for methods). To find out if this is an interface (maybe it was not a class initially, but an interface), you need to use the islnter-face method. We will not consider this class in detail here.

Double class. Responsible for the double type. Similar to the Byte class, however, it cannot specify the number system (in the parseDouble and valueOf methods). There is an isNaN method that allows you to determine if the given value is a number (returns a boolean value).
There is also an islnf inite method that lets you know if a value is infinite.

Float class. Responsible for the float data type. Similar to the Double class.

Integer class. Responsible for the int data type. Similar to the Byte class.

Long class. Responsible for the long data type. Similar to the Byte class.

Math class. Needed to perform mathematical operations. Contains two constants: E (Euler’s constant) and PI (number i). Here are some methods (they are all static).

  • – abs – returns the absolute value of a number,
  • – acos – returns the arc cosine,
  • – as in – returns the arcsine,
  • – atan – returns the arc tangent.
  • – atan2 – returns the arc tangent, the numbers x / y (x, y – the first and second parameters respectively),
  • – cei 1 is the nearest larger integer,
  • – cos – returns the cosine.
  • – exp – returns the exponent raised to the given power,
  • – floor — nearest smaller integer,
  • – log – calculates the natural logarithm,
  • – check – chooses the maximum of two numbers,
  • – min – returns the minimum of two numbers,
  • – pow – raises the first number to the power of the second,
  • – random – gets a random number from 0 to 1 and returns it.- rint – rounds the number.
  • – round – rounds a number to a value in int or long type,
  • – sin – returns the sine,
  • – sqrt – calculates the square root,
  • – tan – returns the tangent.

Class Number. Is the superclass for numeric value classes.

Object class. Superclass for all other classes. Contains several methods that can be used by any objects (thread methods wait (), notify () , notifyAll (); finalize () method, toString () method, etc.).

Package class. This class allows you to collect information about a package.

 Short class. Responsible for the short data type. Similar to the Byte class.

String class. It exists to work with strings. Here are some methods:

  • – charAt – gets a character from the string with the given number;
  • – concat – adds two strings;
  • – length – string length;
  • – replace – replaces in the string the character passed in the first parameter with the character passed in the second parameter;
  • – toCharArray – converts a string into an array of characters;
  • – toLowerCase — string conversion to lower case;
  • – toUpperCase – convert string to upper case;
  • – substring – copies a part of the string with the given character numbers;
  • – valueOf – converting data to a string.

The StringBuffered class. A class similar to String. Here the strings can be of non-fixed length. There are some interesting methods:

  • – append – converts data to StringBuffered type;
  • – delete – deletes part of the string passed by coordinates;
  • – deleteCharAt – deletes the character whose index is specified in the parameter from the string;
  • – insert – inserts data into a string at the specified position;
  • – replace – replaces the section of the string that is found by coordinates with the string specified in the third parameter;
  • – reverse – reverses the order of characters in a string.

System class. It contains the properties of the Java executive. The most well-known fields are the standard output (out), input (in), and error output (err) fields. Here are some methods:

  • – currentTimeMillis – current time in milliseconds since 1/1/1970;
  • – exit – stops the execution of the program (if the parameters are 0, then
    the program ended normally);
  • – setErr – sets the parameter to the err stream;
  • – set In – sets the parameter to the in-stream;
  • – setOut – sets the parameter to the out stream.

Thread class. Multiple constructors, three priority constants
(MIN_VALUE, MAX_VALUE and NORM_VALUE). Basic methods (methods discussed in Chapter 5 are excluded from the list):

  • – destroy — termination of the stream;
  • – getName – returns the name of the stream;
  • – interrupt — thread interruption;
  • – islnterrupted – is the thread interrupted? The response is returned by this method;
  • – setName – sets the name of the stream.

ThreadGroup class. This class allows you to combine threads into a group. Here are some of his methods:

  • – destroy – destroys a group of threads;
  • – enumerate – creates a group of threads;
  • – getMaxPriority – returns the maximum priority;
  • – interrupt – calls the interrupt method for all threads belonging to this group;
  • – setMaxPriority – sets the maximum priority.

Here is an example of using this package with some of its classes (Listing 6.5).

Rate article
ASJAVA.COM
Add a comment

Your email address will not be published. Required fields are marked *

*

code