PESIT Bangalore South Campus

Similar documents
PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Science and Engineering

NITI NITI I PRIORITET

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

JDBC Drivers Type. JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server.

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

JDBC. Sun Microsystems has included JDBC API as a part of J2SDK to develop Java applications that can communicate with databases.

UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING. A Multithreaded program contains two or more parts that can run concurrently.

Enterprise Java Unit 1- Chapter 6 Prof. Sujata Rizal

JDBC Architecture. JDBC API: This provides the application-to- JDBC Manager connection.

Which of the following syntax used to attach an input stream to console?

Programmierpraktikum

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

CSIS 10A Practice Final Exam Solutions

Unit 3 - Java Data Base Connectivity

G51PRG: Introduction to Programming Second semester Applets and graphics

The AWT Event Model 9

Module 5 Applets About Applets Hierarchy of Applet Life Cycle of an Applet

UCLA PIC 20A Java Programming

Applet which displays a simulated trackball in the upper half of its window.

GUI 4.1 GUI GUI MouseTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 1 */

Discuss setting up JDBC connectivity. Demonstrate a JDBC program Discuss and demonstrate methods associated with JDBC connectivity

JDBC. Oracle ODBC SP API SP API. SQL server C function calls. SQL server ODBC SP API. Oracle DSN Oracle ODBC Oracle

SQL in a Server Environment

User interfaces and Swing

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Unit 7: Event driven programming

Event Driven Programming

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

UNIT-3 Java Database Client/Server

public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public void mouseclicked (MouseEvent e) int x = e.getx(), y = e.gety();

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

Come & Join Us at VUSTUDENTS.net

CSIS 10A Assignment 14 SOLUTIONS

GUI in Java TalentHome Solutions

CS2110. GUIS: Listening to Events

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development

EE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS

CS2110. GUIS: Listening to Events. Anonymous functions. Anonymous functions. Anonymous functions. Checkers.java. mainbox

Applet. 1. init (): called once by the applet containers when an applet is loaded for execution.

CS2110. GUIS: Listening to Events

Advanced Java Programming (17625) Event Handling. 20 Marks

CS 120 Fall 2008 Practice Final Exam v1.0m. Name: Model Solution. True/False Section, 20 points: 10 true/false, 2 points each

Introduction to Java Applets 12

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

Introduction JDBC 4.1. Bok, Jong Soon

1. PhP Project. Create a new PhP Project as shown below and click next

Questions and Answers. A. A DataSource is the basic service for managing a set of JDBC drivers.

CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1

J.73 J.74 THE I/O PACKAGE. Java I/O is defined in terms of streams. Streams are ordered sequences of data that have a source and a destination.

Chapter 1 GUI Applications

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

ERwin and JDBC. Mar. 6, 2007 Myoung Ho Kim

COMPSCI 230. Software Design and Construction. Swing

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

You write standard JDBC API application and plug in the appropriate JDBC driver for the database the you want to use. Java applet, app or servlets

CS2110. GUIS: Listening to Events Also anonymous classes versus Java 8 functions. Anonymous functions. Anonymous functions. Anonymous functions

Java Database Connectivity (JDBC) 25.1 What is JDBC?

AP CS Unit 12: Drawing and Mouse Events

ABOUT CORE JAVA COURSE SCOPE:

Graphical User Interfaces 2

2. (True/False) All methods in an interface must be declared public.

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige

Java Applet Basics. Life cycle of an applet:

CS 180 Problem Solving and Object Oriented Programming Fall 2011

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below.

CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed

e-pg Pathshala Subject: Computer Science Paper: Web Technology Module: JDBC INTRODUCTION Module No: CS/WT/26 Quadrant 2 e-text

cs Java: lecture #5

Top 50 JDBC Interview Questions and Answers

Working with Databases and Java

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

The Design of JDBC The Structured Query Language Basic JDBC Programming Concepts Query Execution Scrollable and Updatable Result Sets

JDBC Programming: Intro

UNIT III - JDBC Two Marks

Kyle Brown Knowledge Systems Corporation by Kyle Brown and Knowledge Systems Corporation

Reading from URL. Intent - open URL get an input stream on the connection, and read from the input stream.

CS 251 Intermediate Programming GUIs: Event Listeners

Outline. More on the Swing API Graphics: double buffering and timers Model - View - Controller paradigm Applets

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Lecture 2. Introduction to JDBC

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Unit 1- Java Applets. Applet Programming. Local Applet and Remote Applet ** Applet and Application

