Use Classes From the Java Class Library

Use classes from the Java class library:

The Java Class Library provides you with a foundation of thousands of Classes available. It is almost impossible to write Java programs who don’t use at least a couple of these class library. That is true even for the simple Hello World program that can be accessed via System.out on a Object of the PrintStream class library With its method println shows the Hello World program texts on the screen. Using classes and their objects you have to be in Java from the start.

Classes of the class library:

A class is a type of data. Classes usually serve to process data of a certain type or tasks for to do a certain task. Examples of classes are e.g. String, LocalDateTime or Random.



Objects of the class library:

Classes only provide the infrastructure, the construction plan. As soon as specific data is to be saved, new objects are created by the corresponding class. Other Terms for “objects” are “instances” or “instances”. For example, the String class is used to manage character strings. “abc”, “Hello World!” and “123” are three objects of this class. Similarly, you need a to save a specific date LocalDateTime object. Before you can determine the first random number, you have to create a random object. So the difference between class and object is that the class is an abstract description for now, so code if you have so want. But only when objects are created from them do concrete things lie Data that can be edited. The following applies: One class can be the basis for many objects. An object must always be from come from a very specific class.

How objects are created depends on the respective class. At the majority of the classes can be created with new classname () Object. For some classes there are also other mechanisms, e.g. getInstance. Two important special cases are strings and arrays, which you can simply create with string x = “abc” or int [] x = {1, 2, 3} can. The objects are mostly accessed using variables. so x is a variable that refers to an object of the String class.

Methods of the class library:

Classes provide methods – for some Only a few classes, many others. Usually, methods serve to edit objects. For example, the method delivers length of the string class is the length of a character string. In continuation in the above example, x.length () results in 3. The string “abc” consists of three characters. Many methods can only be used if there is an appropriate one Object there. They are in the form objvar.method-name () called. The round brackets are mandatory regardless of whether the method expects parameters or not. Some classes provide static methods. Such Methods can be used without an object. For example the Math class knows the sqrt method for calculating the square root. This method is called in the form Math.sqrt (2). It is not necessary (and in this case not even possible), a Create object of the Math class.


Attributes / class variables / fields:

In addition to the methods, Classes also define so-called attributes. About attributes can Properties of objects can be read or saved. Access to attributes is the same as for methods.


Related Article:

java Internal bye code, JVM, and library

 

 

Recommended For You

About the Author: Fawad

My name is Shahzada Fawad and I am a Programmer. Currently, I am running my own YouTube channel "Expertstech", and managing this Website. My Hobbies are * Watching Movies * Music * Photography * Travelling * gaming and so on...

Leave a Reply

%d bloggers like this: