Unit 1 Part4 ExceptionHandlingn, AWT, Event Handling, Applet
Unit 1 Part4 ExceptionHandlingn, AWT, Event Handling, Applet
Unit-2
Web Page Designing: HTML: List, Table, Images, Frames, forms, CSS, Document type definition, XML: DTD, XML schemes, Object Models, presenting and
using XML, Using XML Processors: DOM and SAX, Dynamic HTML
Unit-3
Scripting: Java script: Introduction, documents, forms, statements, functions, objects; introduction to AJAX, Networking : Internet Addressing, InetAddress,
Factory Methods, Instance Methods, TCP/IP Client Sockets, URL, URL Connection, TCP/IP Server Sockets, Datagram.
Unit-4
Enterprise Java Bean: Preparing a Class to be a JavaBeans, Creating a JavaBeans, JavaBeans Properties, Types of beans, Stateful Session bean, Stateless
Session bean, Entity bean
Java Database Connectivity (JDBC): Merging Data from Multiple Tables: Joining, Manipulating, Databases with JDBC, Prepared Statements,
Transaction Processing, Stored Procedures.
Unit-5
Servlets: Servlet Overview and Architecture, Interface Servlet and the Servlet Life Cycle, Handling HTTP get Requests, Handling HTTP post Requests,
Redirecting Requests to Other Resources, Session Tracking, Cookies, Session Tracking with Http Session
Java Server Pages (JSP): Introduction, Java Server Pages Overview, A First Java Server Page Example, Implicit Objects, Scripting, Standard Actions,
Directives, Custom Tag Libraries..
Subject:Web
Subject: Web Technology
Technology
Exception Handling in Java
Wrong Concept
Compile time exceptions occurs at compile time and
runtime exceptions occur at runtime.
Right Concept
All the exceptions occur at runtime
2. Unchecked exceptions is an exception that occurs at the time of execution. These are
also called as Runtime Exceptions. These include programming bugs, such as logic
errors or improper use of an API. Runtime exceptions are ignored at the time of
compilation.
3. Errors − These are not exceptions at all, but problems that arise beyond the control of
the user or the programmer. Errors are typically ignored in your code because you can
rarely do anything about an error. For example, if a stack overflow occurs, an error will
arise. They are also ignored at the time of compilation.
Keyword Description
try The "try" keyword is used to specify a block where we should place exception code. The try
block must be followed by either catch or finally. It means, we can't use try block alone.
catch The "catch" block is used to handle the exception. It must be preceded by try block which
means we can't use catch block alone. It can be followed by finally block later.
finally The "finally" block is used to execute the important code of the program. It is executed whether
an exception is handled or not.
throw The "throw" keyword is used to throw an exception.
throws The "throws" keyword is used to declare exceptions. It doesn't throw an exception. It specifies
that there may occur an exception in the method. It is always used with method signature.
Steps
I. Program statements that you think can raise exceptions are contained within a try block.
II. If an exception occurs within the try block, it is thrown. Code can catch this exception(using
catch block) and handle it in some rational manner.
III. In finally, write the code which must necessarily run. For example- Closing files, and database
connection release.
Note: Finally will run mandatory irrespective run of the exception.
Subject: Web Technology
Exception Handling in Java(Cont.…)
Multitasking
• Task means a small work on a computer, if such work is done in multiples at the same time it is known
as multitasking.
• Multitasking is a process of executing multiple tasks simultaneously.
• We use multitasking to utilize the CPU.
• Multitasking can be achieved in two ways:
1) Process-based Multitasking (Multiprocessing)
2) Thread-based Multitasking (Multithreading)
There are various stages of the life cycle of thread as shown in the above diagram:
1. New: In this phase, the thread is created using the class “Thread class". It remains in this state till the
program starts the thread. It is also known as the born thread.
2. Runnable: On this page, the instance of the thread is invoked with a start method. The thread control is
given to the scheduler to finish the execution. It depends on the scheduler, and whether to run the
thread.
3. Running: When the thread starts executing, then the state is changed to a “running” state. The scheduler
selects one thread from the thread pool, and it starts executing in the application.
4. Waiting: This is the state in which a thread has to wait. As there multiple threads are running in the
application, there is a need for synchronization between threads. Hence, one thread has to wait, till the
other thread gets executed. Therefore, this state is referred to as a waiting state.
5. Dead: This is the state in which the thread is terminated. The thread is in a running state and as soon as
it completed processing it is in a “dead state”.
class Demo_print {
public static void main(String[] args)
{
// using print()
// all are printed in the
// same line
System.out.print("GfG! ");
System.out.print("GfG! ");
System.out.print("GfG! ");
}
}
Advantage of Applet
• It works on the client side so less response time.
• Secured
• It can be executed by browsers running under many platforms, including Linux,
Windows, Mac Os, etc.
Drawback of Applet
• Plugin is required at the client browser to execute the applet.
Syntax:
addTypeListener()
• Example 1: For KeyEvent we use addKeyListener() to register.
• Example 2:that For ActionEvent we use addActionListener() to register.
Types of containers:
There are four types of containers
in Java AWT:
1. Window
2. Panel
3. Frame
4. Dialog
public void setSize(int width,int height) Sets the size (width and height) of the component.
public void setLayout(LayoutManager m) Defines the layout manager for the component.
public void setVisible(boolean status) Changes the visibility of the component, by default
false.
By Creating
the object of
the frame
class.