Chapter 3 DB-Gateways

SNS COLLEGE OF ENGINEERING, Coimbatore

Chapter 7 Applets. Answers

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Part I: Stored Procedures. Introduction to SQL Programming Techniques. CSC 375, Fall 2017

Object Oriented Programming with Java. Unit-1

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN

Definition: A thread is a single sequential flow of control within a program.

JDBC [Java DataBase Connectivity]

Course: CMPT 101/104 E.100 Thursday, November 23, 2000

Contents. 6-1 Copyright (c) N. Afshartous

Computer Science 210: Data Structures. Intro to Java Graphics

Cheng, CSE870. More Frameworks. Overview. Recap on OOP. Acknowledgements:

AP Computer Science Unit 13. Still More Graphics and Animation.

Chapter 3 DB-Gateways

Programming graphics

Graphical User Interfaces 2

Transcription:

INTERNAL ASSESSMENT TEST II Date : 20-09-2016 Max Marks: 50 Subject & Code: JAVA & J2EE (10IS752) Section : A & B Name of faculty: Sreenath M V Time : 8.30-10.00 AM Note: Answer all five questions 1) a) Explain any two event listener interfaces with its function or methods. 5 The KeyListener Interface This interface defines three methods. The keypressed () and keyreleased () methods are invoked when a key is pressed and released, respectively. The keytyped () method is invoked when a character has been entered. Ex: If a user presses and releases the a key, three events are generated in sequence: key pressed, typed and released. If a user presses and releases the HOME key, two key events are generated in sequence: key pressed and released. The general forms of the three methods are: void keypressed (KeyEvent ke) void keyreleased (KeyEvent ke) void keytyped (KeyEvent ke) The MouseListener Interface Five methods: void mouseclicked (MouseEvent me) (Invoked when the mouse is pressed and released at the same point) void mouseentered (MouseEvent me) (Invoked when the mouse enters a component) void mouseexited (MouseEvent me) (Invoked when the mouse exits a component)

