Bit OOPJ
Bit OOPJ
a simple language. Many features JAVA OPERATORS - An operator is a symbol that tells the computer to TYPES OF JAVA PROGRAMS - 1)Standalone applications are programs
provides a way of modularizing programs by creatingpartitioned of C and C++ that are either redundant or sources of unreliable code are perform certain mathematical or logical manipulations.Operators are written in Java to carry out certain task on a standalone computer.
memory area for both data and functions thatcan be used as not part of Java. For example, Java does not use Pointers , used in programs to manipulate data and variables. They usually form a Executing a standalone Java program involves two steps:Compiling
templates for creating copies of such modules on Preprocessor Directives , goto, Operator overloading , Multiple part of mathematical or logical expressions.Java operators can be source code into bytecodes using javac compiler.Executing the
demand.Emphasis is on data rather than procedure.Programs are Inheritance. 2. Object-Oriented - Java is a true Object Oriented classified into number of related categories: bytecode program using java interpreter. 2)Applets are small Java
divided into Objects.Data structures are designed such that they Language. Almost everything in Java is an object. All program code and 1)Arithmetic operators - Arithmetic operators are used in mathematical program developed for Internet Applications. An applet
characterize the object.Methods that operate on the data of an data reside within objects and classes. Java comes with an extensive expressions in the same way that they are used in algebra. located on distant computer(Server) can be downloaded via Internet
object are tied together in the data structure.Data is hidden and set of classes, arranged in packages, that we can use in our programs by Operators are - Addition(+),Subtraction (-),Multiplication and executed on a local computer (Client) using a Java-capable
cannot be accessed by external functions.Objects may inheritance. The object model in Java is simple and easy to extend. 3. (*),Modulus(%),Division(/).The operands of the arithmetic operators browser.From simple animated graphics to complex games and utilities
communicate with each other through methods.New data and Robust - Java is a robust language. It provides many safeguards to must be of a numeric type. You cannot use them on boolean types, but can be developed by applets.Standalone programs can read and write
methods can be easily added whenever necessary.Bottom up ensure reliable code.The multiplatformed environment of the Web you can use them on char types, since the char type in Java is, files and perform certain operations. Applet can only run within a web
approach is followed in the program design.CONCEPTS - places extraordinary demands on aprogram,because the program must essentially, a subset of int.The minus operator also has a unary form browser.
i)OBJECTS : Objects are basic runtime entities in an object execute reliably in a variety of systems.At the same time, Java frees you that negates its single operand.
oriented system.They may represent a person, a place, a bank from having to worry about many of the most common causes of Integer arithmetic - When both the operands in a single arithmetic JAVA TOKENS - Smallest individual units in a program are known as
account, a table etc.,They may represent user-defined data type programming errors. Because Java is a strictly typed language, it expression such as a+b are integers, the expression is called an integer Tokens. The compiler recognizes them for building up expressions and
such as vector, list etc.,Any programming problem is analyzed in checks your code at compile time. However, it also checks your code at expression and the operation is called integer arithmetic.Integer statements.A Java program is a collection of tokens, comments and
terms of objects and the nature of communication between run time. Java virtually eliminates these problems by managing arithmetic always yields an integer value. white spaces.Java language includes five types of tokens. They are:
them.Objects take up space in memory and has an associated memory allocation and deallocation for you. Exceptional conditions in Real Arithmetic - An arithmetic operation involving only real operands 1)Java Character Set - The characters are used to write Java
address.When a program is executed, the objects interact by traditional environments often arise in situations such as division by is called real arithmetic.Unlike C and C++, modulus operator % can be Tokens.These characters are defined by the Unicode character set. This
sending messages to one another.Eg: customer object may send a zero or “file not found,” and they must be managed with clumsy and applied to the floating point data as well.The floating point modulus standard tries to create characters for a large number of scripts
message to account object requesting balance.Each object has hard-to-read constructs. Java helps in this area by providing object- operator returns the floating point equivalent of an integer division. worldwide.The Unicode is a 16-bit character coding system and
data and code to manipulate the data. oriented exception handling.In a well-written Java program, all run- (i.e) The division is carried out with both floating point operands, but currently supports more than 34,000 defined characters derived from
ii)CLASS : A class is a collection of objects of similar type.The time errors can—and should—be managed by your program. 4. Secure - the resulting divisor is treated as an integer, resulting in a floating 24 languages from America, Europe, Middle east, Africa and Asia.
entire set of data and code of an object can be made a user- In order for Java to enable applets to be downloaded and executed on point remainder. 2)Keywords - Keywords implement specific features of the Language.
defined data type using the concept of Class.A class is thought of the client computer safely, it was necessary to prevent an applet from Mixed mode Arithmetic - When one of the operand is real and the other Java language has 50 words as keywords.These keywords, combined
a “data type” and object as a “variable”.Once a class is defined we launching such an attack.Java achieved this protection by confining an is integer, the expression is called a mixed mode arithmetic expression. with operators and separators according to a syntax, form the
can create any number of object belonging to that class.Eg: Shape applet to the Java execution environment and not allowing it access to If either operand is of the real type, then the other operand is foundation of the Java language.Since keywords have specific meaning
is the class .Square,triangle, rectangle are the objects. other parts of the computer.The ability to download applets with converted to real and the real arithmetic is performed. The result will in Java, it can not be used as names for variables, class, methods and so
iii)DATA ABSTRACTION AND ENCAPSULATION : The wrapping up confidence that no harm will be done and that no security will be be a real. on.All keywords are written in lower case letters.In addition to the
of data and methods into a single unit(class) is known as breached is considered by many to be the single most innovative 2)RELATIONAL OPERATORS- determine the relationship that one keywords, Java reserves the following: true, false, and null. These are
encapsulation.Data encapsulation – the data is not accessible to aspect of Java.The absence of pointers in Java ensures that programs operand has to the other.Specifically, they determine equality and values defined by Java. You may not use these words for the names of
the outside world and only those methods which are wrapped in cannot gain access to memory locations without proper authorization. ordering. The relational operators are shown here: Op1 variables, classes, and so on.
the class can access it. These methods provide the interface 5. Distributed - Java is designed as a distributed language for creating relational_operator OP2, OP1 and OP2 can be constants,variables or 3)Identifiers - Identifiers are programmer designed tokens. They are
between object’s data and program.This insulation of data from application on network.It has the ability to share both data and combination of them.When arithmetic expressions are used on either used for naming classes, methods, variables, objects, labels, packages
direct access by the program is called data hiding.Encapsulation programs.Java applications can open and access remote objects on side of relational operator, the arithmetic expressions will be evaluated and interface in a program.
makes it possible for objects to be treated like “black box” each Internet as easily as they can do in a local system.This enables multiple first and then the result compared. Arithmetic operators have higher Java identifiers follow the following rules: An identifier may be any
performing a specific task without any concern for internal programmers at multiple remote locations to collaborate and work priority than relational operator. descriptive sequence of uppercase and lowercase letters, numbers, or
implementation.Abstraction refers to the act of representing together on a single project.Java is designed for the distributed Operators - equal to(==),not equal to (!=),>(greater than),<(less than),<= the underscore and dollar-sign characters.They must not begin with a
essential features without including the background environment of the Internet because it handles TCP/IP protocols.In (less than or equal to ), >=(greater than or equal to) .In Java, true and number.Uppercase and lowercase letters are distinct.
details.Example of Encapsulation and Abstraction fact, accessing a resource using a URL is not much different from false are nonnumeric values that do not relate to zero or nonzero. They can be of any length Identifiers must be meaningful, short enough
Mobile Phone – used for text and voice communication accessing a file.Java also supports Remote Method Invocation (RMI). Therefore, to test for zero or nonzero, you must explicitly employ one to be quickly and easily typed and long enough to be descriptive and
Internal circuitry of the mobile phone function is hidden from the This feature enables a program to invoke methods across a network. or more of the relational operators. easily read.
user. User 6. Multithreaded - Java was designed to meet the real-world 3)LOGICAL OPERATORS - are used to combine two or more 4)Literals - A constant value in Java is created by using a literal
concerned about pressing the “answer key” to talk. requirement of creating interactive, networked programs.To relationalexpressions.The logical operators are: || Short-circuit OR , && representation of it. A literal can be used anywhere a value of its type is
Operations: Dialing a call, receiving a call, sending and receiving accomplish this, Java supports multithreaded programming, which Short-circuit AND , ! Logical unary NOTAn expression which combines allowed.Java language specifies following types of literals: Integer
text messages. allows you to write programs that do many things simultaneously.The two or more relational expressions is termed as a logical expression or a Literals , Floating_point Literals , Character Literals , String Literals ,
Data : address book, inbox, sent items. Java run-time system comes with an elegant yet sophisticated solution compound relational expression.It yields a value of true or false Boolean Literals , Null Literal
sets of data and operations – abstraction of generic mobile phone. for multiprocess synchronization that enables you to construct according to the truth table.Eg: a>b && x==10; 5)Operators - An operator is a symbol that takes one or more arguments
iv)INHERITANCE : Inheritance is the process by which one object smoothly running interactive systems.Java’s easy-to-use approach to BOOLEAN LOGICAL OPERATORS - operate only on boolean and operators on them to produce a result. There are many types of
acquires the properties ofanother object.This is important multithreading allows you to think about the specific behavior of your operands.All of the binary logical operators combine two boolean operators.
because it supports the concept of hierarchical classification.Eg: program, not the multitasking subsystem. 7. Compiled and Interpreted - values to form a resultant boolean value.The logical Boolean operators, 6)Separators - Separators are symbols used to indicate where groups of
Bird Robin is a part of the class “Flying bird”, which is again a part Usually a computer language is either compiled or interpreted. Java &, |, and ^, operate on boolean values in the same way that they operate code are divided and
of the class “bird”.Without the use of hierarchies, each object combines both the approaches thus making Java a two stage on the bits of an integer. The logical ! operator inverts the Boolean arranged. They basically define the shape and function of our
would need to define all of its characteristics explicitly.However, system.First ,Java compiler translates source code into what is known state:!true == false and !false == true.If you use the || and && forms, code.Parenthesis() , Braces {} , Brackets [ ] , Semicolon ; , Comma (,) ,
by use of inheritance, an object need only define those qualities as bytecode instructions. Bytecode are not machine instructions.In the rather than the | and & forms of these operators, Java will not bother to Period ( . )
that make it unique within its class.It can inherit its general second stage, Java interpreter generates machine code that can be evaluate the right-hand operand when the outcome of the expression
attributes from its parent.Thus, it is the inheritance mechanism directly executed by the machine that is running the Java Program. can be determined by the left operand alone.This is very useful when
CONTROL STATEMENTS - A programming language uses control
that makes it possible for one object to be a specific instance of a 8.Architecture-Neutral - A central issue for the Java designers was that the right-hand operand depends on the value of the left one in order to
statements to cause the flow of execution to advance and branch based
more general case. The concept of Inheritance provide the idea of of code longevity and portability.One of the main problems facing function properly.
on changes to the state of a program.Java’s program control
“reusability”. This means we can add additional features to an programmers is that no guarantee exists that if you write a program
4)ASSIGNMENT OPERATOR - is used to assign the value of an statements can be put into the following categories: selection,
existing class without modifying it. This is possible by deriving a today, it will run tomorrow—even on the same machine. Operating
expression to a variable.The assignment operator is the single equal iteration, and jump.
new class from the existing one.The real appeal and power of system upgrades, processor upgrades, and changes in core system
sign, =. The assignment operator works in Java much as it does in any DECISION MAKING WITH IF STATEMENT - The if statement is a powerful
inheritance mechanism is that it allows the programmer to reuse a resources can all combine to make a program malfunction.The Java
other computer language. It has this general form: decision making statement and is used to control the flow ofexecution
class and also add new features to the new class without designers made several hard decisions in the Java language and the
var = expression; of statements.The if statement may be implemented in different forms
introducing undesirable side effects into the rest of the classes.In Java Virtual Machine in an attempt to alter this situation.Their goal was
depending on the complexity of conditions to be tested.
Java, the derived class is known as ‘subclass’ or ‘child class’Each “write once; run anywhere, any time, forever.” To a great extent, this Here, the type of var must be compatible with the type of
expression.The assignment operator does have one interesting i)Simple if statement
subclass defines only those features that are unique to it. goal was accomplished.
attribute that you may not be familiarwith .Advantage of shorthand if…else statement
v)POLYMORPHISM: Polymorphism is another important OOP 9. Interpreted and High Performance - Java enables the creation of
assignment operator:Left-hand side need not be repeated and if (test expression or condition) { Statement-block; }
concept.Polymorphism means the ability to take more than one cross-platform programs by compiling into an intermediate
therefore it becomes easier to write.The statement is more concise and Statement-X;
form.For example, an operation may exhibit different behavior in representation called Java bytecode. This code can be executed on any
easier to read.Use of shorthand operator results in a more efficient The Statement-block may be single or group of statements. If the test
different instances.The behavior depends upon the types of data system that implements the Java Virtual Machine. Most previous
code. expression is true, the statement-block will be executed; otherwise it
used in the operation.The concept of polymorphism is often attempts at cross-platform solutions have done so at the expense of
will be skipped and the execution will jump to the statement-X.When
expressed by the phrase “one interface,multiple methods.” performance.The Java bytecode was carefully designed so that it would
5)INCREMENT AND DECREMENT Operators - The operator ++ adds 1 to the condition is true both the statement-block and statement-X will be
Compile time refers to any of the following: be easy to translate directly into native machine code for very high
the operand while – subtracts 1.Both are unary operators. executed in sequence.Most often, the expression used to control the if
The operations performed by the compiler such as syntactic and performance by using a just-in-time compiler. Java run-time systems
++m or m++ => m=m+1; --m or m-- =>m=m-1; will involve the relational operators. However, this is not technically
semantic that provide this feature lose none of the benefits of the platform-
++m and m++ mean the same thing when they form statements necessary. It is possible to control the if using a single boolean variable
analysis.The pre-runtime assessment of the program’s behavior. independent code.
independently, but they behave differently when they are used in ii)IF…ELSE STATEMENT - If the test expression is true, then the true-
In Java, apart from syntax and semantic checks, one important 9. Dynamic and Extensible - Java is capable of dynamically linking in
expressions on the right-hand side of an assignment statement. block statement immediately following the if statement are executed;
logical task new class libraries, methods and objects.Java supports functions
otherwise, the false-block statements are executed.
that is considered to be performed at compile time is the written in other languages such as C and C++. These functions are
6)CONDITIONAL OPERATOR- The Character pair ?: is called conditional if (test expression or condition) { True block Statement-block; }
implementation of known as native methods.Native methods are dynamically linked at
or ternary operator.This is used to construct conditional expression of else {
inheritance. It is at compile time that the child class inherits the runtime.
the form Expression1? Expression2: Expression3 false block statement ; }
public data 10. Portability - Portability is a major aspect of the Internet because
Expression1 is first evaluated. If it is true, then Expression2 is evaluated Statement-X;
members and methods of the base class.Runtime, on the other there are many different types of computers and operating systems
and becomes the value of the conditional expression. If Expression1 is iii)NESTING OF IF..ELSE STATEMENT - When a series of decisions are
hand is the time period when a syntactically correct program is connected to it. If a Java program were to be run on virtually any
false, Expression3 is evaluated and its value becomes the value of the involved, more than one if..else statement is needed.
actually executed in the computer system. Thus all the task computer connected to the Internet, there needed to be some way to
conditional expression.Both expression2 and expression3 are required iv)THE ELSE IF LADDER - Multipath decisions are involved else if ladder
thatare performed during this time is prefixes with word runtime enable that program to execute on different systems.For example, in
to return the same type, which can’t be void. is used. A multipath decisions is a chain of ifs in which the statement
or dynamic such as runtime type checking or dynamic memory the case of an applet, the same applet must be able to be downloaded
Example: a=10; b=15; associated with each else is an if.
allocation.In Java, one of the important concepts that is and executed by the wide variety of CPUs,operating systems, and
X=(a>b)?a:b; => 15 v)SWITCH STATEMENT - The switch statement is Java’s multiway
associated with runtime is the browsers connected to the Internet. It is not practical to have different
True branch statement. It provides an easy way to dispatch execution to
implementation of polymorphism. It is also referred as Dynamic versions of the applet for different computers.The same code must
False different parts of your code based on the value of an expression.As
Binding. work on all computers.
7)BITWISE OPERATOR- Java defines several bitwise operators that can such, it often provides a better alternative than a large series of if-else-
vi)DYNAMIC BINDING : Binding refers to the linking of a procedure 11. Ease of Development - Java 2 Standard Edition (2SE) 5.o supports
be applied to the integer types, long, int, short, char, and byte.These if statements.The expression must be of type byte, short, int, or char;
call to the code to be executed in response to the call.Dynamic features, such as Generics, Enhanced for Loop, Autoboxing or unboxing,
operators act upon the individual bits of their operands. each of the values specified in the case statements must be of a type
binding means that the code associated with a given procedure Typesafe Enums, Varargs, Static import and Annotation. These features
BITWISE LOGICAL OPERATOR- The bitwise logical operators are &, |, ^, compatible with the expression.Each case value must be a unique
call is known until the time at runtime.It is associated with reduce the work of the programmer by shifting the responsibility of
and ~.Bitwise operators are applied to each individual bit within each literal (that is, it must be a constant, not a variable). Duplicate case
polymorphism and inheritance. A procedure call associated with a creating the reusable code to the compiler. The resulting source code is
operand.Bitwise NOT - Also called the bitwise complement, the unary values are not allowed.The switch statement works like this: The value
polymorphic reference depends on the dynamic type of that free from bugs because the errors made by thecompiler are less when
NOT operator, ~, inverts all of the bits of its operand. For example, the of the expression is compared with each of the literal values in the case
reference. compared to those made by programmers. Thus, each of the linguistic
number 42, Bitwise AND - The AND operator, &, produces a 1 bit if both statements.If a match is found, the code sequence following that case
vii)MESSAGE COMMUNICATION: An object oriented program features is designed to develop Java programs in an easier way.
operands are also 1. A zero is produced in all other cases. Here is an statement is executed.If none of the constants matches the value of the
consists of a set of objects that communicate witheach other.The 12 Scalability and Performance - J2SE 5.0 assures a significant increase
example: expression, then the default statement is executed.However, the
process of programming in an object oriented language, therefore in scalability and performance by improving the startup time and
Bitwise OR - The OR operator, |, combines bits such that if either of the default statement is optional. If no case matches and no default is
involves the following basic steps.Creating classes that define reducing the amount of memory used in Java 2 runtimne environment.
bits in the operands is a 1, then the resultant bit present, then no further action is taken.The break statement is used
objects and their behavior.Creating objects from class For example, the introduction of the class, data sharing in the Hotspot
is a 1, Bitwise XOR - The XOR operator, ^, combines bits such that if inside the switch to terminate a statement sequence. When a break
definitions.Establishing communication among objects.Objects Java Virtual Machine GVM) improves the startup time by loading the
exactly one operand is 1, then the result is 1.Otherwise, the result is statement is encountered, execution branches to the first line of code
communicate with one another by sending and receiving core classes from the jar files into a shared archive. Memory utilization
zero. Left Shift (<<) - The left shift operator, <<, shifts all of the bits in a that follows the entire switch statement.This has the effect of “jumping
information by passing messages.A message for an object is a is reduced by sharing data in the shared archive among multiple JVM
value to the left a specified number of times. It has this general form: out” of the switch.The break statement is optional. If you omit the
request for execution of a procedure, and therefore will invoke a processes. In the earlier versions, the data was replicated in each JVM
value << num . Here, num specifies the number of positions to left-shift break, execution will continue on into the next case. It is sometimes
method in the receiving object that generates the desired result instance.
the value in value. That is, the << moves all of the bits in the specified desirable to have multiple cases without break statements between
as shown in the figure below.Message Passing involves specifying
value to the left by the number of bit positions specified by num.For them.
the name of the object, the name of the method(message) and the
SUPER - Whenever a subclass needs to refer to its immediate each shift left, the high-order bit is shifted out (and lost), and a zero is
information to be sent.When properly applied, polymorphism,
superclass, it can do so brought in on the right.This means that when a left shift is applied to an Nested switch Statements - You can use a switch as part of the
encapsulation, and inheritance combine to produce a
by use of the keyword super.super has two general forms.The int operand, bits are lost once they are shifted past bit position 31. If statement sequence of an outer switch. This is called a nested switch.
programming environment that supports the development of far
first calls the superclass’ constructor.The second is used to the operand is a long, then bits are lost after bit position 63 Since a switch statement defines its own block, no conflicts arise
more robust and scalable programs than does the process-
access a member of the superclass that has been hidden by a Right Shift (>>) - The right shift operator, >>, shifts all of the bits in a between the case constants in the inner switch and those in the outer
oriented model.A well-designed hierarchy of classes is the basis
member of a subclass.The parameters in the super call must value to the right a specified number of times. Its general form isshown switch.
for reusing the code in which you have invested time and effort
match the order and type of the instance variable declared in here: value >> num • The switch differs from the if in that switch can only test for equality,
developing and testing.Encapsulation allows you to migrate your
the superclass. Here, num specifies the number of positions to right-shift the value in whereas if can evaluate any type of Boolean expression. That is, the
implementations over time without breaking the code that
1)Using super to Call Superclass Constructors value. That is, the >> moves all of the bits in the specified value to the switch looks only for a match between the value of the expression and
depends on the public interface of your classes.Polymorphism
A subclass can call a constructor defined by its superclass by right the number of bit positions specified by num. one of its case constants.
allows you to create clean, sensible, readable, and resilient
use of Unsigned Right Shift (>>>) - The >> operator automatically fills the high- • No two case constants in the same switch can have identical values. Of
code.By the application of object-oriented principles, the various
the following form of super: order bit with its previous contents each time a shift occurs. This course, a switch statement and an enclosing outer switch can have case
parts of a
super(arg-list); preserves the sign of the value.However, sometimes this is undesirable. constants in common.
complex program can be brought together to form a cohesive,
Here, arg-list specifies any arguments needed by the For example, if you are shifting something that does not represent a • A switch statement is usually more efficient than a set of nested ifs.
robust,
constructor in numeric value, you may not want sign extension to take place.This
maintainable whole.
the superclass. situation is common when you are working with pixel-based values and .
super( ) must always be the first statement executed inside a graphics.In these cases, you will generally want to shift a zero into the JUMP STATEMENTS - When executing a loop it becomes desirable to
subclass’ constructor. high-order bit no matter what its initial value was. This is known as an skip a part of the loop or to leave the loop as soon as a certain condition
2)A Second Use for super - The second form of super acts unsigned shift. To accomplish this, you will use Java’s unsigned, shift-
BENEFITS OF OOPS - The principal advantages are:Through occurs.Java permits a jump from one statement to the end or beginning
somewhat like this, except that it right operator, >>>, which always shifts zeros into the high-order bit.
inheritance, we can eliminate redundant code and extend of a loop as well as jump out of a loop.Java supports three jump
always refers to the superclass of the subclass in which it is 8)SPECIAL OPERATORS i)instanceof operator - The instanceof is an
the use of existing classes.We can build programs from the statements: break, continue, and return. These statements transfer
used. This object reference operator and returns true if the object on the left-
standard working modules that communicate with one control to another part of your program.
usage has the following general form: hand side is an instance of the class given on the right-hand side. This
another, rather than having to start writing the code from JUMPING OUT OF A LOOP - An early exit from a loop can be
super.member operator allows us to determine whether the object belongs to a
scratch. This leads tosaving of development time and accomplished by using the break statement.Break is already used in
Here, member can be either a method or an instance variable. particular class or not.Eg: person instanceof student; Is true if the
higher productivity.The principle of data hiding helps the switch statement. This can be used within while, do while and for loops.
This second form of super is most applicable to situations in object person belongs to the class student; otherwise it is false.
programmer to build secure programs that cannot be Syntax: break;
which ii)Dot Operator - The dot operator(.) is used to access the instance
invaded by code in other parts of the program.It is possible When the break statement is encountered inside the loop, the loop is
member names of a subclass hide members by the same name in variables and methods of class objects. Eg: person1.age;
to have multiple objects to coexist without any immediately exited and the program continues with the statement
the person1.salary();It is also used to access classes and subpackages from
interference.It is possible to map objects in the problem immediately following the loop.During the loop operation, it my be
superclass. a package.
domain to those objects in the program.It is easy to necessary to skip a part of the body of the loop under certain
partition the work in a project based on objects.Object conditions.
Oriented system can be easily upgraded from small to large Continue statement causes the loop to be continued with the next
systems. iteration after skipping any statements in between. The continue
Message passing techniques for communication between statement tell the compiler ,”SKIP THE FOLLOWING STATEMENTS AND
objects make the interface descriptions with external CONTINUE WITH THE NEXT ITERATION”
systems much simpler.Software complexity can be easily SYNTAX : continue;
managed. RETURN - The last control statement is return. The return statement is
used to explicitly return from a method.That is, it causes program
APPLICATIONS OF OOPS - Real-time Systems , Simulation control to transfer back to the caller of the method.As such, it is
and modeling , Object Oriented databases , Hypertext and categorized as a jump statement. At any time in a method the return
hypermedia , AI and Expert Systems , Neural networks and statement can be used to cause execution to branch back to the caller
Parallel Programming , Decision support and office of the method.Thus, the return statement immediately terminates the
automation systems method in which it is executed.
LOOPING OR ITERATION OR REPETITION STATEMENT - The DATA TYPE - specify the size and type of values that DYNAMIC METHOD DISPATCH - Dynamic method IMPLEMENTING MULTIPLE INHERITANCE USING
process of repeatedly executing a block of statements is known can be stored.The variety of data types allow the dispatch is the mechanism by which a call to an INTERFACE
as Looping. programmer to select the type appropriate to the need overridden method is class Student {
The statement in the block may be executed any number of of the application.Various categories are: Primitive or resolved at run time, rather than compile int rollNumber;
times, from zero to infinite number. If a loop continues forever, intrinsic or built-in or simple types , Derived or Non time.Dynamic method dispatch is important void getNumber(int n) {
it is called an infinite loop.In looping, a sequence of statements Primitive or reference type.Java defines eight because this is how Java implements run-time rollNumber=n; }
are executed until some conditions for the termination of the primitive types of data: byte, short, int, long, char, polymorphism.A superclass reference variable can void putNumber() {
loop are satisfied. float, double,and boolean. refer to a subclass object. Java uses this fact to System.out.println(“Roll No:”+rollNumber); }}
Java’s iteration statements are for, while, and do-while. 1)Integers - Java defines four integer types: byte, resolve calls to overridden methods at run time.It class Test extends Student {
i)WHILE STATEMENT - The while loop is Java’s most short, int, and long. All of these are signed, positive is the type of the object being referred to (not the float part1,part2;
fundamental loop statement.It repeats a statement or block and negative values.Java does not support unsigned, type of the reference void getMarks(float m1,float m2) {
while its controlling expression is true.It is an entry-controlled positive-only integers.Wider datatypes require more variable) that determines which version of an part1=m1;
loop statement.Here is its general form: time for manipulation and therefore it is advisable to overridden method will be executed. part2=m2; }
Initialization: use smaller datatypes wherever possible. class A { void putMarks() {
while(condition or Boolean expression) (i)byte - The smallest integer type is byte.This is a void callme() { System.out.println(“Marks Obtained”);
{ signed 8-bit type that has a range from –128 to System.out.println("Inside A's callme method"); }} System.out.println(“Part 1 =”+part1);
//body of the loop 127.Variables of type byte are especially useful when class B extends A { System.out.println (“Part 2 =”+part2); }}
} you’re working with a stream of data from a network or void callme() { interface Sports {
The condition can be any Boolean expression. The body of the file.They are also useful when you’re working with raw System.out.println("Inside B's callme method"); }} float sportWt=6.0F;
loop will be executed as long as the binary data that may not be directly compatible with class C extends A { void putwt(); }
conditional expression is true. When condition becomes false, Java’s other built-in types.Byte variables are declared void callme() { class Results extends Test implements Sports {
control passes to the next line of code by use of the byte keyword. byte b, c; System.out.println("Inside C's callme method"); }} float total;
immediately following the loop. The curly braces are (ii) short - short is a signed 16-bit type. It has a range class Dispatch { public void putWt() {
unnecessary if only a single statement is being from –32,768 to 32,767.It is probably the least-used public static void main(String args[]) { System.out.println(“Sports Wt=“+sportWt); }
repeated. Java type. A a = new A(); void display() {
EXAMPLE short t; B b = new B(); total=part1+part2+sportWt;
(iii) int - The most commonly used integer type is int.It C c = new C(); putNumber();
public class MyClass { is a signed 32-bit type that has a range from – A r; putMarks();
public static void main(String[] args) { 2,147,483,648 to 2,147,483,647.In addition to other r = a; putWt();
int i = 0; uses, variables of type int are commonly employed to r.callme(); System.out.println(“Total Score=“+total); }}
while (i < 5) { control loops and to index arrays.The reason is that r = b; class Hybrid {
System.out.println(i); when byte and short values are used in an expression r.callme(); public static void main(String args[]) {
i++; }}} they are promoted to int when the expression is r = c; Result student1=new Results();
evaluated.Therefore, int is often the best choice when r.callme(); }} student1.getNumbers(1234);
ii)DO-WHILE STATEMENT - Like a while statement, except that an integer is needed. student1.getMarks(27.5F,33.0F);
it tests the condition at the end of the loop body. do...while (iv) long - long is a signed 64-bit type and is useful for student1.display(); }}
loop is guaranteed to execute at least one time. those occasions where an int type is not large enough
Syntax: to hold the desired value.The range of a long is quite
Initialization; large. This makes it useful when big, whole numbers INTERFACES - Java provides an alternate
do { are needed. approach known as interfaces to support the
//Body of the loop 2)Floating-Point Types - Floating-point numbers, also concept of multiple inheritance.Using the keyword
}while(condition or Boolean expression); known as real numbers, are used when evaluating interface, you can fully abstract a class’ interface
Notice that the Boolean expression appears at the end of the expressions that require fractional precision.For eg from its implementation.difference. The
loop, so the statements in the loop execute once before the calculations such as square root, or transcendentals difference is that interfaces define only abstract
Boolean is tested.If the Boolean expression is true, the control such as sine and cosine, result in a value whose methods and final fields.
jumps back up to do statement, and the statements in the loop precision requires a floating-point type.There are two This means that interfaces do not specify any code
execute again. This process repeats until the Boolean kinds of floating-point types, float and double, which to implement these methods and
expression is false. represent single- and double-precision numbers, data fields contain only constants.
respectively. Floating point datatype support a special access interface name {
public class Test { value Not-a-Number(NAN). return-type method-name1(parameter-list);
public static void main(String args[]) { (i) float - The type float specifies a single-precision return-type method-name2(parameter-list);
int x = 10; value that uses 32 bits of storage.Single precision is static final type varname1 = value;
do { faster on some processors and takes half as much static final type varname2 = value;
System.out.print("value of x : " + x ); space as double precision, but will become imprecise // ...
x++; when the values are either very large or very return-type method-nameN(parameter-list);
System.out.print("\n"); small.Variables of type float are useful when you need static final type varnameN = value; }
}while( x < 20 ); }} a fractional component, but don’t require a large Variables can be declared inside of interface
degree of precision.float hightemp, lowtemp; declarations. They are implicitly final and
iii)FOR STATEMENT - The for loop is another entry-controlled (ii) double - Double precision, as denoted by the static, meaning they cannot be changed by the
loop that provides a more concise loop control structure.A for double keyword, uses 64 bits to store a value.Double implementing class.
loop is a repetition control structure that allows you to precision is actually faster than single precision on They must also be initialized. All methods and
efficiently write a loop that needs to be executed a specific some modern processors that have been optimized for variables are implicitly public.
number of times. high-speed mathematical calculations.All IMPLEMENTING INTERFACE
Syntax: transcendental math functions, such as sin( ), cos( ), class classname [extends superclass] [implements
for(initialization; Boolean_expression or test_condition; and sqrt( ), return double values. When you need to interface1 ,interface2...] {
update) { maintain accuracy over many iterative calculations, or // class-body }
// body of loop are manipulating large-valued numbers, double is the The methods that implement an interface must be
} best choice. declared public.
3)Character - In Java, the data type used to store Also, the type signature of the implementing
EXAMPLE characters is char.Unicode defines a fully international method must match exactly the type signature
public class Test { character set that can represent all of the characters specified in the interface definition.
public static void main(String args[]) { found in all human languages. It is a unification of interface Callback {
for(int x = 10; x < 20; x = x + 1) { dozens of character sets, such as Latin, Greek, Arabic, void callback(int param); }
System.out.print("value of x : " + x ); Cyrillic, Hebrew, Katakana, Hangul, and many more.For class Client implements Callback {
System.out.print("\n"); }}} this purpose, it requires 16 bits.Thus, in Java char is a public void callback(int p) {
ADDITIONAL FEATURES OF FOR LOOP - More than one variable 16-bit type. The range of a char is 0 to 65,536. There System.out.println("callback called with " + p); }
can be initialized at a time in the for statement. are no negative chars.The standard set of characters void nonIfaceMeth() {
for(p=1,n=0;n<17;n++) known as ASCII still ranges from 0 to 127 as always, and System.out.println("Classes that implement
Update section can have more than one part. the extended 8-bit character set, ISO-Latin-1, ranges interfaces " + "may also define other members,
for(n=1,m=50;n<=m;n=n+1,m=m-1) from 0 to 255. too."); }}
Test condition may have compound relation and the testing 4)Booleans - Java has a primitive type, called boolean, class TestIface {
need not be limited only to the loop control variable. for logical values. Uses one bit of storage.It can have public static void main(String args[]) {
sum=0; only one of two possible values, true or false.This is the Callback c = new Client();
for(i=1;i<20&&sum<100;i++) type returned by all relational operators, as in the case c.callback(42); }}
Another unique aspect of for loop is that one or more sections of a < b. boolean is also the type required by the
can be omitted, if necessary. In such a case, the sections are conditional expressions that govern the control
left blank. However, the semicolons separating the section statements such as if and for.
must remain.
m=5; STATIC - The members that are declared static are
for(;m!=100;) METHOD OVERLOADING - In Java it is possible to called static members. Since these members are
{ define two or more methods within the same class that associated with the class itself rather than
System.out.println(m); share the same name, as long as their parameter individual objects, the static variables and static
m=m+5; } declarations are different. methods are associated with the class itself rather
If the test condition is not present, for statement set up an When this is the case, the methods are said to be than individual objects, they are often referred as
infinite loop.Time delay loops can be setup using the null overloaded, and the process is class variables and class methods.When a member
statement. referred to as method overloading.Method is declared static, it can be accessed before any
for(j=1000;j>0;j--); This loop executes 1000 times without overloading is one of the ways that Java supports objects of its class are created, and without
producing any output. It simple causes a time delay. polymorphism.When an overloaded method is reference to any object.Instance variables
invoked, Java uses the type and/or number of declared as static are, essentially, global variables.
ENHANCED FOR LOOP - The enhanced for loop also called for arguments as its guide to determine which version of When objects of its class are
each loop, is an extended language feature introduced with the overloaded method to declared, no copy of a static variable is made.
J2SE 5.0 release.This feature help us to retrieve the array of actually call.Thus, overloaded methods must differ in Instead, all instances of the class share the same
elements efficiently rather than using the array index.This the type and/or number of their static variable (i.e one copy).Methods declared as
feature eliminates the iterators in a for loop and to retrieve the parameters.When Java encounters a call to an static have several restrictions: They can only call
elements from a collection. overloaded method, it simply executes the other static methods.They must only access static
Syntax: version of the method whose parameters match the data.They cannot refer to this or super in any
for(type identifier : Expression) { arguments used in the call. way.static block that gets executed exactly once,
//statements } class OverloadDemo { when the class is first loaded.
Where, type represents the data type or object used; identifier void test() { class UseStatic {
refers to the name of a variable and expression is an instance of System.out.println("No parameters"); } static int a = 3;
the java.lang.Iterable interface or an array. void test(int a) { static int b;
Example: System.out.println("a: " + a); } static void meth(int x) {
int num[3]={56,48,79}; void test(int a, int b) { System.out.println("x = " + x);
for(int k=0;k<3;k++) => for(int k : num) { System.out.println("a and b: " + a + " " + b); } System.out.println("a = " + a);
…… } double test(double a) { System.out.println("b = " + b); }
System.out.println("double a: " + a); static {
public class Test { return a*a; }} System.out.println("Static block initialized.");
public static void main(String args[]) { class Overload { b = a * 4; }
int [] numbers = {10, 20, 30, 40, 50}; public static void main(String args[]) { public static void main(String args[]) {
for(int x : numbers ) { OverloadDemo ob = new OverloadDemo(); meth(42); }}
System.out.print( x ); double result;
System.out.print(","); } ob.test();
System.out.print("\n"); ob.test(10);
String [] names = {"James", "Larry", "Tom", "Lacy"}; ob.test(10, 20);
for( String name : names ) { result = ob.test(123.25); ABSTRACT CLASSES - define a superclass that
System.out.print( name ); System.out.println("Result of ob.test(123.25): "+ declares the structure of a given abstraction
System.out.print(","); } result); }} without providing a complete implementation of
every method.That is, sometimes you will want to
METHOD OVERRIDING - In a class hierarchy, when create a superclass that only defines a generalized
CONSTRUCTOR OVERLOADING - class Box { a method in a subclass has the same name form that will be shared by all of its subclasses,
double width; and type signature as a method in its superclass, leaving it to each subclass to fill in the details.You
double height; then the method in can require that certain methods be overridden by
double depth; the subclass is said to override the method in the subclasses by specifying the abstract type
Box(double w, double h, double d) { superclass.When an overridden method is called modifier. These methods are sometimes referred to
width = w; from within a subclass, it will as subclasser responsibility because they have no
height = h; always refer to the version of that method defined implementation specified in the
depth = d; } by the subclass.The version of the method defined superclass.abstract type name(parameter-list);
Box() { by the superclass will be hidden. Any class that contains one or more abstract
width = -1; class A { methods must also be declared abstract.There can
height = -1; int i, j; be no objects of an abstract class.you cannot
depth = -1; } A(int a, int b) { declare abstract constructors, or abstract static
Box(double len) { i = a; methods.Any subclass of an abstract class must
width = height = depth = len; } j = b; } either implement all of the abstract methods in the
double volume() { void show() { superclass, or be itself declared abstract.
return width * height * depth; }} System.out.println("i and j: " + i + " " + j); }} abstract class A {
class OverloadCons { class B extends A { abstract void callme();
public static void main(String args[]) { int k; void callmetoo() {
Box mybox1 = new Box(10, 20, 15); B(int a, int b, int c) { System.out.println("This is a concrete method."); }}
Box mybox2 = new Box(); super(a, b); class B extends A {
Box mycube = new Box(7); k = c; } void callme() {
double vol; void show() { System.out.println("B's implementation of
vol = mybox1.volume(); System.out.println("k: " + k); }} callme."); }}
System.out.println("Volume of mybox1 is " + vol); class Override { class AbstractDemo {
vol = mybox2.volume(); public static void main(String args[]) { public static void main(String args[]) {
System.out.println("Volume of mybox2 is " + vol); B subOb = new B(1, 2, 3); B b = new B();
vol = mycube.volume(); subOb.show(); }} b.callme();
System.out.println("Volume of mycube is " + vol); }} Here, super.show( ) calls the superclass version of b.callmetoo(); }}
show( ).
Packages SWINGS
• Containers for classes used to keep the class MAJOR COMPONENTSOF JDBC • Swing is a set of classes that provides more
name space compartmentalized. • Packages Application powerful and flexible components such as
are stored in a hierarchical manner and are Applications in JDBC architecture are buttons, checkboxes, labels etc. • For example a
explicitly imported into new class definitions. 1. java applications like applets or servlet button may have both an image and a text string
Java API packages 2. User defined packages 2 that communicates with databases. associated with it
September 2021 21 Java API Packages • JDBC API Components of SWING
The JDBC API is an Application -J-LABEL--Swing labels are instances of the
Provides a large number of classes grouped
Programming Interface used to create JLabel class. It can display text and icon. •
into different packages. 1. java.lang – include Constructors for JLabel --*JLabel(Icon i)
classes for primitive types, mathematical Databases. JDBC API uses classes and
interfaces to connect with databases. *JLabel(String s)
functions, threads, exceptions etc. 2. java.util – - JTextField -- • Swing version of TextField. •
DriverManager
consists of language utility classes such as Constructors for JTextField *JTextField()
DriverManager class in the JDBC
date, time, hashtables etc. architecture is used to establish a *JTextField(int cols)
User defined Packages 1. Declare the package connection between java applications - JTextArea __• Swing version of TextArea. •
at the beginning of the program using the form and databases Constructors for JTextArea * JTextArea()-
package pkg1[.pkg2[.pkg3]]; 2. Define the class JDBC Drivers Constructs a new TextArea. * JTextArea(int rows,
that is to be put in the package and declare it JDBC drivers are used to connecting with int columns)-Constructs a new empty TextArea
public. 3. Create a subdirectory under the data sources. All databases like Oracle, - JButton• Swing version of Button. More powerful
directory where the main source files are MSSQL, MYSQL, etc. have their drivers, to than buttons in AWT. • For example, we can place
stored. 4. Store the file as classname.java in the connect with these databases we need to an icon on the swing button. • Constructors for
subdirectory created. 5. Compile the file. This load their specific drivers. JButton * JButton(Icon i) *JButton(String s)
creates the .class file in the subdirectory Class.forName() method is used to load - JCheckBox • Swing version of Checkbox. • It has
drivers in JDBC architecture two states either checked or unchecked. •
Data Sources Constructors for JCheckBox *JCheckBox(Icon i)
Exception Handling Data Sources in the JDBC architecture * JCheckBox(String S)
• Exception is an abnormal condition caused by are the databases that we can connect - JRadioButton 2 September 2021 60 • Swing
a runtime error in the program. • Example using this API. These are the sources version of RadioButton. • The button has only two
division by zero. STEPS:::1. Find the problem where data is stored and used by Java states • Constructors for JRadioButton
(Hit the Exception) 2. Inform that an error has applications * JRadioButton(Icon i) * JRadioButton(String s)
occurred (Throws the exception) 3. Receive the . - JComboBox • Swing version of Combo box. • A
error information(Catch the exception) 4. Take ARCHITECTURE combo box normally displays one entry. • It also
corrective actions (Handle the Exception) There are two architectures of JDBC displays a drop-down list that allows a user to
Exception Types 1. ArithmeticException – 2-tier JDBC architecture model is a basic select a different item. • Constructorfor JComBox
caused by mathematical errors such as division model. in this model, a java application * JComboBox() * JComboBox(Vector v)
by zero. 2. ArrayIndexOutOfBoundsException – communicates directly to the data sources. - JList • Swing version of List. • Displays a list of
caused by wrong array indices. This model is also known as client/server objects and allows the user to select one or more
3. ArrayStoreException – caused when a 3-tier model items. • JList allows the user to select multiple
program tries to store the wrong type of data in In this model the user queries are sent to the ranges of items within the list.• Constructors for
an array. 4. FileNotFoundException – caused middle tier and then they are executed on JList *JList()-Constructs a JList with an empty,
by an attempt to access a non-existent file. the data source. read-only, model.
5. IOException – caused by general I/O failures Java application is considered as one tier * JList(Object[] listData)- Constructs a JList that
such as inability to read from a file. connected to the data source displays the elements in the specified array.
6. StringIndexOutOfBoundsException – caused In this model user queries are sent to the - JFrame • Swing version of Frame. • Top-level
when a program attempts to access a non data source using middle-tier services, window with a title and a border. • Constructors
existent character position in a string. Steps to connect using JDBC API. for JFrame *JFrame()-Constructs a new frame
Exception Handling methods – 1. Load Driver: Load JDBC Driver for specific that is initially invisible. *JFrame(String title)-
try and catch databases using forName() method of class Creates a new, initially invisible Frame with the
SYNTAX--try{ statement; } catch(Exception e) Class. Syntax: specified title. Architecture of JDBC
{statement; } Class.forName("com.mysql.jdbc.Driver") - JPanel • Swing version of Panel. • A Container is
Try is to prepare a block of code that is likely to 2. Create Connection: Create a connection a component that can contain other SWING
cause an error condition and throw an with a database using DriverManager class. components. • A container provides a space
exception. – try and catch • Catch block catches Database credentials are to be passed while where a component can be located
the exception thrown by the try block. • Try establishing the connection. Syntax: • Constructors for JPanel * JPanel()-Creates a
block can have one or more statements that DriverManager.getConnection() new JPanel with a flow layout.
could generate an exception. • If any one 3. Create Query: To manipulate the * JPanel(LayoutManager layout)
statement generates an exception, the database we need to create a query using Layout Managers • A Layout Manager
remaining statements are skipped and commands like INSERT, UPDATE, DELETE, automatically arranges the controls within a
execution jumps to the catch block that is etc. These queries are created and stored in window.
placed next to the try block.– try and catch • string format. Syntax: String sql_query = 1. Flow Layout--• Default layout manager •
Catch block can have one or more statements. • "INSERT INTO Student(name, roll_no) Components are laid from upper left corner, left
If the catch parameter matches with the type values('ABC','XYZ')" to right and top to bottom. Constructors 1.
of exception object, then the exception is 4. Create Statement: To perform the FlowLayout() – creates a default layout which
caught and statements in the catch block will operations in the string on a database we centers components and leaves five pixels of
be executed. • Every try statement should be need to fire query on the database. To space between each component. 2.
followed by at least one catch statement. achieve this we need to convert a string FlowLayout(int how) – Specify how each line is
Other exception handling techniques object into SQL statements. This can be done aligned.
are*mutliple catch using createStatement() and 2. Border Layout-- • Implements a common
*nested try *finally *throw and throw prepareStatement() interfaces. Syntax: layout style for top-level windows. • Four sides are
Statement St = con.createStatement(); referred to as north, south, east and west. •
Multithreading 5. Execute Statement: To execute SQL Middle area is called the center. Constructors 1.
• A concept in which the programs are divided statements on the database we can use two BorderLayout() – creates a default layout. 2.
into two or more processes which can be run in methods depending on which type of query BorderLayout(int horz, int vert)
parallel. In a multithreaded environment, CPU we are executing. Execute Update: Execute 3. Grid Layout --• Lays out components in a two-
can perform other computational tasks when it update method is used to execute queries dimensional grid.• numRows or numColumns can
waits for the I/O.Life Cycle of a Thread 1. like insert, update, delete, etc be zero. Constructors 1. GridLayout() – creates a
Newborn State 2. Runnable State 3. Running 2--Execute Query: Execute query method is single-column grid layout. 2. GridLayout(int
State 4. Blocked State 5. Dead State used to execute queries used to display data numRows, int numColumns) – creates a grid
• Newborn State – When we create a thread, it is from the database, such as select layout
in the new born state. 1. Schedule it for running 6. Closing Statement: After performing 4. Card Layout-- • Unique among other layout
using start() method. 2. Kill it using stop() operations on the database, it is better to managers in that it stores several different
method.. • Runnable State – This state means close every interface object to avoid further layouts. • Each layout can be thought of as a
the thread is ready for execution and is waiting conflicts. Synatx: con.close(); separate index card in a deck that can be
for the availability of the processor. • These shuffled so that any card is on top at a given
threads are executed in a FIFO manner time.Constructors 1. CardLayout() – creates a
• This process of assigning time to threads is default card layout 2. CardLayout(int horz, int
known as time slicing.• Running State – the vert)- specify the horizontal and vertical space
processor has given its time to the thread for between the components.
execution. • A running thread may relinquish its 5. Box Layout--• The BoxLayout is used to arrange
control in one of the following situations.me to the components either vertically or horizontally. •
threads is known as time slicing. For this purpose, BoxLayout provides four
• Blocked State – When a thread is prevented constants. They are X_AXIS, Y_AXIS, LINE_AXIS
from entering into the runnable state and and PAGE_AXIS. 6. Null Layout -• Rather than
subsequently the running state. • Happens using a layout manager that controls the size and
when the thread is suspended, sleep or in wait position of all components in a container, we can
state.• Dead State – Kill the thread using the set the layout manager to null. • Each component
stop() method. then controls its own position and size using its
bounds.
Applets
• Small Java programs that can be downloaded
and executed in a Java enabled Web browser. •
Transported via internet.• Perform arithmetic Event Class
operations, display graphics, play sounds, 1. ActionEvent - Generated when a button is
create animations, play interactive games etc. • pressed, a list item is double-clicked or a menu
Two types of applets 1. Local applet 2. Remote item is selected. 2. AdjustmentEvent – Generated
applet.• Applet developed locally and stored in when a scroll bar is manipulated.
a local system is known as local applet.• 3. ComponentEvent – Generated when a
Remote applet is developed by someone else component is hidden, moved, resized or becomes
and stored on a remote computer. Building visible. 4. ContainerEvent – Generated when a
applet code • Two classes Applet and Graphics component is added or removed.
needs to be imported. • The Applet class is 5. FocusEvent – Generated when a component
contained in the java.applet package. gains or loses keyboard focus. 6. InputEvent –
Life Cycle of an Applet Abstract super class for all component input
• init() – this method is called first. This is where event classes. 7. ItemEvent - Generated when a
we should initialize variables. • start() – this checkbox or list item is clicked. Also occurs when
method is called after init(). This is also called a choice selection is made or a checkable menu
after an applet has been stopped. • paint() – item is selected or deselected. KeyEvent –
This method is called each time the applet is Generated when input is received from the
damaged. If any other window covers the keyboard. 9. MouseEvent – Generated when the
applet, the window system calls paint() mouse is dragged, moved, clicked, pressed or
method. • update() – The default update released. Also generated when the mouse enters
method in class Applet first fills an applet with or exits a component. 10.TextEvent – Generated
default background color and then calls paint(). when the value of a text area or text field is
• stop() – This method is called when a Web changed. 11.WindowEvent – Generated when a
browser leaves the HTML document containing window is activated, closed, deactivated,
the applet. When the user returns to the page deiconified, iconified, opened or quit
applets are restarted using start() method. •
destroy() – This method is called when the
runtime environment determines that the AWT: Frame Class • The Frame class is derived
applet needs to be removed completely from from the base class Window. • Constructors 1.
memory. • repaint() – Calling repaint() in turn Frame() - Creates a standard window that does
calls update() method. PROGRAM not contain a title. 2. Frame(String title) – Creates
import java.applet.*; a standard window with the title specified by time
import java.awt.*; public class HelloJavaParam • We cannot specify the dimensions of the
extends Applet{ String str; public void init() window. Instead we must set the size of the
{str=getParameter("string"); if(str ==null) window after it has been created. • setSize() – this
str="Java"; str="Hello"+str;} method is used to set the dimensions of the
public void paint(Graphics g) { window.• Hiding and Showing a Window – After a
g.drawString(str,10,100);}} <html> frame window has been created, it will not be
<applet code="HelloJavaParam.class" visible until we call setVisible().• Setting a
width=200 height=200> <param name="string" Window’s Title – We can change the title in a
value="applet!"> </applet> </html> frame window using setTitle(). AWT Controls 1.
Label 2. Button 3. Checkbox 4. Choice 5. List 6.
TextField 7. TextArea
Java Data Base Connectivity-JDBC
Java Database Connectivity (JDBC) is an
Application Programming Interface (API), from
Sun microsystem that is used by the Java
application to communicate with the relational
databases from different vendors.
Design of JDBC defines the components of
JDBC, which is used for connecting to the
database.
COMPONENTS OF JDBC
JDBC API provides two different packages
to connect with different databases.
JDBC Driver Manager
JDBC DriverManager is a class in JDBC API
that loads a database-specific driver in
Java application and establishes a
connection with a database.
JDBC Test Suite
JDBC Test Suite is used to test operations
being performed on databases using JDBC
drivers. JDBC Test Suite tests operations
such as insertion, updating, and deletion.
JDBC-ODBC Bridge Drivers
These are used to translate JDBC methods
to ODBC function calls. JDBC-ODBC Bridge
Drivers are used to connect database
drivers to the database.