0% found this document useful (0 votes)
4 views2 pages

Java JDBC, Applets, Threads, Exceptions

The document provides an overview of various Java concepts including JDBC, Java Applets, multithreading, exception handling, and string manipulation. It explains the functionalities of JDBC for database connectivity, the lifecycle of applets, and the principles of object-oriented programming such as polymorphism, inheritance, and encapsulation. Additionally, it discusses Java's features like portability, security, and the role of the Java Virtual Machine (JVM).

Uploaded by

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

Java JDBC, Applets, Threads, Exceptions

The document provides an overview of various Java concepts including JDBC, Java Applets, multithreading, exception handling, and string manipulation. It explains the functionalities of JDBC for database connectivity, the lifecycle of applets, and the principles of object-oriented programming such as polymorphism, inheritance, and encapsulation. Additionally, it discusses Java's features like portability, security, and the role of the Java Virtual Machine (JVM).

Uploaded by

amishakumari9649
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JDBC stands for Java Java Applet is a special type of Multithreading in Java is a process of executing Exception Handling in Java

ng Exception Handling in Java is one of the powerful Java String : It is basically an object that represents sequence
Database Connectivity. JDBC program that is embedded in the multiple threads simultaneously. A thread is a mechanism to handle the runtime errors such as of char values. An array of characters works same as Java
is a Java API to connect and webpage to generate the dynamic lightweight sub-process, the smallest unit of ClassNotFoundException, IOException etc, so that the string. Java String class provides a lot of methods to perform
execute the query with the content. It runs inside the browser and processing. Multiprocessing and multithreading, normal flow of the application can be maintained. An operations on strings such as compare(), concat(), equals(),
database. JDBC API uses works at client side. both are used to achieve multitasking. exception is an event that disrupts the normal flow of the split(), length(), replace(), compareTo(), intern(), substring() etc.
JDBC drivers to connect with Advantages: (1) It works at client side Advantages: (1) It doesn't block the user because program. It is an object which is thrown at runtime. There There are two ways to create String object:
the database. There are four so less response time. (2) Secured. (3) threads are independent and you can perform are mainly two types of exceptions: (1) Checked (2) 1. By string literal -> String s="welcome";
types of JDBC drivers: It can be executed by browsers running multiple operations at the same time. (2) We can Unchecked. 2. By new keyword -> String s=new String("Welcome");
JDBC-ODBC Bridge Driver under many platforms, including Linux, perform many operations together, so it saves time. Checked Exception : The classes that directly inherit the String StringBuffer
Native Driver Windows, Mac Os etc. (3) Threads are independent, so it doesn't affect Throwable class except RuntimeException and Error are
Network Protocol Driver Drawback: Plugin is required at client other threads if an exception occurs in a single known as checked exceptions. It is immutable. It is mutable.
Thin Driver browser to execute applet. thread. Unchecked Exception : The classes that inherit the It is slow and consumes It is is fast and consumes
Lifecycle of Java Applet Threads can be created by using two mechanisms : RuntimeException are known as unchecked exceptions. more memory when we less memory when we
(1) Applet is initialized. (2) Applet is 1. Extending the Thread class Java provides five keywords that are used to handle the concatenate too many concatenate strings.
started. (3) Applet is painted. (4) 2. Implementing the Runnable Interface exception. strings because every time
Applet is stopped. (5) Applet is Life cycle of a Thread : A thread always exists in try : The "try" keyword is used to specify a block where we it creates new instance.
destroyed. any one of the following states. These states are: should place an exception code. The try block must be String class overrides the StringBuffer class doesn't
We can use JDBC API to For creating any applet (1) New: Whenever a new thread is created, it is followed by either catch or finally. equals() method of Object override the equals()
access tabular data stored in [Link] class must be always in the new state. For a thread in the new catch : The "catch" block is used to handle the exception. It class. So we can compare method of Object class.
any relational database. By inherited. It provides 4 life cycle state, the code has not been run yet and thus has must be preceded by try block. It can be followed by finally the contents of two strings
the help of JDBC API, we can methods of applet. not begun its execution. block later. by equals() method.
save, update, delete and fetch 1. public void init(): is used to (2) Active: When a thread invokes the start() finally : The "finally" block is used to execute the necessary String class is slower while StringBuffer class is
data from the database. The initialized the Applet. It is invoked method, it moves from the new state to the active code of the program. It is executed whether an exception is performing concatenation faster while performing
[Link] package contains only once. state. The active state contains two states within it: handled or not. operation. concatenation operation.
classes and interfaces for 2. public void start(): is invoked after one is runnable, and the other is running. throw : The "throw" keyword is used to throw an exception. String class uses String StringBuffer uses Heap
JDBC API. the init() method or browser is (3) Blocked or Waiting: Whenever a thread is throws : The "throws" keyword is used to declare constant pool. memory
JDBC Driver is a software maximized. It is used to start the inactive for a span of time (not permanently) then, exceptions. It specifies that there may occur an exception
component that enables java Applet. either the thread is in the blocked state or is in the in the method. It doesn't throw an exception. It is always Java Swing tutorial is a part of Java Foundation Classes (JFC)
application to interact with 3. public void stop(): is used to stop waiting state. used with method signature. that is used to create window-based applications. It is built on
the database. There are 4 the Applet. It is invoked when (4) Timed Waiting: The sleep() method puts the Program: Output: the top of AWT (Abstract Windowing Toolkit) API and entirely
types of JDBC drivers: Applet is stop or browser is thread in the timed wait state. After the time runs public class JavaExceptionExample { Exception in thread main written in java. Unlike AWT, Java Swing provides platform-
public static void main(String args[]) { [Link]:/ by
1. JDBC-ODBC bridge driver minimized. out, the thread wakes up and start its execution try{ zero independent and lightweight components. The [Link]
2. Native-API driver 4. public void destroy(): is used to from when it has left earlier. int data=100/0; } rest of the code... package provides classes for java swing API such as JButton,
catch(ArithmeticException e {
3. Network Protocol driver destroy the Applet. It is invoked (5) Terminated: A terminated thread means the [Link](e); } JTextField, JTextArea, JRadioButton, JCheckbox, JMenu,
4. Thin driver only once. thread is no more in the system. [Link]("rest of the code..."); } } JColorChooser.

Polymorphism : If one task is performed in different Abstract class : Abstraction is a process of hiding the implementation Features of Java : The primary objective JVM : Java Virtual Machine is an Java OOPs Concepts
ways, it is known as polymorphism. In Java, we use details and showing only functionality to the user. A class which is of Java programming language creation abstract machine. It is called a virtual Object : An Object can be defined as an
method overloading and method overriding to declared as abstract is known as an abstract class. It can have was to make it portable, simple and machine because it doesn't physically instance of a class. An object contains
achieve polymorphism. abstract and non-abstract methods. It needs to be extended and its secure programming language. exist. It is a specification that provides an address and takes up some space in
Method Overloading : If a class has multiple method implemented. It cannot be instantiated. An abstract class must Simple : Java is very easy to learn, and a runtime environment in which Java memory.
methods having same name but different in be declared with an abstract keyword. its syntax is simple, clean and easy to bytecode can be executed. It can also Class : Class is a blueprint from which
parameters. There are two ways to overload the Program : understand. run those programs which are written you can create an individual object. Class
method in java : (1) By changing number of abstract class Bike{ Garbage Collection is process of Object Oriented : Java is an object- in other languages and compiled to doesn't consume any space.
arguments (2) By changing the data type abstract void run(); reclaiming the runtime unused memory oriented programming language. Java bytecode. The JVM performs the Inheritance : It is a mechanism in which
Program : } automatically. In other words, it is a way Everything in Java is an object. Basic following main tasks: (1)Loads code one object acquires all the properties and
class Adder{ class Honda4 extends Bike{ to destroy the concepts of OOPs are: Object, Class, (2)Verifies code (3)Executes code behaviors of a parent object. The idea
static int add(int a,int b){return a+b;} void run(){[Link]("running safely");} unused objects. Inheritance, Polymorphism, Abstraction, (4)Provides runtime environment behind inheritance in Java is that we can
static int add(int a,int b,int c){return a+b+c;} public static void main(String args[]){ Advantages : Encapsulation. create new classes that are built upon
} Bike obj = new Honda4(); It makes java Platform Independent : Java is platform JRE : Java Runtime Environment is a existing classes. When we inherit from an
class TestOverloading1{ Output : [Link](); memory independent because it is different from set of software tools which are used existing class, you can reuse methods
public static void main(String[] args){ 22 }} Output : running safely efficient. other languages like C, C++, etc. which for developing Java applications. It is and fields of the parent class. Moreover,
[Link]([Link](11,11)); 23 are compiled into platform specific used to provide the runtime you can add new methods and fields in
[Link]([Link](11,11,11)); An Interface in Java is a blueprint of a class. It has static constants machines while Java is a write once, run environment. It is the implementation your current class also. Inheritance
}} and abstract methods. It is a mechanism to achieve abstraction. There anywhere language. of JVM. It physically exists. It contains represents the IS-A relationship which is
Method Overriding : If subclass has the same can be only abstract methods in the Java interface, not method body. Secured : Java is best known for its a set of libraries + other files that JVM also known as a parent-childrelationship.
method as declared in the parent class, it is known An interface is declared by using the interface keyword. It provides security. With Java, we can develop uses at runtime. The extends keyword indicates that we
as method overriding. Rules for Java Method total abstraction; means all the methods in an interface are declared virus-free systems. are making a new class that derives from
Overriding : (1) The method must have the same with the empty body, and all the fields are public, static and final by Robust : It uses strong memory JDK : Java Development Kit. is a an existing class. Types of inheritance in
name as in the parent class. (2) The method must default. A class that implements an interface must implement all the management. software development environment java are :
have the same parameter as in the parent class. (3) methods declared in the interface. Portable : Java is portable because it which is used to develop Java 1. Single inheritance : Subclasses
There must be an IS-A relationship (inheritance). Program : Types of Operators : Unary Operator, facilitates you to carry the Java bytecode applications and applets. It physically inherit the features of one
Program : interface printable{ Arithmetic Operator, Shift Operator, Relational to any platform. exists. It contains JRE + development superclass.
class Vehicle{ void print(); Operator, Bitwise Operator, Logical Operator, Distributed : Java is distributed because tools. The JDK contains a private Java 2. Multilevel Inheritance : A derived
void run(){[Link]("Vehicle is running");} } Ternary Operator it facilitates users to create distributed Virtual Machine (JVM) and a few other class will be inheriting a base class,
} class MyClass implements printable{ and Assignment applications in Java. resources such as an and as well as the derived class also
class Bike extends Vehicle{ public void print(){[Link]("Hello");} Operator. Multi-threaded : A thread is like a interpreter/loader (java), a compiler acts as the base class for other
public static void main(String args[]){ public static void main(String args[]){ separate program, executing (javac), an archiver (jar), a classes.
Bike obj = new Bike(); MyClass obj = new MyClass(); concurrently. documentation generator (Javadoc), 3. Hierarchical Inheritance : One class
[Link](); [Link](); Dynamic : Java is a dynamic language. It etc. to complete the development of a serves as a superclass (base class)
} } Output : Vehicle is running }} Output : hello supports the dynamic loading of classes. Java Application. for more than one subclass.

Constructor : In Java, a constructor is a block of static keyword : In Java, it is used for memory management mainly. We Access modifiers : In Java, it specifies the accessibility or scope of a field, Encapsulation in Java is a process of wrapping
codes similar to the method. It is called when an can apply static keyword with variables, methods, blocks and nested method, constructor, or class. We can change the access level of fields, code and data together into a single unit, for
instance of the class is created. At the time of classes. The static keyword belongs to the class than an instance of constructors, methods, and class by applying the access modifier on it. example, a capsule which is mixed of several
calling constructor, memory for the object is the class. There are four types of Java access modifiers: medicines. We can create a fully encapsulated
allocated in the memory. It is a special type of Program : The super keyword in Java is a 1. Private: The access level of a private modifier is only within the class. class in Java by making all the data members of
method which is used to initialize the object. Every class Student{ reference variable which is used to It cannot be accessed from outside the class. the class private. Now we can use setter and
time an object is created using the new() keyword, at int rollno; refer immediate parent class object. 2. Default: The access level of a default modifier is only within the getter methods to set and get the data in it.
least one constructor is called. It calls a default String name; Whenever we create the instance of package. It cannot be accessed from outside the package. If you do Advantages :
constructor if there is no constructor available in the static String college ="PU"; subclass, an instance of parent class is not specify any access level, it will be the default. 1. By providing only a setter or getter method,
class. In such case, Java compiler provides a Student(int r, String n){ created implicitly which is referred by 3. Protected: The access level of a protected modifier is within the we can make the class read-only or write-
default constructor by default. rollno = r; super reference variable. super can be package and outside the package through child class. If you do not only.
Rules for creating Java constructor : (1)Constructor name = n; used to refer immediate parent class make the child class, it cannot be accessed from outside the package. 2. It provides you the control over the data.
name must be the same as its class name. } instance variable, method & constructor 4. Public: The access level of a public modifier is everywhere. It can be 3. It is a way to achieve data hiding.
(2)Constructor must have no explicit return type. void display (){ accessed from within the class, outside the class, within the package 4. The encapsulate class is easy to test.
(3)Java constructor cannot be abstract, static, final, [Link](rollno+" "+name+" "+college); and outside the package.
and synchronized. }} Command Line Argument is an argument i.e. passed at the time of
There are two types of constructors in Java: public class TestStaticVariable1{ final keyword in java is used Stream : Java provides a new additional package in running the java program. The arguments passed from the console can
(1)Default constructor (2)Parameterized constructor public static void main(String args[]){ to restrict the user. The java Java 8 called [Link]. This package be received in the java program and it can be used as an input. Program
Default Constructor Program : Student s1 = new Student(111,"Abc"); final keyword can be used in consists of classes, interfaces and enum to allows class CommandLineExample{
class Bike1{ Student s2 = new Student(222,"Xyz"); many context. Final can be functional-style operations on the elements. You public static void main(String args[]){
Bike1(){[Link]("Bike is created"); [Link](); variable, method or class. It can use stream by importing [Link] [Link]("Your first argument is: "+args[0]);
} [Link](); can be used to : package. }}
Output : 111 Abc PU Stop Value Change Stream provides following features: compile by > javac [Link]
public static void main(String args[]){ }} run by > java CommandLineExample hello
Bike1 b=new Bike1(); 222 Xyz PU Stop Method Overridding Stream does not store elements. It simply Output : Your first argument is: hello
Output : Bike is created Stop Inheritance conveys elements from a source such as a data
}}
Parameterized Constructor Program : structure, an array, or an I/O channel, through a
class Student{ Package : In java, it is a group of similar types of classes, interfaces and sub- pipeline of computational operations.
String name; packages. It can be categorized in two form, built-in package and user- Stream is functional in nature. Operations
Student(String n){ defined package. There are many built-in packages such as java, lang, awt, performed on a stream does not modify it's
name = n; javax, swing, net, io, util, sql etc. source.
} Advantages : (1) Java package is used to categorize the classes and Stream is lazy and evaluates code only when
void display(){[Link](name);} interfaces so that they can be easily maintained. (2) Java package provides required.
public static void main(String args[]){ access protection. (3) Java package removes naming collision. The elements of a stream are only visited once
Student s = new Student("ABC"); There are three ways to access the package from outside the package. during the life of a stream. Like an Iterator, a
[Link](); (1) import package.*; (2) import [Link]; (3) fully qualified name. new stream must be generated to revisit the
}} Output : ABC same elements of the source.
JDBC stands for Java Java Applet is a special type of Multithreading in Java is a process of executing Exception Handling in Java is one of the powerful Java String : It is basically an object that represents sequence
Database Connectivity. JDBC program that is embedded in the multiple threads simultaneously. A thread is a mechanism to handle the runtime errors such as of char values. An array of characters works same as Java
is a Java API to connect and webpage to generate the dynamic lightweight sub-process, the smallest unit of ClassNotFoundException, IOException etc, so that the string. Java String class provides a lot of methods to perform
execute the query with the content. It runs inside the browser and processing. Multiprocessing and multithreading, normal flow of the application can be maintained. An operations on strings such as compare(), concat(), equals(),
database. JDBC API uses works at client side. both are used to achieve multitasking. exception is an event that disrupts the normal flow of the split(), length(), replace(), compareTo(), intern(), substring() etc.
JDBC drivers to connect with Advantages: (1) It works at client side Advantages: (1) It doesn't block the user because program. It is an object which is thrown at runtime. There There are two ways to create String object:
the database. There are four so less response time. (2) Secured. (3) threads are independent and you can perform are mainly two types of exceptions: (1) Checked (2) 1. By string literal -> String s="welcome";
types of JDBC drivers: It can be executed by browsers running multiple operations at the same time. (2) We can Unchecked. 2. By new keyword -> String s=new String("Welcome");
JDBC-ODBC Bridge Driver under many platforms, including Linux, perform many operations together, so it saves time. Checked Exception : The classes that directly inherit the String StringBuffer
Native Driver Windows, Mac Os etc. (3) Threads are independent, so it doesn't affect Throwable class except RuntimeException and Error are
Network Protocol Driver Drawback: Plugin is required at client other threads if an exception occurs in a single known as checked exceptions. It is immutable. It is mutable.
Thin Driver browser to execute applet. thread. Unchecked Exception : The classes that inherit the It is slow and consumes It is is fast and consumes
Lifecycle of Java Applet Threads can be created by using two mechanisms : RuntimeException are known as unchecked exceptions. more memory when we less memory when we
(1) Applet is initialized. (2) Applet is 1. Extending the Thread class Java provides five keywords that are used to handle the concatenate too many concatenate strings.
started. (3) Applet is painted. (4) 2. Implementing the Runnable Interface exception. strings because every time
Applet is stopped. (5) Applet is Life cycle of a Thread : A thread always exists in try : The "try" keyword is used to specify a block where we it creates new instance.
destroyed. any one of the following states. These states are: should place an exception code. The try block must be String class overrides the StringBuffer class doesn't
We can use JDBC API to For creating any applet (1) New: Whenever a new thread is created, it is followed by either catch or finally. equals() method of Object override the equals()
access tabular data stored in [Link] class must be always in the new state. For a thread in the new catch : The "catch" block is used to handle the exception. It class. So we can compare method of Object class.
any relational database. By inherited. It provides 4 life cycle state, the code has not been run yet and thus has must be preceded by try block. It can be followed by finally the contents of two strings
the help of JDBC API, we can methods of applet. not begun its execution. block later. by equals() method.
save, update, delete and fetch 1. public void init(): is used to (2) Active: When a thread invokes the start() finally : The "finally" block is used to execute the necessary String class is slower while StringBuffer class is
data from the database. The initialized the Applet. It is invoked method, it moves from the new state to the active code of the program. It is executed whether an exception is performing concatenation faster while performing
[Link] package contains only once. state. The active state contains two states within it: handled or not. operation. concatenation operation.
classes and interfaces for 2. public void start(): is invoked after one is runnable, and the other is running. throw : The "throw" keyword is used to throw an exception. String class uses String StringBuffer uses Heap
JDBC API. the init() method or browser is (3) Blocked or Waiting: Whenever a thread is throws : The "throws" keyword is used to declare constant pool. memory
JDBC Driver is a software maximized. It is used to start the inactive for a span of time (not permanently) then, exceptions. It specifies that there may occur an exception
component that enables java Applet. either the thread is in the blocked state or is in the in the method. It doesn't throw an exception. It is always Java Swing tutorial is a part of Java Foundation Classes (JFC)
application to interact with 3. public void stop(): is used to stop waiting state. used with method signature. that is used to create window-based applications. It is built on
the database. There are 4 the Applet. It is invoked when (4) Timed Waiting: The sleep() method puts the Program: Output: the top of AWT (Abstract Windowing Toolkit) API and entirely
types of JDBC drivers: Applet is stop or browser is thread in the timed wait state. After the time runs public class JavaExceptionExample { Exception in thread main written in java. Unlike AWT, Java Swing provides platform-
public static void main(String args[]) { [Link]:/ by
1. JDBC-ODBC bridge driver minimized. out, the thread wakes up and start its execution try{ zero independent and lightweight components. The [Link]
2. Native-API driver 4. public void destroy(): is used to from when it has left earlier. int data=100/0; } rest of the code... package provides classes for java swing API such as JButton,
catch(ArithmeticException e {
3. Network Protocol driver destroy the Applet. It is invoked (5) Terminated: A terminated thread means the [Link](e); } JTextField, JTextArea, JRadioButton, JCheckbox, JMenu,
4. Thin driver only once. thread is no more in the system. [Link]("rest of the code..."); } } JColorChooser.
JDBC stands for Java Java Applet is a special type of Multithreading in Java is a process of executing Exception Handling in Java is one of the powerful Java String : It is basically an object that represents sequence
Database Connectivity. JDBC program that is embedded in the multiple threads simultaneously. A thread is a mechanism to handle the runtime errors such as of char values. An array of characters works same as Java
is a Java API to connect and webpage to generate the dynamic lightweight sub-process, the smallest unit of ClassNotFoundException, IOException etc, so that the string. Java String class provides a lot of methods to perform
execute the query with the content. It runs inside the browser and processing. Multiprocessing and multithreading, normal flow of the application can be maintained. An operations on strings such as compare(), concat(), equals(),
database. JDBC API uses works at client side. both are used to achieve multitasking. exception is an event that disrupts the normal flow of the split(), length(), replace(), compareTo(), intern(), substring() etc.
JDBC drivers to connect with Advantages: (1) It works at client side Advantages: (1) It doesn't block the user because program. It is an object which is thrown at runtime. There There are two ways to create String object:
the database. There are four so less response time. (2) Secured. (3) threads are independent and you can perform are mainly two types of exceptions: (1) Checked (2) 1. By string literal -> String s="welcome";
types of JDBC drivers: It can be executed by browsers running multiple operations at the same time. (2) We can Unchecked. 2. By new keyword -> String s=new String("Welcome");
JDBC-ODBC Bridge Driver under many platforms, including Linux, perform many operations together, so it saves time. Checked Exception : The classes that directly inherit the String StringBuffer
Native Driver Windows, Mac Os etc. (3) Threads are independent, so it doesn't affect Throwable class except RuntimeException and Error are
Network Protocol Driver Drawback: Plugin is required at client other threads if an exception occurs in a single known as checked exceptions. It is immutable. It is mutable.
Thin Driver browser to execute applet. thread. Unchecked Exception : The classes that inherit the It is slow and consumes It is is fast and consumes
Lifecycle of Java Applet Threads can be created by using two mechanisms : RuntimeException are known as unchecked exceptions. more memory when we less memory when we
(1) Applet is initialized. (2) Applet is 1. Extending the Thread class Java provides five keywords that are used to handle the concatenate too many concatenate strings.
started. (3) Applet is painted. (4) 2. Implementing the Runnable Interface exception. strings because every time
Applet is stopped. (5) Applet is Life cycle of a Thread : A thread always exists in try : The "try" keyword is used to specify a block where we it creates new instance.
destroyed. any one of the following states. These states are: should place an exception code. The try block must be String class overrides the StringBuffer class doesn't
We can use JDBC API to For creating any applet (1) New: Whenever a new thread is created, it is followed by either catch or finally. equals() method of Object override the equals()
access tabular data stored in [Link] class must be always in the new state. For a thread in the new catch : The "catch" block is used to handle the exception. It class. So we can compare method of Object class.
any relational database. By inherited. It provides 4 life cycle state, the code has not been run yet and thus has must be preceded by try block. It can be followed by finally the contents of two strings
the help of JDBC API, we can methods of applet. not begun its execution. block later. by equals() method.
save, update, delete and fetch 1. public void init(): is used to (2) Active: When a thread invokes the start() finally : The "finally" block is used to execute the necessary String class is slower while StringBuffer class is
data from the database. The initialized the Applet. It is invoked method, it moves from the new state to the active code of the program. It is executed whether an exception is performing concatenation faster while performing
[Link] package contains only once. state. The active state contains two states within it: handled or not. operation. concatenation operation.
classes and interfaces for 2. public void start(): is invoked after one is runnable, and the other is running. throw : The "throw" keyword is used to throw an exception. String class uses String StringBuffer uses Heap
JDBC API. the init() method or browser is (3) Blocked or Waiting: Whenever a thread is throws : The "throws" keyword is used to declare constant pool. memory
JDBC Driver is a software maximized. It is used to start the inactive for a span of time (not permanently) then, exceptions. It specifies that there may occur an exception
component that enables java Applet. either the thread is in the blocked state or is in the in the method. It doesn't throw an exception. It is always Java Swing tutorial is a part of Java Foundation Classes (JFC)
application to interact with 3. public void stop(): is used to stop waiting state. used with method signature. that is used to create window-based applications. It is built on
the database. There are 4 the Applet. It is invoked when (4) Timed Waiting: The sleep() method puts the Program: Output: the top of AWT (Abstract Windowing Toolkit) API and entirely
types of JDBC drivers: Applet is stop or browser is thread in the timed wait state. After the time runs public class JavaExceptionExample { Exception in thread main written in java. Unlike AWT, Java Swing provides platform-
public static void main(String args[]) { [Link]:/ by
1. JDBC-ODBC bridge driver minimized. out, the thread wakes up and start its execution try{ zero independent and lightweight components. The [Link]
2. Native-API driver 4. public void destroy(): is used to from when it has left earlier. int data=100/0; } rest of the code... package provides classes for java swing API such as JButton,
catch(ArithmeticException e {
3. Network Protocol driver destroy the Applet. It is invoked (5) Terminated: A terminated thread means the [Link](e); } JTextField, JTextArea, JRadioButton, JCheckbox, JMenu,
4. Thin driver only once. thread is no more in the system. [Link]("rest of the code..."); } } JColorChooser.

Polymorphism : If one task is performed in different Abstract class : Abstraction is a process of hiding the implementation Features of Java : The primary objective JVM : Java Virtual Machine is an Java OOPs Concepts
ways, it is known as polymorphism. In Java, we use details and showing only functionality to the user. A class which is of Java programming language creation abstract machine. It is called a virtual Object : An Object can be defined as an
method overloading and method overriding to declared as abstract is known as an abstract class. It can have was to make it portable, simple and machine because it doesn't physically instance of a class. An object contains
achieve polymorphism. abstract and non-abstract methods. It needs to be extended and its secure programming language. exist. It is a specification that provides an address and takes up some space in
Method Overloading : If a class has multiple method implemented. It cannot be instantiated. An abstract class must Simple : Java is very easy to learn, and a runtime environment in which Java memory.
methods having same name but different in be declared with an abstract keyword. its syntax is simple, clean and easy to bytecode can be executed. It can also Class : Class is a blueprint from which
parameters. There are two ways to overload the Program : understand. run those programs which are written you can create an individual object. Class
method in java : (1) By changing number of abstract class Bike{ Garbage Collection is process of Object Oriented : Java is an object- in other languages and compiled to doesn't consume any space.
arguments (2) By changing the data type abstract void run(); reclaiming the runtime unused memory oriented programming language. Java bytecode. The JVM performs the Inheritance : It is a mechanism in which
Program : } automatically. In other words, it is a way Everything in Java is an object. Basic following main tasks: (1)Loads code one object acquires all the properties and
class Adder{ class Honda4 extends Bike{ to destroy the concepts of OOPs are: Object, Class, (2)Verifies code (3)Executes code behaviors of a parent object. The idea
static int add(int a,int b){return a+b;} void run(){[Link]("running safely");} unused objects. Inheritance, Polymorphism, Abstraction, (4)Provides runtime environment behind inheritance in Java is that we can
static int add(int a,int b,int c){return a+b+c;} public static void main(String args[]){ Advantages : Encapsulation. create new classes that are built upon
} Bike obj = new Honda4(); It makes java Platform Independent : Java is platform JRE : Java Runtime Environment is a existing classes. When we inherit from an
class TestOverloading1{ Output : [Link](); memory independent because it is different from set of software tools which are used existing class, you can reuse methods
public static void main(String[] args){ 22 }} Output : running safely efficient. other languages like C, C++, etc. which for developing Java applications. It is and fields of the parent class. Moreover,
[Link]([Link](11,11)); 23 are compiled into platform specific used to provide the runtime you can add new methods and fields in
[Link]([Link](11,11,11)); An Interface in Java is a blueprint of a class. It has static constants machines while Java is a write once, run environment. It is the implementation your current class also. Inheritance
}} and abstract methods. It is a mechanism to achieve abstraction. There anywhere language. of JVM. It physically exists. It contains represents the IS-A relationship which is
Method Overriding : If subclass has the same can be only abstract methods in the Java interface, not method body. Secured : Java is best known for its a set of libraries + other files that JVM also known as a parent-childrelationship.
method as declared in the parent class, it is known An interface is declared by using the interface keyword. It provides security. With Java, we can develop uses at runtime. The extends keyword indicates that we
as method overriding. Rules for Java Method total abstraction; means all the methods in an interface are declared virus-free systems. are making a new class that derives from
Overriding : (1) The method must have the same with the empty body, and all the fields are public, static and final by Robust : It uses strong memory JDK : Java Development Kit. is a an existing class. Types of inheritance in
name as in the parent class. (2) The method must default. A class that implements an interface must implement all the management. software development environment java are :
have the same parameter as in the parent class. (3) methods declared in the interface. Portable : Java is portable because it which is used to develop Java 1. Single inheritance : Subclasses
There must be an IS-A relationship (inheritance). Program : Types of Operators : Unary Operator, facilitates you to carry the Java bytecode applications and applets. It physically inherit the features of one
Program : interface printable{ Arithmetic Operator, Shift Operator, Relational to any platform. exists. It contains JRE + development superclass.
class Vehicle{ void print(); Operator, Bitwise Operator, Logical Operator, Distributed : Java is distributed because tools. The JDK contains a private Java 2. Multilevel Inheritance : A derived
void run(){[Link]("Vehicle is running");} } Ternary Operator it facilitates users to create distributed Virtual Machine (JVM) and a few other class will be inheriting a base class,
} class MyClass implements printable{ and Assignment applications in Java. resources such as an and as well as the derived class also
class Bike extends Vehicle{ public void print(){[Link]("Hello");} Operator. Multi-threaded : A thread is like a interpreter/loader (java), a compiler acts as the base class for other
public static void main(String args[]){ public static void main(String args[]){ separate program, executing (javac), an archiver (jar), a classes.
Bike obj = new Bike(); MyClass obj = new MyClass(); concurrently. documentation generator (Javadoc), 3. Hierarchical Inheritance : One class
[Link](); [Link](); Dynamic : Java is a dynamic language. It etc. to complete the development of a serves as a superclass (base class)
} } Output : Vehicle is running }} Output : hello supports the dynamic loading of classes. Java Application. for more than one subclass.

Constructor : In Java, a constructor is a block of static keyword : In Java, it is used for memory management mainly. We Access modifiers : In Java, it specifies the accessibility or scope of a field, Encapsulation in Java is a process of wrapping
codes similar to the method. It is called when an can apply static keyword with variables, methods, blocks and nested method, constructor, or class. We can change the access level of fields, code and data together into a single unit, for
instance of the class is created. At the time of classes. The static keyword belongs to the class than an instance of constructors, methods, and class by applying the access modifier on it. example, a capsule which is mixed of several
calling constructor, memory for the object is the class. There are four types of Java access modifiers: medicines. We can create a fully encapsulated
allocated in the memory. It is a special type of Program : The super keyword in Java is a 1. Private: The access level of a private modifier is only within the class. class in Java by making all the data members of
method which is used to initialize the object. Every class Student{ reference variable which is used to It cannot be accessed from outside the class. the class private. Now we can use setter and
time an object is created using the new() keyword, at int rollno; refer immediate parent class object. 2. Default: The access level of a default modifier is only within the getter methods to set and get the data in it.
least one constructor is called. It calls a default String name; Whenever we create the instance of package. It cannot be accessed from outside the package. If you do Advantages :
constructor if there is no constructor available in the static String college ="PU"; subclass, an instance of parent class is not specify any access level, it will be the default. 1. By providing only a setter or getter method,
class. In such case, Java compiler provides a Student(int r, String n){ created implicitly which is referred by 3. Protected: The access level of a protected modifier is within the we can make the class read-only or write-
default constructor by default. rollno = r; super reference variable. super can be package and outside the package through child class. If you do not only.
Rules for creating Java constructor : (1)Constructor name = n; used to refer immediate parent class make the child class, it cannot be accessed from outside the package. 2. It provides you the control over the data.
name must be the same as its class name. } instance variable, method & constructor 4. Public: The access level of a public modifier is everywhere. It can be 3. It is a way to achieve data hiding.
(2)Constructor must have no explicit return type. void display (){ accessed from within the class, outside the class, within the package 4. The encapsulate class is easy to test.
(3)Java constructor cannot be abstract, static, final, [Link](rollno+" "+name+" "+college); and outside the package.
and synchronized. }} Command Line Argument is an argument i.e. passed at the time of
There are two types of constructors in Java: public class TestStaticVariable1{ final keyword in java is used Stream : Java provides a new additional package in running the java program. The arguments passed from the console can
(1)Default constructor (2)Parameterized constructor public static void main(String args[]){ to restrict the user. The java Java 8 called [Link]. This package be received in the java program and it can be used as an input. Program
Default Constructor Program : Student s1 = new Student(111,"Abc"); final keyword can be used in consists of classes, interfaces and enum to allows class CommandLineExample{
class Bike1{ Student s2 = new Student(222,"Xyz"); many context. Final can be functional-style operations on the elements. You public static void main(String args[]){
Bike1(){[Link]("Bike is created"); [Link](); variable, method or class. It can use stream by importing [Link] [Link]("Your first argument is: "+args[0]);
} [Link](); can be used to : package. }}
Output : 111 Abc PU Stop Value Change Stream provides following features: compile by > javac [Link]
public static void main(String args[]){ }} run by > java CommandLineExample hello
Bike1 b=new Bike1(); 222 Xyz PU Stop Method Overridding Stream does not store elements. It simply Output : Your first argument is: hello
Output : Bike is created Stop Inheritance conveys elements from a source such as a data
}}
Parameterized Constructor Program : structure, an array, or an I/O channel, through a
class Student{ Package : In java, it is a group of similar types of classes, interfaces and sub- pipeline of computational operations.
String name; packages. It can be categorized in two form, built-in package and user- Stream is functional in nature. Operations
Student(String n){ defined package. There are many built-in packages such as java, lang, awt, performed on a stream does not modify it's
name = n; javax, swing, net, io, util, sql etc. source.
} Advantages : (1) Java package is used to categorize the classes and Stream is lazy and evaluates code only when
void display(){[Link](name);} interfaces so that they can be easily maintained. (2) Java package provides required.
public static void main(String args[]){ access protection. (3) Java package removes naming collision. The elements of a stream are only visited once
Student s = new Student("ABC"); There are three ways to access the package from outside the package. during the life of a stream. Like an Iterator, a
[Link](); (1) import package.*; (2) import [Link]; (3) fully qualified name. new stream must be generated to revisit the
}} Output : ABC same elements of the source.
Polymorphism : If one task is performed in different Abstract class : Abstraction is a process of hiding the implementation Features of Java : The primary objective JVM : Java Virtual Machine is an Java OOPs Concepts
ways, it is known as polymorphism. In Java, we use details and showing only functionality to the user. A class which is of Java programming language creation abstract machine. It is called a virtual Object : An Object can be defined as an
method overloading and method overriding to declared as abstract is known as an abstract class. It can have was to make it portable, simple and machine because it doesn't physically instance of a class. An object contains
achieve polymorphism. abstract and non-abstract methods. It needs to be extended and its secure programming language. exist. It is a specification that provides an address and takes up some space in
Method Overloading : If a class has multiple method implemented. It cannot be instantiated. An abstract class must Simple : Java is very easy to learn, and a runtime environment in which Java memory.
methods having same name but different in be declared with an abstract keyword. its syntax is simple, clean and easy to bytecode can be executed. It can also Class : Class is a blueprint from which
parameters. There are two ways to overload the Program : understand. run those programs which are written you can create an individual object. Class
method in java : (1) By changing number of abstract class Bike{ Garbage Collection is process of Object Oriented : Java is an object- in other languages and compiled to doesn't consume any space.
arguments (2) By changing the data type abstract void run(); reclaiming the runtime unused memory oriented programming language. Java bytecode. The JVM performs the Inheritance : It is a mechanism in which
Program : } automatically. In other words, it is a way Everything in Java is an object. Basic following main tasks: (1)Loads code one object acquires all the properties and
class Adder{ class Honda4 extends Bike{ to destroy the concepts of OOPs are: Object, Class, (2)Verifies code (3)Executes code behaviors of a parent object. The idea
static int add(int a,int b){return a+b;} void run(){[Link]("running safely");} unused objects. Inheritance, Polymorphism, Abstraction, (4)Provides runtime environment behind inheritance in Java is that we can
static int add(int a,int b,int c){return a+b+c;} public static void main(String args[]){ Advantages : Encapsulation. create new classes that are built upon
} Bike obj = new Honda4(); It makes java Platform Independent : Java is platform JRE : Java Runtime Environment is a existing classes. When we inherit from an
class TestOverloading1{ Output : [Link](); memory independent because it is different from set of software tools which are used existing class, you can reuse methods
public static void main(String[] args){ 22 }} Output : running safely efficient. other languages like C, C++, etc. which for developing Java applications. It is and fields of the parent class. Moreover,
[Link]([Link](11,11)); 23 are compiled into platform specific used to provide the runtime you can add new methods and fields in
[Link]([Link](11,11,11)); An Interface in Java is a blueprint of a class. It has static constants machines while Java is a write once, run environment. It is the implementation your current class also. Inheritance
}} and abstract methods. It is a mechanism to achieve abstraction. There anywhere language. of JVM. It physically exists. It contains represents the IS-A relationship which is
Method Overriding : If subclass has the same can be only abstract methods in the Java interface, not method body. Secured : Java is best known for its a set of libraries + other files that JVM also known as a parent-childrelationship.
method as declared in the parent class, it is known An interface is declared by using the interface keyword. It provides security. With Java, we can develop uses at runtime. The extends keyword indicates that we
as method overriding. Rules for Java Method total abstraction; means all the methods in an interface are declared virus-free systems. are making a new class that derives from
Overriding : (1) The method must have the same with the empty body, and all the fields are public, static and final by Robust : It uses strong memory JDK : Java Development Kit. is a an existing class. Types of inheritance in
name as in the parent class. (2) The method must default. A class that implements an interface must implement all the management. software development environment java are :
have the same parameter as in the parent class. (3) methods declared in the interface. Portable : Java is portable because it which is used to develop Java 1. Single inheritance : Subclasses
There must be an IS-A relationship (inheritance). Program : Types of Operators : Unary Operator, facilitates you to carry the Java bytecode applications and applets. It physically inherit the features of one
Program : interface printable{ Arithmetic Operator, Shift Operator, Relational to any platform. exists. It contains JRE + development superclass.
class Vehicle{ void print(); Operator, Bitwise Operator, Logical Operator, Distributed : Java is distributed because tools. The JDK contains a private Java 2. Multilevel Inheritance : A derived
void run(){[Link]("Vehicle is running");} } Ternary Operator it facilitates users to create distributed Virtual Machine (JVM) and a few other class will be inheriting a base class,
} class MyClass implements printable{ and Assignment applications in Java. resources such as an and as well as the derived class also
class Bike extends Vehicle{ public void print(){[Link]("Hello");} Operator. Multi-threaded : A thread is like a interpreter/loader (java), a compiler acts as the base class for other
public static void main(String args[]){ public static void main(String args[]){ separate program, executing (javac), an archiver (jar), a classes.
Bike obj = new Bike(); MyClass obj = new MyClass(); concurrently. documentation generator (Javadoc), 3. Hierarchical Inheritance : One class
[Link](); [Link](); Dynamic : Java is a dynamic language. It etc. to complete the development of a serves as a superclass (base class)
} } Output : Vehicle is running }} Output : hello supports the dynamic loading of classes. Java Application. for more than one subclass.

You might also like