To Handle Ad Blocker

Java Library

Java ships with hundreds of pre-built classes. You don't have to write it yourself if you know how to find what you need in the java library, known as the Java API. The java API is full of code you don't have to type. All you need to do is learn to use it. Every class in the java library belongs to a package. The package has a name , like javax.swing (a package that holds some of the Swing GUI classes). ArrayList is in the package called java.util. To use any class from the API you have use its full name or you have to import that class. This tutorial would cover package Java.Lang and Java.util.

Java.Lang Package

Java.lang Package is automatically imported into all programs. It contains classes and interfaces that are fundamental to virtually all of Java programming. It is most widely used package of Java. java.lang includes the following classes:
NameDescription
BooleanBoolean class is for storing Boolean values.
LongThe Long class wraps a value of the primitive type long in an object.
StackTraceElementAn element in a stack trace, as returned by Throwable.getStackTrace().
ByteThe Byte class wraps a value of primitive type byte in an object.
MathThe class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
StrictMathThe class StrictMath contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
CharacterThe Character class wraps a value of the primitive type char in an object.
NumberThe abstract class Number is the super class of classes BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, and Short.
StringString class is used to create string object.Java's String is basically an object that represents a sequence of character values. An array of characters works same as java string.
ClassClass is a template for creating objects.It tells the virtual machine how to make an object of that particular type.
ObjectAny entity that has state and behavior is known as Object.It can be physical and logical. It is an instance of class.
StringBufferA string buffer implements a mutable sequence of characters.
ClassLoaderA class loader is an object that is responsible for loading classes.
PackagePackage objects contain version information about the implementation and specification of a Java package.
SystemOne use of the System class that you might find particularly interesting is to use the currentTimeMillis( ) method to time how long various parts of your program take to execute. The currentTimeMillis( ) method returns the current time in terms of milliseconds since midnight, January 1, 1970. To time a section of your program, store this value just before beginning the section in question. Immediately upon completion, call currentTimeMillis( ) again. The elapsed time will be the ending time minus the starting time.
CompilerThe Compiler class is provided to support Java-to-native-code compilers and related services.
ProcessThe abstract Process class encapsulates a process—that is, an executing program. It is used primarily as a superclass for the type of objects created by exec( ) in the Runtime class
ThreadThread class allows you to run more than two thread at the same time. Thread are light weighted subprocess a small unit of processing. Thread shares same address space and cost of communication between the thread is low. At least one process is required for each thread.
DoubleThe Double class wraps a value of the primitive type double in an object.
RuntimeThe Runtime class encapsulates the run-time environment. You cannot instantiate a Runtime object. However, you can get a reference to the current Runtime object by calling the static method Runtime.getRuntime( ). Once you obtain a reference to the current Runtime object, you can call several methods that control the state and behavior of the Java Virtual Machine. Applets and other untrusted code typically cannot call any of the Runtime methods without raising a SecurityException. The two of the most common uses of the Runtime class are: memory management and executing additional processes.
ThreadGroupA thread group represents a set of threads.
FloatThe Float class wraps a value of primitive type float in an object.
RuntimePermissionThis class is for runtime permissions.
ThreadLocalThis class provides thread-local variables.
Security ManagerThe security manager is a class that allows applications to implement a security policy.
IntegerThe Integer class wraps a value of the primitive type int in an object.
ShortThe Short class wraps a value of primitive type short in an object.
VoidThe Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void.

In addition, there are two classes defined by Character: Character.Subset and Character.UnicodeBlock. These were added by Java2. java.lang Package also defines the following interfaces:
Cloneable
Comparable
Runnable
CharSequence

java.util Package

It contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, miscellaneous utility classes, tokenize strings, compute random numbers, and observe events. It includes the following classes:
NameDescription
DateThe Date class encapsulates the current date and time.The java. util , java.sql and java.text packages contains classes for representing date and time.
DateFormatJava.text.Format is the parent class of DateFormat class and SimpleDateFormat class is the sub class of DateFormat class. In java, converting date into string is called formatting and vise versa parsing. The java.text.DateFormat provides various methods to format and parse date and time in java in language independent manner.
NumberFormatNumberFormat is abstract, so you'll typically use some version of either getInstance() or getCurrencyInstance() to create a NumberFormat object. Not surprisingly, you use this class to format numbers or currency values:
CalendarThis class provides a huge variety of methods that help you convert and manipulate dates and times. For instance, if you want to add a month to a given date, or find out what day of the week January 1, 3000 falls on, the methods in the Calendar class will save your bacon.The Calendar class is designed to make date manipulation easy! (Well, easier.) While the Calendar class has about a million fields and methods, once you get the hang of a few of them the rest tend to work in a similar fashion.
LocaleAn object of Locale class represents a geographical or cultural region. This object can be used to get the locale specific information such as country name, language, variant etc.
Timer And TimerTaskJava 2, version 1.3 added an interesting and useful feature to java.util: the ability to schedule a task for execution at some future time. The classes that support this are Timer and TimerTask. Using these classes you can create a thread that runs in the background, waiting for a specific time. When the time arrives, the task linked to that thread is executed. Timer and TimerTask work together. Timer is the class that you will use to schedule a task for execution. The task being scheduled must be an instance of TimerTask. Thus, to schedule a task, you will first create a TimerTask object and then schedule it for execution using an instance of Timer. TimerTask implements the Runnable interface; thus it can be used to create a thread of execution.