Ch_1 : introduction to java.
- java is geeral purpose , high level, object oriented programing language.
- oops use their object ad itraction to design application and computer program.
- java use to create web application, mobile application, standlone application , enterprices application.
Features of OOP’s :
- oops follow buttom-up approach in program design.
- oops program is divided into objects.
- objects in oops is communicate with each other using functions.
Classes :
- class is a blue print for created object.
- a class is a collection of objects .
- class are user defie datatype.
- class consist of data and method.
Object :
- object represent real-word runtime entity.
- an object is an instance of class.
- object has two general characteristics state and behaviour.
Data Abtraction :
- Data abtraction represent essential teatures without including background details or example.
- classes use the consept of abtraction.
Data Ancapsulation :
- data encapsulation means wrapping or binding the data and function into a single unit.
- the data is not accessible to the outside world.
Inheritance :
- inheritance means one class of object inherits the data and behaviour from another class.
- the old class is refered as base class and new class is colled as derived class.
- the new class has combined features of the both class.
Polymorphism :
- polymorphism is the ability of an object to take on many froms.
- the most common use of ther polymorphism in oop occurs when a parent class reference is used to refer to a child
class object.
Advatage of OOP :
- Software is easily developed for complex problems.
- software matnance cost is reduced.
- improved performance.
- Quality improved.
- provide better data security.
Disadvatages :
- requires intensive testing procedures.
- solving a problem using OOP approach consumes more time.
**FEATURES OR BUZZWORDS OF JAVA :
Simpl Object
Dynami oriente
Architecur
Secur neutr
High
Multi performanc
threade
Feature
Platfor
Interactiv independe
Distribute
Robus
Interprete Portabl
JAVA TOOLS :
1 . JAVAC :
- javac is used to compile java source into bytecode.
2 . java :
- java is the interpreter which launches a java program.
3 . AppletViewer :
- an Applet is a java program that run in the web browser.
- AppletViewer is runs outside the browser.
4 . jdb :
- the java debugger is a tool for java classes to debug a program I command line.
- jdb helps to find and fix bugs ion java language program.
5 . Javadoc :
- Javadoc tool is a document generator tool in java for generating standart documentation in HTML format.
- Javadoc is comes with JDK and it is used for geeratig java code documentation in a predefine format.
6 . javap :
- the javap is used to get the information of any class.
- the javap command command disassembles one or more class files.
7 . jar :
- jar stads for java archive.
- jar tool used to combine multiple files into a single JAR archive file.
- jar is a general purpose archiving and compression tool based on ZIP and the ZLIB compression format.
DATA TYPE :
- datatype specify the different values that can be stored I the variable.
- variable means reserver memory location to store values .
PRIMITIVE DATA TYPE :
-primitive data type also known as built-in data types.
- In java language primitive data type includes integer, floting point, character and Boolean.
- byte, short, int, long, float, double, Boolean, char,
FINAL VARIABLE :
- variable are useful when we need to store information that can be changed as program runs.
- the final variable also colled constant variable.
- the final variable is a variable woth a value that cannot be modified during the execution of the program.
Ex . fial int = 12;
ARRAYS IN JAVA :
-An array is a group of continues memory location that store the data .
- an array is a collection of similar type of elements that have continuous memory location.
ACCEPTING INPUT :
- java provide different way to get input from the user.
- using BuferedReader class reads text form a character – input stream.
OOP’S_CH_2 : Objects and Classes
• Java is an object-oriented programming language. Objects and classes are the basic building blocks of OOP.
• An object is a basic unit of OOP and represents the real life entities like a house, a tree
• Classes create objects and objects use methods to communicate between them.
Object in Java:
• An object is A real-world entity that has state and behaviour.
Class in Java:
• A class is a user-defined type which groups data members.
• In Java language the data members are called fields and the functions are called methods.
CONSTRUCTORS :
• A constructor is a special method of a class in Java programming that initializes an object.
• Constructors have the same name as the class itself. A constructor is automatically called when an object is
created.
• Constructors can be classified into two types, default constructors and parametarized constructors.
Default Constructor:
• The constructor which does not accept any argument is called default constructor.
M
• In other word, when the object is created Java creates a no-argument constructor automatically known as
default constructor.
• It does not contain any parameters nor does it contain any statements in its body.
Parameterized Constructor:
• A constructor that has parameters is known as parameterized constructor.
• Parameterized constructor is used to provide different values to the distinct objects.
r.
CONSTRUCTOR OVERLOADING :
• Constructor having the same name with different parameter list is called as constructor overloading.
USE OF 'this' KEYWORD :
• 'this' keyword can be used to refer current class instance variable.
• 'this' keyword can be used to invoke current class constructor.
• The ‘this’ is used inside the method or constructor to refer its own object
R
STATIC BLOCK, STATIC FIELDS AND METHODS :
• In Java basically, class contains variables called instance variables and methods called instance method.
Static Block :
• A class can contain code in a static block that does not exist within a method body. Static code block
executes only once when the class is loaded.
oh
• A static block is used to initialize static attributes. Static blocks are also called static initialization blocks.
• A static initialization block is a normal block of code enclosed in braces, { }, and preceded by the static
keyword. static {
//whatever code is needed for initialization goes here, …
}
• A class can have any number of static initialization blocks, and they can appear anywhere in the class
it
body.
Static Field :
• A static field of a class is referred as a class variable .
• A static field gets memory only once for the whole class.
• To declare a static field It's syntax is, static datatype fieldName;
Static Methods :
• If you apply static keyword with any method, it is known as static method.
• A static method belongs to the class.
• Static method can access static data member and can change the value of it.
• A static method is also called class method as it is associated with a class and not with individual instance
of the class.
• A static method cannot access non-static method.
Object Class :
• The object class is the parent class of all the classes in Java by default. In other words, it is the topmost class of
java.
• The Object class provides some common behaviours to all the objects such as object can be compared, object can
be cloned, object can be notified etc.
• Some methods of the object class are:
Boolean equals(Object obj) , protected Object clone() , int hashCode() , void notify(). void notifyAll() .
String Class :
• The strings in Java are treated as objects of type 'String' class. This class is present in the package [Link].
• This package contains two string classes String class and StringBuffer class.
• The string class is used when we work with the string which cannot change whereas StringBuffer class is used
when we want to manipulate the contents of the string.
• When we create object of String Class they are designed to be immutable.
• We can use + operator to overload for string objects. Only two operators i.e. '+' & '+=" are overloaded for string
classes.
Example: String str = "Kal" + "pa" + "na";
Output: Kalpana
M
StringBuffer Class :
• It is a peer class which provides the functionality of strings. The string generally represents fixed length,
immutable character sequence whereas StringBuffer represents growable and writeable character sequences.
• StringBuffer may have some characters
• Java generally manipulate the strings using + as overloaded operator. StringBuffer class in Java is used to created
mutable (modifiable) string.
r.
• The StringBuffer class in Java is same as String class except it is mutable i.e., it can be changed.
Advantages of StringBuffer Class: 1. Alternative to String class. 2. Can be used wherever a string is used. 3. More
flexible than String.
Difference between String and StringBuffer:
• String objects are constants and immutable whereas StringBuffer objects are not constants and immutable.
• StringBuffer Class supports growable and modifiable string whereas String class supports constant strings.
R
• Strings once created we cannot modify them Whereas StingBuffer objects after creation also can be able to
delete or append any characteres to it.
• String values are resolved at run time whereas StringBuffer values are resolved at compile time.
WRAPPER CLASSES :
• A data type is to be converted into an object and then added to a Stack. For this conversion, the introduced
oh
wrapper classes.
PACKAGES :
• A Java package is a mechanism for organizing Java classes.
• A package can be defined as "a group of similar types of classes, interface, enumeration and sub-packages".
• Packages are collection of classes and interface or packages act as container for classes.
• There are two types of packages:
it
1. Built-in Package: Existing built-in Java packages like [Link], [Link], [Link] etc.
2. User-define Package: Java package created by user to categorized classes, interface and enumeration.
Creating Packages :
• simply include a package command as the first statement in a Java source file.
• package pkg_name;
• There are three ways to access the package from outside the package.
•Using packagename:
• If we use package.* then all the classes and interfaces of this package will be accessible but not
subpackages. • The ‘import’ keyword is used to make the classes and interface of another package
accessible to the current package.
• Using [Link]:
• If we import [Link] then only declared class of this package will be accessible.
User Defined Packages :
• The packages credited by user are called as user defined package.
• User defined packages generally represent programs data.
it
oh
R
r.
M
OOP’S_CH_3 :Inheritance and Interface
• Inheritance can be defined as, the process where one class acquires the properties of another. With the use of inheritance
the information is made manageable in a hierarchical order
INHERITANCE :
• Inheritance can be defined as, “the process where one object acquires the properties of another class.
• Inheritance represents the 'IS-A relationship', also known as 'parent-child relationship'.
•In simple words, the mechanism of deriving a new class from an old class is called inheritance.
• A class that is derived from any another class is called a subclass or derivedclass or extendedclass or childclass.
•The class from which a subclass is derived is called superclass or baseclass or parentclass.
• The keyword ‘extends’ is used to inherit the properties of a class through another class.
• The keyword extends indicates that, we are making a new class that derives from an existing class.
Types of Inheritance :
• Single Inheritance:
• When a class extends another one class only then we call it a single inheritance.
• In case of single inheritance there is only a sub class and it's parent class. It is also called simple inheritance
or one level inheritance.
• Multilevel Inheritance:
M
• We can create any layers in the inheritance as we want, this is called Multilevel Inheritance.
• When a subclass is derived from a derived class then this mechanism is known as the Multilevel inheritance.
• The derived class is called the subclass or child class.
Use of 'super' Keyword :
• The 'super' keyword is used by subclass to refer its immediate superclass.
•There are two different forms of using super:
r.
1. 'super' calls the superclass constructor.
2. 'super' can access members of the superclass those have been hidden by members of a subclass.
method overriding :
• If the same method is defined in both the superclass and the subclass, then the method of the subclass class
overrides the method of the superclass. This is known as method overriding.
• If subclass (child class) has the same method as declared in the parent class, it is known as method overriding
R
• Method overriding is an example of runtime polymorphism
Runtime polymorphism :
• Runtime polymorphism is a process in which a call to an overridden method is resolved at runtime rather than
compile-time.
oh
• Method overriding is an example of runtime polymorphism.
USAGE OF 'final' KEYWORD :
• The "final" is a keyword in Java which generally means, cannot be changed once created.
• The final variables cannot be modified, The final method cannot be overridden. , The final class cannot be inherited
or extended.
Abstraction :
• Abstraction is a process of hiding the implementation details and showing only functionality to the user.
it
• The methods which have only declaration and no method body in the base class are called abstract method.
• The abstract methods are declared using the keyword "abstract".
INTERFACE :
• An interface in Java is a blueprint of a class. It has static constants and abstract methods only.
• A class can implement more than one interface. In Java, an interface is not.
• Interfaces can also have more than one method.
Marker Interface:
• An interface that does not contain methods, fields, and constants is known as marker interface .
Functional Interface:
• An interface that contains exactly one abstract method is known as functional interface.
OOP’s_ch_4 :User Interface with AWT and Swing
• Every user interface considers the following three main aspects: UI elements, Layouts, Behavior.
• The Abstract Window Toolkit (AWT) is Java's original platform-dependent windowing, graphics, and user-
interface widget toolkit.
• The AWT is part of theJava Foundation Classes (JFC) .
What is AWT? :
• The Java programming language class library provides a user interface toolkit called the Abstract Window
Toolkit, or the AWT.
•Java AWT is an API to develop GUI or window-based application in Java.
• Java AWT components are platform-dependent.
• The AWT is now part of the Java Foundation Classes (JFC) is the standard API for providing a Graphical
User Interface (GUI) for a Java program.
• The AWT classes are contained in the [Link] package. It is one of Java’s largest packages.
What is Swing? :
• Swing is a GUI widget toolkit for Java.
• It is part of Oracle's Java Foundation Classes (JFC)- is the API for providing a Graphical User Interface (GUI)
for Java programs.
• The swing components are defined in the package [Link]. This package provides more powerful and
Mr
flexible components
• Swing is a Java foundation classes, library and it is has extension to do Abstract Window Toolkit (AWT).
• Various features of swing are:
Light Weight, Rich Controls, Borders, Easy mouseless Operation, Tooltips, Easy Scrolling, Highly
.R
Customizable,
Sr. No. AWT Swing
1. AWT components are platform dependent. Java swing components are platformindependent.
oh
2. AWT components are heavy weight. Swing components are light weight.
3. AWT doesn't support pluggable look and feel. Swing supports pluggable look and feel.
4. AWT provides less components than Swing. Swing provides more powerful com-
it
ponents such as tables, lists, scrollpanes, colorchooser,
tabbedpane etc.
5. AWT components require [Link] package. Swing components require [Link] package.
6. Advanced features is not available in AWT. Swing has many advanced features like JTabel, Jtabbed
pane which is not available in AWT.
7. Different looked feel feature is not supported in AWT. We can have different look and feel in Swing.
8. Using AWT, we have to implement a lot of things ourself. Swing has them built in.
LAYOUTS AND LAYOUT MANAGERS :
• Layout means the arrangement of components within the container.
• In other way we can say that placing the components at a particular position within the container.
• Layout manager is an object which determines the way that components are arranged in a frame window.
• A layout manager automatically arranges our controls within a window by using some type of algorithm.
• A layout manager is an instance of any class that implements the LayoutManager interface.
• The layout manager is set by the setLayout() method.
• Each layout manager keeps track of a list of components that are stored by their names
• The layout manager automatically positions all the components within the container.
• A check box is a control that is used to turn an option on (true) or off (false). It consists of a small box that can
either contain a check mark or not.
• Listclass provides a list of items, which can be scrolled. From list of items, single or multiple items can be selected.
•A menu bar displays a list of top-level menu choices. Each choice is associated with a dropdown menu.
• The JButton class is used to create a push buttons.
• A toggle button is two states button that allows user to switch on and off. To create a toggle button in Swing we
use JToggleButton class
• The JTextField component allows us to enter/edit a single line of text.
• The JTextArea is used to accept several lines of text from the user and it has capabilities not found in the AWT
class.
• Swing provides a combo box (a combination of a text field and a dropdown list) through the JComboBox class,
which extends JComponent. A combobox normally displays one entry.
• A dialog is defined as a conversation between two or more persons. In a computer application a dialog is a
window which is used to "talk" to the application.
• Message dialogs are simple dialogs that provide information to the user.
• File chooser dialog box is used for navigating the file system.
• The class JColorChooser provides a pane of controls designed to allow a user to manipulate and select a color.
EVENT HANDLING :
Mr
• Changing the state of an object is known as an even.
• The [Link] package provides many event classes and Listener interfaces for event handling.
• Each event must return a Boolean value (true or false).
•An Event is an object that describes a state change in a source.
.R
•Event handling is a process of responding to events that can occur at any time during execution of a
program.
ADAPTERS :
• Adapter pattern is frequently used in modern Java frameworks.
• Adapter pattern works as a bridge between two incompatible interfaces.
oh
• This pattern involves a single class which is responsible to join functionalities.
ANONYMOUS INNER CLASSES :
• Anonymous classes of Java are called anonymous because they have no name.
• A class that have no name is known as anonymous inner class in Java.
it
•An anonymous class is a local class without a name.