void mousepressed (MouseEvent me) (Invoked when the mouse is pressed) void mousereleased (MouseEvent me) (Invoked when the mouse is released) b) What is adapter class? Demonstrate with an example. 5 Each adapter class implements the corresponding interface with a series of donothing methods. For example, MouseListener declares these five methods: public abstract void mouseclicked(mouseevent evt) public abstract void mousepressed(mouseevent evt) public abstract void mousereleased(mouseevent evt) public abstract void mouseentered(mouseevent evt) public abstract void mouseexited(mouseevent evt) Therefore, MouseAdapter looks like this: package java.awt.event; import java.awt.*; import java.awt.event.*; public class MouseAdapter implements MouseListener { public void mouseclicked(mouseevent evt) { public void mousepressed(mouseevent evt) {

public void mousereleased(mouseevent evt) { public void mouseentered(mouseevent evt) { public void mouseexited(mouseevent evt) { By subclassing MouseAdapter rather than implementing MouseListener directly, you avoid having to write the methods you don't actually need. You only override those that you plan to actually implement. 2) What is multithreading? Write a program to create multiple threads in JAVA. 10 class MyThread implements Runnable { String tname; Thread t; MyThread (String threadname) { tname = threadname; t = new Thread (this, tname); t.start(); public void run() { try { System.out.println("Thread: " + tname ); Thread.sleep(2000); catch (InterruptedException e ) {

System.out.println("Exception: Thread " + tname + " interrupted"); System.out.println("Terminating thread: " + tname ); class Demo { public static void main (String args []) { new MyThread ("1"); new MyThread ("2"); new MyThread ("3"); new MyThread ("4"); try { Thread.sleep (10000); catch (InterruptedException e) { System.out.println( "Exception: Thread main interrupted."); System.out.println( "Terminating thread: main thread.");

3) What are applets? Explain different stages in the life cycle of an applet with example. 10 An applet is a special kind of Java program that a browser enabled with Java technology can download from the internet and run. // Sample Java Applet; an Applet skeleton import java.applet.applet; import java.awt.graphics; public class Simple extends Applet { StringBuffer buffer; public void init() { buffer = new StringBuffer(); additem("initializing... "); public void start() { additem("starting... "); public void stop() { additem("stopping... "); /* A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. */ public void destroy() { additem("preparing for unloading..."); private void additem(string newword) { System.out.println(newWord); buffer.append(newword); repaint(); public void paint(graphics g) { //Draw a Rectangle around the applet's display area. g.drawrect(0, 0, getwidth() - 1, getheight() - 1);

//Draw the current string inside the rectangle. g.drawstring(buffer.tostring(), 5, 15); Invoking an Applet: An applet may be invoked by embedding directives in an HTML file and viewing the file through an applet viewer or Java-enabled browser. The <applet> tag is the basis for embedding an applet in an HTML file. Below is an example that invokes the "Hello, World" applet: <html> <title>the Hello, World Applet</title> <hr> <applet code="helloworldapplet.class" width="320" height="120"> If your browser was Java-enabled, a "Hello, World" message would appear here. </applet> <hr> </html> The code attribute of the <applet> tag is required. It specifies the Applet class to run. Width and height are also required to specify the initial size of the panel in which an applet runs. The applet directive must be closed with a </applet> tag. 4) a) With syntax explain three execute methods. Once you've created a Statement object, you can then use it to execute an SQL statement with one of its three execute methods. 5 boolean execute (String SQL): Returns a boolean value of true if a ResultSet object can be retrieved; otherwise, it returns false. Use this method to execute SQL DDL statements or when you need to use truly dynamic SQL. int executeupdate (String SQL): Returns the number of rows affected by the execution of the SQL statement. Use this method to execute SQL statements for which you expect to get a number of rows affected - for example, an INSERT, UPDATE, or DELETE statement. ResultSet executequery (String SQL): Returns a ResultSet object. Use this method when you expect to get a result set, as you would with a SELECT statement.

b) Explain i) Statement ii) Prepared Statement 5 Statement Objects Overview Once a connection is obtained we can interact with the database. The JDBC Statement, CallableStatement, and PreparedStatement interfaces define the methods and properties that enable you to send SQL or PL/SQL commands and receive data from your database. They also define methods that help bridge data type differences between Java and SQL data types used in a database. Statement-Used for the general-purpose access to your database. Useful when you are using static SQL statements at runtime. The Statement interface cannot accept parameters PreparedStatement-Use the when you plan to use the SQL statements many times. The PreparedStatement interface accepts input parameters at runtime. Creating Statement Objects The Statement Objects Creating Statement Object Before you can use a Statement object to execute a SQL statement, you need to create one using the Connection object's createstatement( ) method, as in the following example Statement stmt = null; try { stmt = conn.createstatement( );... catch (SQLException e) {... finally {... The PreparedStatement Objects The PreparedStatement interface extends the Statement interface, which gives you added functionality with a couple of advantages over a generic Statement object. This statement gives you the flexibility of supplying arguments dynamically. Creating PreparedStatement Object PreparedStatement pstmt = null; try { String SQL = "Update Employees SET age =? WHERE id =?"; pstmt = conn.preparestatement(sql);... catch (SQLException e) {... finally {... All parameters in JDBC are represented by the? symbol, which is known as

the parameter marker. You must supply values for every parameter before executing the SQL statement. 5) a) Explain J2EE multitier architecture with a neat diagram. 5

b) Explain four types of JDBC Drivers. 5 JDBC Driver types JDBC drivers are divided into four types: Type 1: JDBC-ODBC Bridge driver (Bridge) Type 2: Native-API/partly Java driver (Native) Type 3: All Java/Net-protocol driver (Middleware) Type 4: All Java/Native-protocol driver (Pure) Type 1 - JDBC-ODBC Bridge driver A JDBC-ODBC bridge provides JDBC API access via one or more ODBC drivers. Note that some ODBC native code and in many cases native database client code must be loaded on each client machine that uses this type of driver. Hence, this kind of driver is generally most appropriate when automatic installation and downloading of a Java technology application is not important. Type 2 - Native-API/partly Java driver A native-api partly Java technology-enabled driver converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine. Type 3 - All Java/Net-protocol driver A net-protocol fully Java technology-enabled driver translates JDBC API calls into a DBMS-independent net protocol which is then translated to a DBMS protocol by a server. This net server middleware is able to connect all of its Java technology-based clients to many different databases.

Type 4 - Native-protocol/all-Java driver A native-protocol fully Java technology-enabled driver converts JDBC technology calls into the network protocol used by DBMSs directly. This allows a direct call from the client machine to the DBMS server and is a practical solution for Intranet access. Since many of these protocols are proprietary, the database vendors themselves will be the primary source for this style of driver. Several database vendors have these in progress. * * * * * *