[go: up one dir, main page]

0% found this document useful (0 votes)
2 views16 pages

Classes and Libraries

The document provides an overview of built-in classes in programming, focusing on the String, Math, Wrapper, and System classes. It details the functionalities and methods associated with each class, such as string manipulation methods, mathematical operations, and the use of wrapper classes for primitive data types. Additionally, it describes the System class's role in handling input and output streams and accessing system properties.

Uploaded by

Bonny runameso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

Classes and Libraries

The document provides an overview of built-in classes in programming, focusing on the String, Math, Wrapper, and System classes. It details the functionalities and methods associated with each class, such as string manipulation methods, mathematical operations, and the use of wrapper classes for primitive data types. Additionally, it describes the System class's role in handling input and output streams and accessing system properties.

Uploaded by

Bonny runameso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Classes and libraries

Built in classes
• The classes that are already provided in a programming language for
use are inbuilt classes. These classes provide some functions or objects
that can be used by the programmer for easier code.
• A built-in class is a class whose instances have restricted capabilities
or special representations.
Calling or Using built in classes
• The inbuilt classes must be included in the program. Whenever some
functions are used, they must have a declaration before use. The same
is the case with classes.
Built in Classes
What is contained in built in classes?
• The classes contain the definitions of the special functions that are
provided for the programmers use. Those functions can be used to
make the programming easy and to reuse the already existing code.
The Built in classes we will focus on:
• string classes
• math class
• wrapper classes
• system class
String Class
• The String class represents character strings. All string literals in Java programs, such as “msu", are
implemented as instances of this class.

• Strings are constant; their values cannot be changed after they are created. String buffers support mutable
strings. Because String objects are immutable they can be shared.

• The String class includes methods for examining individual characters of the sequence, for comparing strings,
for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to
uppercase or to lowercase. Case mapping is based on the Unicode Standard version specified by the Character
class.
• String is a static method as well as instance of a method.
String constructor summary
• String ( ) – this initializes a newly created String object so that it
represents an empty character sequence.
String method summary
• CharAt (int index)- returns the character at the specified index
• Concat (String str)- joins the specified string to the end of this string
• indexOf (int ch) returns the index within this string of the first
occurance of the specified character, starting the search at the
specified index.
• Length()- retuns length of the string
• toUpper ()- converts all the characters to uppercase
• There are more method that can be used to manipulate stringss
Summary of string methods
Using the string class
Math Class
• The Math class contains methods for performing basic numeric
operation such as the elementary exponential, logarithm, square root,
and trigonometric functions.
• The class do not need to be imported.
Some Fields for java.lang.Math class:
• static double E − This is the double value that is closer than any other
to e, the base of the natural logarithms.
• static double PI − This is the double value that is closer than any other
to pi, the ratio of the circumference of a circle to its diameter
Using the math class
Wrapper Class
• A Wrapper class in Java is the type of class that provides a mechanism
to use the primitive data types as objects and vice-versa.
• When a wrapper class is created, there is a creation of a new field in
which we store the primitive data types.
• We need wrapper class when:
• 1. when an object is needed to support synchronization in multithreading
• 2.Data structures in the collection framework such as ArrayList, store
only objects (reference types) and not primitive types.
• 3. the java.util package handles only objects and hence wrapper class
helps.
Primitive data type and Wrapper class
Primitive Data Type Wrapper Class
byte Byte
short Short
int Integer
long Long
float Float
double Double
boolean Boolean
char Character
Using Wrapper class
System class
• The System class provides facilities such as standard input, standard
output, and error output streams; access to externally defined
properties and environment variables; a means of loading files and
libraries; and a utility method for quickly copying a portion of an
array. It extends class Object.
Fields of system class

• Public static final Input Stream in: The “standard” input stream. This stream is already open and
ready to supply input data. Typically this stream corresponds to keyboard input or another input
source specified by the host environment or user.

• Public static final Print Stream out: The “standard” output stream. This stream is already open
and ready to accept output data. Typically this stream corresponds to display output or another
output destination specified by the host environment or user.

• Public static final Print Stream err: This output stream is used to display error messages or other
information that should come to the immediate attention of a user even if the principal output stream,
the value of the variable out, has been redirected to a file or other destination that is typically not
continuously monitored.
Using the system class

You might also like