Monday, 9 March 2015

Object Oriented Concepts

What Is an Object?

Objects are key to understanding object-oriented technology. Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle.

Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming

 

What Is a Class?

In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is the blueprint from which individual objects are created.

Here look at following figure, here person is the class and Elaya ,Dara, Bharath are the objects.
Observe the point that Person doesn’t exist physically but Elaya ,Dara etc.. they exist physically. So they are objects

 

What Is a Package?

A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer. You might keep HTML pages in one folder, images in another, and scripts or applications in yet another. Because software written in the Java programming language can be composed of hundreds or thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages.

Advantage of Java Package

1) Java package is used to categorize the classes and interfaces so that they can be easily maintained.
2) Java package provides access protection.
3) Java package removes naming collision.
we have number of pre-define packages in java, here look at the following lang and io package description and list of classes ( list of classes information is gathered from oracle website the link is provided in the bottom of the page)
Package java.lang Description
Provides classes that are fundamental to the design of the Java programming language. The most important classes are Object, which is the root of the class hierarchy, and Class, instances of which represent classes at run time.
Frequently it is necessary to represent a value of primitive type as if it were an object. The wrapper classes Boolean, Character, Integer, Long, Float, and Double serve this purpose. An object of type Double, for example, contains a field whose type is double, representing that value in such a way that a reference to it can be stored in a variable of reference type. These classes also provide a number of methods for converting among primitive values, as well as supporting such standard methods as equals and hashCode. The Void class is a non-instantiable class that holds a reference to a Class object representing the type void.
The class Math provides commonly used mathematical functions such as sine, cosine, and square root. The classes String, StringBuffer, and StringBuilder similarly provide commonly used operations on character strings.
List of classes available in Lang  package

Class
Description
The Boolean class wraps a value of the primitive type boolean in an object.
The Byte class wraps a value of primitive type byte in an object.
The Character class wraps a value of the primitive type char in an object.
Instances of this class represent particular subsets of the Unicode character set.
A family of character subsets representing the character blocks in the Unicode specification.
Class<T>
Instances of the class Class represent classes and interfaces in a running Java application.
A class loader is an object that is responsible for loading classes.
Lazily associate a computed value with (potentially) every type.
The Compiler class is provided to support Java-to-native-code compilers and related services.
The Double class wraps a value of the primitive type double in an object.
Enum<E extends Enum<E>>
This is the common base class of all Java language enumeration types.
The Float class wraps a value of primitive type float in an object.
This class extends ThreadLocal to provide inheritance of values from parent thread to child thread: when a child thread is created, the child receives initial values for all inheritable thread-local variables for which the parent has values.
The Integer class wraps a value of the primitive type int in an object.
The Long class wraps a value of the primitive type long in an object.
The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
The abstract class Number is the superclass of classes BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, and Short.
Class Object is the root of the class hierarchy.
Package objects contain version information about the implementation and specification of a Java package.
The ProcessBuilder.start() and Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it.
This class is used to create operating system processes.
Represents a source of subprocess input or a destination of subprocess output.
Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running.
This class is for runtime permissions.
The security manager is a class that allows applications to implement a security policy.
The Short class wraps a value of primitive type short in an object.
An element in a stack trace, as returned by Throwable.getStackTrace().
The class StrictMath contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
The String class represents character strings.
A thread-safe, mutable sequence of characters.
A mutable sequence of characters.
The System class contains several useful class fields and methods.
A thread is a thread of execution in a program.
A thread group represents a set of threads.
This class provides thread-local variables.
The Throwable class is the superclass of all errors and exceptions in the Java language.
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void.

Package java.io Description
Provides for system input and output through data streams, serialization and the file system. Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.

List of classes available in IO  package


Class
Description
A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the input and to support the mark and resetmethods.
The class implements a buffered output stream.
Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
Writes text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings.
A ByteArrayInputStream contains an internal buffer that contains bytes that may be read from the stream.
This class implements an output stream in which the data is written into a byte array.
This class implements a character buffer that can be used as a character-input stream.
This class implements a character buffer that can be used as an Writer.
Methods to access the character-based console device, if any, associated with the current Java virtual machine.
A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way.
A data output stream lets an application write primitive Java data types to an output stream in a portable way.
An abstract representation of file and directory pathnames.
Instances of the file descriptor class serve as an opaque handle to the underlying machine-specific structure representing an open file, an open socket, or another source or sink of bytes.
A FileInputStream obtains input bytes from a file in a file system.
A file output stream is an output stream for writing data to a File or to a FileDescriptor.
This class represents access to a file or directory.
Convenience class for reading character files.
Convenience class for writing character files.
A FilterInputStream contains some other input stream, which it uses as its basic source of data, possibly transforming the data along the way or providing additional functionality.
This class is the superclass of all classes that filter output streams.
Abstract class for reading filtered character streams.
Abstract class for writing filtered character streams.
This abstract class is the superclass of all classes representing an input stream of bytes.
An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specifiedcharset.
Deprecated
This class incorrectly assumes that bytes adequately represent characters.
A buffered character-input stream that keeps track of line numbers.
An ObjectInputStream deserializes primitive data and objects previously written using an ObjectOutputStream.
Provide access to the persistent fields read from the input stream.
An ObjectOutputStream writes primitive data types and graphs of Java objects to an OutputStream.
Provide programmatic access to the persistent fields to be written to ObjectOutput.
Serialization's descriptor for classes.
A description of a Serializable field from a Serializable class.
This abstract class is the superclass of all classes representing an output stream of bytes.
An OutputStreamWriter is a bridge from character streams to byte streams: Characters written to it are encoded into bytes using a specifiedcharset.
A piped input stream should be connected to a piped output stream; the piped input stream then provides whatever data bytes are written to the piped output stream.
A piped output stream can be connected to a piped input stream to create a communications pipe.
Piped character-input streams.
Piped character-output streams.
A PrintStream adds functionality to another output stream, namely the ability to print representations of various data values conveniently.
Prints formatted representations of objects to a text-output stream.
A PushbackInputStream adds functionality to another input stream, namely the ability to "push back" or "unread" one byte.
A character-stream reader that allows characters to be pushed back into the stream.
Instances of this class support both reading and writing to a random access file.
Abstract class for reading character streams.
A SequenceInputStream represents the logical concatenation of other input streams.
This class is for Serializable permissions.
The StreamTokenizer class takes an input stream and parses it into "tokens", allowing the tokens to be read one at a time.
Deprecated
This class does not properly convert characters into bytes.
A character stream whose source is a string.
A character stream that collects its output in a string buffer, which can then be used to construct a string.
Abstract class for writing to character streams.


This information gathered from following link

http://docs.oracle.com/javase/7/docs/api/index.html







No comments:

Post a Comment