Advanced Java Programming PDF
Advanced Java Programming PDF
2012
SIXTH SEMESTER
COMPUTER ENGINEERING GROUP
December 2014
MAHARASHTRA STATE
BOARD OF TECHNICAL EDUCATION, Mumbai
(Autonomous) (ISO 9001:2008) (ISO/IEC 27001:2005)
1
INDEX
Content No. Contents Page No.
1.0 APPROACH TO CURRICULUM DESIGN 3
2.0 OBJECTIVES 8
3.0 CONTENT ANALYSIS 13
4.0 CURRICULUM 20
5.0 IMPLIMENTATION STRATEGIES 26
5.1 Planning of Lectures for a Semester with 26
Content Detailing
5.2 Planning and Conduct of Test 55
5.3 Detail about Conduct of Assignment 55
5.4 Strategies for conduct of Practical 56
6.0 MODE OF ASSESSMENT 57
6.1 Class Test 57
6.1.1 Sample Test Paper –I 58
6.1.2 Sample Test Paper –II 70
6.2 Sample Question Paper 78
6.2.1 Specification Table 106
6.2.2 Question Paper Profile 107
6.2.3 Answer Key 108
2
1. 0 APPROACH TO CURRICULUM DESIGN
1.1 Background:
MSBTE is introducing the revised curriculum under ‘G’ scheme from the academic year
2012-13.
There are many institutions in the state running different diploma courses. In order to ensure
uniform and effective implementation of the curriculum it is necessary that every teacher is
aware of approach for curriculum design, educational principles to be adopted, learning
resources to be used and evaluation methods. The teacher guide prepared for each subject
will provide the inputs related to above mentioned aspects to achieve uniform and effective
implementation of curriculum of various subjects.
MSBTE has adopted systems approach while designing the scientific based curriculum
since 1995. The same approach has been adopted while revising the curriculum in
semester pattern.
Fig. No. 1 shows the systems diagram. This diagram provides the holistic view for
curriculum designing, development, implementation and evaluation
The input to polytechnic education system is the students having 10+ qualifications. The
teaching learning process occurs in the institution for six/eight semesters. The output of
the system i. e. Diploma pass out is normally the input to industries. (Some students do
go for higher education). While designing the curriculum the expectations of the
industries play a major role. Due to globalization and competition the industries expect
that pass outs have generic and technological skills along with right attitude.
To fulfill the needs derived from systems approach following conceptual framework is
considered:
1.3 Curriculum:
“Curriculum is an educational program designed and implemented to achieve
specified educational objectives”
This definition takes into account the fact that
Education is purposeful
There is an organized plan of action contemplated
Such a plan is translated into action through appropriate strategies of implementation.
3
REGULATING AGENCIES
M.H.R.D., A.I.C.T.E.
5) MGT
MOE
DTE, DIIC, MSBTE
POLYTECHNICS
3 INPUT
1. Students
2. State level 4) PROCESS EDUCATIONAL PROCESSES 2) OUTPUT 1) CUSTOMER
RO level
Administrator Diploma
Principals State Institutional Curriculum LRDC Instructional Student’s Engineer External
HODs Planning Planning Design & Design Learning with
Teachers & Develop LRUC 1. Industries
Tech. Support desired 2. Service
Staff skills Sector
Ministerial Staff
3. Identified
Resource, ENABLING
Persons PROCESSES
4. Identified
Faculty Manpower Internal
(Trainers) having Staff of:
knowledge, 1. MOE
State
I.I.I. Project I.I.I. H.R.D. Organizational M.I.S skills and
2. DTE/
Planning Development attitudes
required to DIIC/
` MSBTE
use,
operate, &
6) RESOURCES evaluate, Regional
update and Offices
maintain
PHYSICAL HUMAN INFORMATION FINANCE TIME ENERGY AND
MIS
Faculty
Feed Back
Fig 1 Systems Approach
4
1.4 Curriculum goals
5. To develop learning to learn skills and life skills to cope up with industrial culture
Industries expect from the diploma engineer the abilities and skills of general nature and
specific to the job performance. The curriculum aims at developing life skills and
technological skills so that the diploma pass outs would be suitable for industry. The skills
are listed below:
Life Skills:
Technological Skills:
Diploma engineers should possess following intellectual and motor skills in order to
satisfactorily perform duties assigned to them:
5
A) Intellectual skills.
For First Semester Basic Science is divided into two parts- Basic Physics and Basic
Chemistry. Theory examination of both parts as well as practical examination of both
parts will be conducted on separate days. Sum of theory marks of both parts shall be
considered for passing theory examination of Basic Science. Similarly it is applicable to
practical examination. It is mandatory to appear for theory and practical examination of
both parts. Candidate remaining absent in any examination of any section will not be
declared successful for that exam head.
For second semester Applied Science is divided into two sections- Applied Physics and
Applied Chemistry where the theory examination of 50 marks each and practical
examination of 25 Marks each will be conducted separately and the minimum passing
marks for Applied Science will be the combination of both the sections. . It is mandatory
6
to appear for theory and practical examination of both parts. Candidate remaining absent
in any examination of any section will not be declared successful for that exam head.
The components of Development of Life Skills were taught in two semesters. In
Development of Life Skills –I the topics related to personal development, such as
Learning to Learn Skills, personality development, presentation skills etc. were included.
In Development of Life Skills – II the topics related to Team Building, Leadership, group
behavior etc. were covered. In the revised curriculum the scope of development of life
skills has been broaden to include behavioral science component. Therefore the subject
Development of Life Skills – II has been renamed and it is now included at Vth Semester
in the revised curriculum under the title Behavioral Science.
The subject of Professional Practices was introduced to integrate the skills acquired in
Development of Life Skills, through technical subjects from second to sixth semester.
The experience in implementing the contents of the subject shows that there are limited
activities possible in second semester as the technical knowledge given to the students
is very limited. Also at sixth semester the student are doing projects in which they are
performing many activities included in the Professional Practices and therefore it is
proposed that the subject of Professional Practices be prescribed only for three
semesters vis. Third, fourth and fifth semesters.
Introduction of Environment Studies at fourth Semester for all courses
From the experience of implementation of Elective Subjects at V and VI semesters in
last five years, it is proposed to have only one elective at the sixth semester for all
courses. However the specialized courses like Medical Electronics, Electronics and
Video Engineering will not have provision for electives. For elective, student will have
to choose one from the given two/three subjects.
While revising the curriculum redundant /obsolete topics/sub topics are being replaced
by new/advance technology topics/sub topics.
In Computer Engineering Group, for fourth Semester IF Computer Networks (CON) is
replaced with Data Communication and Networking.
For Fourth Semester IF, Applied Multimedia Technology Theory subject is changed to
Practical.
For Fifth semester CT, System Programming subject is included. For IF course,
Information Security subject is included.
7
For Sixth semester, elective subjects have been included.
In order to satisfy the course objectives, online examination has been introduced for the
subjects Management and Advanced Java Programming.
Linux programming has been introduced as practical subject for CO/CM branch and
Scripting Technology has been introduced as practical subject for IF.
Mobile computing has been introduced for IF branch.
2. 0 OBJECTIVES
2.1 Introduction
Objectives are the statements which describe the expected learning outcome. Such
statements enable teachers to plan instructional process with appropriate resources.
These objectives also provide a direction to frame proper questions to assess the
learning outcome. During last decade there has been research on cognitive approach in
psychology. This approach is based on biological structure of brain and meta-
cognitive knowledge dimension. Important elements of this approach which form
basics of learning are explained below.
2.2 Domains of Learning:
Learning is a process by which students develop relatively permanent change in
mental associations through experience. This is how learning is defined by cognitive
psychologists. Behavioral; psychologists define learning as a relatively permanent
change in behavior.
There are following domains of learning:
A: Cognitive Domain relates to intellectual skills or abilities
B: Affective Domain relates to emotions, feelings, likes, dislikes etc.
C: Psychomotor Domain relates to manipulative skills of hands, legs. Eye-hand
coordination in Engineering & Technology courses, endeavor is made to design
curriculum with a focus on development of cognitive skills through classroom
teaching. Whereas manipulative (psychomotor) skills are developed in workshops,
laboratories & seminars where students work individually or in a group. Development
of affective skills attitudes and value is supposed to be acquired through projects and
co-curricular activities. These are also developed from the work culture or institutions.
8
How far a student has developed these abilities/skills especially from cognitive and
psychomotor domains is assessed on the basis of suitable examinations. When
classroom and laboratory teaching is viewed in this light, evaluation becomes an
integral part of teaching – learning process.
9
6
Create
5
Evaluate
4
Analyze
3
Apply
2
Understand
1
Remember
Following are the details of each level which indicate the general and specific objectives.
Further appropriate verbs are given which are useful in setting good questions. In this table
only four levels are considered for diploma students.
Description of the Major Levels in the Illustrative General Illustrative verbs for
cognitive Domain (Bloom’s Taxonomy) Instructional Objectives stating specific
learning outcomes
Remember – Knowledge is defined as the Knows common terms, Define, describe,
remembering of previously learned material. specific facts, basic identify label, list,
This may involve the recall of a wide range of concepts, principles, match, name, outline,
material, from specific facts to complete methods & procedures reproduce, select,
theories, but all that is required to mind of the state
appropriate information. This represents the
lowest level of learning outcomes in the
cognitive domain
Understand – This is defined as the ability to Understands fact, Convert, distinguish
grasp the meaning of material. This may be principles Interprets estimate, explain,
shown by translating material from one form verbal material, extend, generalize,
to another (words or numbers) by interpreting Interprets charts, tables, give examples; infer,
material (explaining or summarizing), and by graphs. paraphrase, predict,
estimating future trends (predicting Translates verbal rewrite, summarize,
consequences or effects). Draw sketches these material to mathematical draw labeled sketches.
learning outcomes go one step beyond the formula. Estimates
simple remembering of material and represent consequences implied in
the lowest level of understanding. data. Justifies methods &
procedures.
10
Apply – Application refers to the ability to Applies principles to new Change, compile,
use learned material in new and concrete situations. Applies demonstrate, discover
situations. This may include the application of theories to practical manipulate, modify
such things as concepts, principles, rules, situations. Solves operate, predict,
methods, laws and theories. Learning mathematical problem. prepare, produce,
outcomes in this area require a higher level of Construct charts, graphs show, solve, use.
understanding than those under the level Demonstrates correct
described earlier. usage of a procedure
Analyze – Analysis refers to the ability to Recognizes unstated Breakdown, diagram,
break down material into its component parts assumptions and logical differentiate,
so that its organizational structure may be fallacies in reasoning. discriminate,
understood. This may include the Distinguishes between distinguish, identify
identification of the parts, analysis of the facts and inferences. illustrate, infer,
relationship between parts, and recognition of Evaluates relevance/ outline, point out,
the organizational principles involved. adequacy of data. relate, select, separate,
Learning outcomes here represent a higher subdivide.
intellectual level than “understand” and apply
because they require an understanding of both
the content and the structural form of the
material.
11
Assessment is required to be done on the basis of categories of knowledge and levels
of learning. Table below indicates the two dimensional grid based on Blooms
Taxonomy for setting questions.
A. Factual
Knowledge
B. Conceptual
Knowledge
C. Procedural
Knowledge
D. Meta-cognitive
Knowledge
2.5.1 Rationale: It indicates the logical basis for the inclusion of the subject in the
curriculum It also indicates the importance of the subject related to entire curriculum.
Rationale tells the students the connection of subjects related to study of higher level
subjects and also the use in their job/profession.
2.5.2 Objectives: Objectives indicate what the student will be able to do/perform
after he/she completes the study of the subject. It also in other words indicates the
scope of the subject.
Objectives indicate what is achievable and hence give direction to the student about
how to study the subject, what important things are to be observed and performed
during practicals.
Just as rationale indicates the use of the knowledge gained while studying the subject,
objectives indicate how efficiently and effectively one can work if the objectives are
fulfilled while studying the subject.
12
Facts, Concepts, Principles are used in developing procedures and applications. So
these are given sequentially below procedure as Principles, Concepts and Facts in their
order. Learning structure also provide an idea about how to develop the subject
logically to achieve the objectives.
2.5.4 Contents: List of topics and subtopics to be included in the curriculum of the
subject is given in the contents. This helps in achieving the rationale and objectives
identified. Contents indicate the importance of the topics, sub topics in development
of the subject and accordingly weightages in terms of Hours required to teach the
subject components, so that the desired learning takes place. Marks to be allotted
while testing the knowledge gained by the student are also indicated.
2.5.5 Practicals: While designing the curriculum the objectives are identified. To
achieve these objectives students have to develop certain intellectual and motor skills.
These skills are developed through well designed Practicals. So in the curriculum the
list of the skills to be developed through Practicals is given. The list of Practicals is so
developed that after performing the Practicals identified skills will be developed. Here
it is necessary that the teacher gives enough opportunity to all the students to perform
the practical properly to develop the skills in each one of them.
The skills will be developed if the students actually perform certain activities or tasks.
Therefore it is necessary that any practical included in the curriculum necessarily
involve some activities to be done by the students. So one has to think and innovate to
modify the study experiments so that students will be asked to perform some activity.
It could be in terms of identifying components, listing of materials used for
manufacturing the components, stating importance of use of certain materials etc.
Before we begin actual teaching of any topic (lesson), we must carefully and critically
analyse it so that we can plan for teaching - select appropriate media, methods and
techniques of teaching and arrange the suitable resources to be required. This analysis
13
of the content of a Topic results in identification of the following components of the
content:
1. Facts
2. Concepts
3. Principles (rules, laws, theories)
4. Applications
5. Procedures
6. Skills (Psychomotor Skills), and
7. Attitudes (underlying affective behaviors as quite often these are not
specifically mentioned in the curriculum, still they are to be developed lesson after
lesson gradually).
Since the nature of the components of content (1 to 7) differs from one another. These
are learned by the students differently as different mental processes are involved in
learning these components. The immediate implication of this varying nature of
components is that these need to be taught differently and assessed differently. For
example, if you look at components I to 5 all of which belong to Cognitive Domain of
Learning; Component 6 belongs to Psychomotor Domain and Component 7 belongs to
Affective Domain (cannot be taught as these attitudes are caught), you will find that
these differ from one another. The classification of human behaviors (activities) into
the above three domains of learning entails the use of entirely different methods and
media of instruction. Different locations of learning (classroom, laboratories,
workshops, field visits) need to be selected.
Now we will discuss these components in some detail and see how each one of these
should be taught and assessed differently.
14
3.1.1 FACTS:
These are universally accepted and commonly understood items about which there
cannot be much argument and discussion. These are required only to be informed. For
example: The sun rises in east and sets in the west; names of scientists and the year in
which their theories were propounded; the rules and regulations of admission and
examination prescribed by the University are some of the examples of facts.
Sometimes, they need not be emphasised in the class as the students already know
them. But information can be passed on by word of mouth, if deemed necessary.
3.1.2 CONCEPTS:
A concept is an abstraction or an idea that permits the learner to classify a variety of
related phenomena into a convenient and meaningful category. Concept of something
is like a picture formation of that thing which helps in conceptualizing it. Gagne says
that concept learning produces a certain fundamental change in human performance
that is independent of subject or content. Concepts can be divided into the following
two categories:
1. Concrete Concepts: those which can be seen, touched and manipulated
e.g. house, book, table, chair, cat, dog, any machine or apparatus, overhead projector,
chalkboard and duster.
2. Abstract Concepts: those which cannot be seen and touched and handled but
can only be imagined e.g. force, work, fractions, decimal, bending moment, moment
of inertia, friction, heat, and induction. Teaching of concrete concepts is not that
difficult because the teacher can show the object physically or its picture. On the
contrary, teaching of an abstract concept offers difficulty to the teacher as well as for
students to understand. These concepts can be learned by heart without understanding
as children mug up Nursery Rhymes without understanding even a single word. But at
the stage of higher tearing, this type of rote learning is not desirable. Adolescents
(teenagers) and adults do not accept things without understanding.
15
teaching a concept to our students we must spell out as many attributes as possible for
better understanding of the concept.
Example: The Concept of Friction
Attributes:
1. Friction is a resistive force.
2. Frictional force acts in the direction opposite to the direction of the applied
force.
3. Frictional force is more when the surfaces in contact are rough.
4. Smooth surfaces (perfect) have zero friction.
5. Frictional force is self-adjusting to a limit.
Towards the end of this Theme Paper a number of examples of concept attributes are
given for your guidance.
3.1.4 PRINCIPLES:
A principle is a statement of relationship between two or more concepts. Principles
are sometimes called rules, laws or generalizations. In others words, relationship
between two or more concepts which is scientific and universally true is called a
Principle.
16
recall the concepts of current, voltage and resistance by asking questions to the
students. Only after that we must tell the relationship among these i.e. Ohm's Law.
3.1.5 APPLICATIONS:
Whatever principles, laws and theories have been learned are only academic exercises
unless these are applied to solve a practical problem. In other words, we call this
application transfer of learning to a new situation. If you recall, the process of
learning dealt with in Theme Paper 2, you will appreciate that the litmus test of
learning having occurred is its application in a new situation or solving a new
problem.
For example:
1. Ohm's law can be applied to find out the unknown quantity (voltage, current,
and resistance).
2. Design of a structure can be made based on related principles and theories.
3. Principles of learning and events of instruction can be applied in ‘Designing a
lesson Plan' and 'Presenting the lesson in the classroom".
4, The above principles can also be applied while preparing textbooks,
workbooks, learning packages and laboratory manuals to be used by the students.
3.1.6 PROCEDURES:
While analysing the content of a topic you might come across certain standard
procedures which are prescribed to perform an operation or a given task. These
procedures should be clearly identified and taught accordingly not to be left to chance.
We should not pre-suppose that the students understand them. We cannot afford to
take these things for granted.
For Example:
1. Procedure of setting up of an apparatus.
2. Procedure to start an engine.
3. Procedure to operate a machine (a lathe).
18
3.3 TEACHING OF PRINCIPLES:
De Cecco & Crawford (1974) has suggested the following steps for teaching
principles effectively.
Steps:
1. Describe the performance expected of the student after he has learned
the principle.
2. Decide and indicate which concepts or principles the students must recall in
learning the new principle.
3. Assist the student in the recall of component concepts.
4. Help the student in the recall of component concepts.
5. Help the student to combine the concepts and put them in a proper order.
6. Provide for practice of the principle and for reinforcement of student responses.
7. Assess the learning of the principle.
3.4 CONCLUSION:
To sum up, it can be said that. it is essential for the teachers to develop the skills of
'Content Analysis' of their subjects. It brings content clarity amongst the teachers
themselves. More importantly, Content Analysis will be a pre-requisite for writing
Instructional Objectives of the topic to be taught. Teaching and learning process is
bound to be effective once these crucial academic activities are undertaken.
19
4.0 CURRICULUM
Course Name : Computer Engineering Group
Course Code : CO/CM/CW/IF/CD
Semester : Sixth for CO/CM/CW/IF and Seventh for CD
Subject Title : Advanced Java Programming
Subject Code : 17625
Examination
Teaching Scheme Scheme
PAPER
TH TU PR TH PR OR TW TOTAL
HRS
03 -- 04 02 100#* 50# -- 50@ 200
*- Online Examination
NOTE:
Two tests each of 25 marks to be conducted as per the schedule given
by MSBTE.
Total of tests marks for all theory subjects are to be converted out of 50 and to be
entered in mark sheet under the head Sessional Work (SW).
Rationale:
Now days, Internet has touched every aspect of life. If we are not connected to
internet, it is like we are nowhere. Online presence is a must for businesses. If your enterprise
is not online, you are far behind. Web presence has dominated the businesses worldwide.
Java technology is more suitable for web applications development. It has market
dominance in the development of online applications. Java is the preferred choice of the
programmers and the enterprises globally.
This subject will equip the students with the required knowledge and the skill needed
for the development of robust, powerful and scalable enterprise level web applications. It
gives students hands-on experience on GUI Technologies viz. AWT and Swings, event
handling mechanisms and network programming. Security issues are also taken into
considerations.
The most important aspect of web applications - Database Interaction - is also nicely
covered. The performance critical areas of the online applications which the Java technology
20
deals with the ease and in a flexible manner by the use of advanced server side components -
servlets - are also systematically covered. The students will be able to understand the
concepts like servlet chaining, filtering, sessions, cookies and the most important Applet -
Servlet communication. Students will also learn the JSP and the Java Beans.
General Objectives:
Intellectual skills:
Use of programming language constructs.
To know apply different logics to solve the given problem.
To be able to write program using different implementations for the same problem.
Study different types of errors.
Debugging of programs.
Understand different steps to develop program such as
a. Problem definition
b. Analysis
c. Design of logic
d. Coding
e. Testing
f. Maintenance
21
Learning Structure:
Designing & implementing GUI based application using AWT & swings,
Application Application networking applications using TCP/IP &UDP protocols, developing
data base driven business application, developing dynamic web application using
servlet and JSP
Designing and
writing Interacting with
window based Writing efficient Writing the database &
Procedure programs programs to network base
making use of
using different
handle events program
using different models
controls and TCP/IP,
layout UDP
managers
Drivers,
mangers,
Basics of connection,
networking, statements,
Principles Component & proxy server, result set
containers, Events instant
and addressing and
Concepts application sources, event
program and model, event security
applet, AWT & listener
swing controls, JDBC, database
dialog boxes, APIS, architecture,
java.sql package
file dialogue and
managers
Network and
Events, delegation, security, Write servlets on
AWT swings,
event model, event socket, JSP, making use
components,
sources, event TCP/IP, UDP, of cookies and
Facts contents session tracking
listener, adopter URL ,
window, applet servlet
and inner classes java. security,
controls, layout
package communication
manager, MVC
architecture
Servlets and its
types, life cycle
response
redirection, session
and cookies, JSP
and java beans
Topic
No. Name of the Topic Hours Marks
Introduction to Abstract Windowing Toolkit(AWT) & Swings
Specific Objective
To design & develop Graphical user interface (GUI)
programs using AWT and swing component.
To arrange the GUI components using different layout
managers.
1.1 Component, container, window, frame, panel.
1.2 Creating windowed programs & applets.
01 1.3 AWT controls & layout managers 16 24
Understanding the use of AWT controls: labels, buttons,
checkbox, checkbox group, scroll bars, text field, text area
Understanding the use of layout managers: flowLayout,
borderLayout, gridLayout, cardLayout, gridbagLayout,
menubars, menus, dialog boxes, file dialog.
1.4 Introduction to swing
Swing features, MVC Architecture, Combo Boxes, progress bar,
tool tips, seperator, tables, trees, toggle button.
Event Handling
Specific Objective
To write event driven programs using the delegation event
model.
To write programs using adapter classes & the inner classes.
2.1 The delegation Event Model
Event sources, Event listeners, Event classes. The Action Event
class, The Component Event class, the Container Event class, the
Focus Event class, the Item Event class, the Key Event class, the
Mouse Event class, the Text Event class, the Window Event class.
02 2.2 Adapter classes 10 20
2.3 Inner classes
2.4 Event listener interfaces
The ActionListener Interface, the ComponentListener Interface,
the ContainerListener Interface, the FocusListener Interface, the
ItemListener Interface, the KeyListener Interface, the MouseListener
Interface, the MouseMotion Interface, the
TextListener Interface, the WindowsListener Interface, the
WindowFocusListener Interface
23
Networking & Security
Specific Objective:
To learn the Java’s built in support for network programming.
To write program to demonstrate connectivity through
software SOCKETS, TCP, ISP, URL and the Java security
package.
3.1 Basics of Networking
Socket, IP, TCP, UDP, Proxy Server, Internet Addressing
3.2 The InetAddress Class
Factory methods
03 Instance methods 08 16
3.3 TCP/IP Sockets
Socket, Server Socket, methods
3.4 URL
URL Connection, http, URL Connection methods, creating &
using TCP/IP client & server
3.5 Security with Java: Theoretical introduction to java.security
Package
Permission class
Policy class
Interacting with Database
Specific Objective :
To create database driven business applications using the
database API’S two tier and three tier models and the
Java.Sql package
4.1 JDBC, ODBC, & Other APIS
04 JDBC two tier & three tier models 06 20
4.2 Connecting to Database
Driver Interface, Driver Manager class, Connection Interface,
Statement Interface, the java.sql.package
Establishing connection & retrieving information Resultset
interface.
Servlets & JSP
Specific Objectives :
To write web based applications using servlets, JSP and Java
Beans.
To write servlet for cookies and session tracking.
5.1 Servlet
Type of Servlet, Servlet life cycle.
05 5.2 Using servlets, response redirection. 08 20
5.3 Basic concepts of sessions, cookies & session tracking
5.4 Introduction to servlet chaining & filters, Introduction to applet
servlet communication.
5.5 JSP, expression, directives& declarations,
Life cycle of a JSP page TLD & JSTL, Java beans.
Total 48 100
Learning Resources:
Books to be referred:
Sr.
No Author Title Publisher
1 Herbert Sheild Complete Reference Tata McGraw
2 Kogent learning Solution Advance JAVA DreamTech Press
3 Sharnam Shah & Vaishali Shah Java EE6 for Beginners SPD
4 Kogent learning Solution Java Server Programming Black DreamTech Press
Book
Practical Contents:
Student will install the following software under the guidance of their Teacher.
1) JDK 1.5 or higher, JRE ( JAVA SOFTWARE)
2) NetBeans (or any IDE)
3) Database (any one )
4) Tomcat web Server
5) Special attention on Servlet and JSP from Projects point of view.
Learning Resources:
Books:
1. Complete Reference Herbert Schildt 5th Edition Mc Graw Hill
2. Java EE6 for Beginners Sharnam Shah & Vaishali Shah SPD
3. Advanced JAVA Kogent learning Solution DreamTech Press
4. Java server Programming Black Book Kogent learning Solution DreamTech
Press
Teaching Aids:
Black board, chalk, Transparencies, PowerPoint presentations, References, Books,
notes, LCD Projector.
PPTs:
1. www.cpsc.ucalgary.ca/~schock/java/CH15AWTComponents.ppt
26
2. www.sci.brooklyn.cuny.edu/~zhou/teaching/java/awt.ppt
Websites
1. www.cs.princeton.edu/courses/archive/spr96/cs333/.../components.html
2. www.tutorialspoint.com/awt/awt_controls.htm
27
Window
3 1.3 (Complete reference Java 2 – 5th Edition) (page nos 736 to 763)
AWT Controls and Layout managers
AWT and Swing controls are used to design a form like MSBTE exam
form, First year Admission form
Understanding use of AWT controls: Labels, Buttons.
A label is used to display a message to user.
28
off. It consists of a small box that can either contain a check mark or not.
There is a label associated with each check box that describes what option
the box represents.
Constructor
Checkbox( )
Checkbox(String str)
Checkbox(String str, boolean on)
Checkbox(String str, boolean on, CheckboxGroup cbGroup)
Checkbox(String str, CheckboxGroup cbGroup, boolean on)
Checkbox group creates a set of mutually exclusive check boxes in which
one and only one check box in the group can be checked at any one time.
Checkbox group: Creates a set of mutually exclusive check boxes in
which one and only one check box in the group can be checked at any one
time. These check boxes are often called radio buttons.
5 Scroll bar
Scroll bar: The slider box in the scroll bar can be dragged by the user to a
new position. The scroll bar will reflect this value.
Scroll bar: Scroll bars are used to select continuous values between a
specified minimum and maximum. Scroll bars may be oriented
horizontally or vertically.
Constructors:
Scrollbar( )
Scrollbar(int style)
Scrollbar(int style, int initialValue, int thumbSize, int min, int max)
Text Field, Text Area.
Text Field is used to take user input when a text such as name,
username, password etc is entered in GUI
TextField class implements a single-line text-entry area, usually called an
edit control.Text fields allow the user to enter strings and to edit the text
using the arrow keys, cut and paste keys, and mouse selections.
Constructors:
TextField( )
TextField(int numChars)
TextField(String str)
TextField(String str, int numChars)
TextArea is used to take user input when a text such as address and
information which is more than one line is entered in GUI
TextArea( )
TextArea(int numLines, int numChars)
TextArea(String str)
TextArea(String str, int numLines, int numChars)
TextArea(String str, int numLines, int numChars, int sBars
7 Understanding the use of layout managers:
(Complete reference Java 2 – 5th Edition) (page nos 763 to 775)
29
flow layout, border layout
Constructors:
FlowLayout( )
FlowLayout(int how)
FlowLayout(int how, int horz, int vert)
Constructors:
BorderLayout( )
BorderLayout(int horz, int vert)
8 grid layout, card layout.
GridLayout: It lays out components in a two-dimensional grid. When
you instantiate a GridLayout, you define the number of rows and columns.
Constructors
GridLayout( )
GridLayout(int numRows, int numColumns )
GridLayout(int numRows, int numColumns, int horz, int vert)
Constructors
CardLayout( )
CardLayout(int horz, int vert)
30
objects. Each Menu object contains a list of MenuItem objects. Each
MenuItem object represents something
that can be selected by the user.
Constructors for Menu:
Menu( )
Menu(String optionName)
Menu(String optionName, boolean removable)
FileDialog: A built-in dialog box provided by Java that lets the user to
specify a file.
Constructors:
FileDialog(Frame parent, String boxName)
FileDialog(Frame parent, String boxName, int how)
FileDialog(Frame parent)
12 1.4 (Complete reference Java 2 – 5th Edition) (page nos 922 to 948)
Introduction to Swing
Swing features, MVC architecture.
Constructors.
JComboBox( ConboBoxModel a Model)
JComboBox(Object [] items)
JComboBox(Vector<?> items)
31
ProgressBar: It draws an updated colored bar that displays the progress of
some operation.
Constructors.
JProgressBar()
JProgressBar(BoundedRangeModel newModel)
JProgressBar(int orient)
JProgressBar(int min, int max)
JProgressBar(int orient, int min, int max )
Tool tips: These are small windows that appear when the user lets rest on a
component.
Constructor.
JToolTip()
14 separator, tables
(Java 7 Programming Kogent Learning Solutions Inc)(Page nos. 551 to
561)
Separator: These are horizontal or vertical lines and they usually appear in
menus to separate options into logical groups.
Constructor.
JSeparator()
JSeparator(int orientation)
Constructor.
JTable(Object data[ ][ ], Object colHeads[ ])
Constructor.
JTree(Hashtable ht)
JTree(Object obj[ ])
JTree(TreeNode tn)
JTree(Vector v)
Toggle Button: They are two state buttons that can appear as selected or
delected.
Constructors.
JToggleButton()
32
JToggleButton(Action a)
JToggleButton(Icon icon)
JToggleButton(String text)
JToggleButton(String text, boolean selected)
JToggleButton(String text, Icon icon)
JToggleButton(String text, Icon icon, boolean selected)
16 Revision
Learning Resources:
Books:
Title: Books:
1. Complete Reference Herbert Schildt 5th Edition Mc Graw Hill
2. Java EE6 for Beginners Sharnam Shah & Vaishali Shah SPD
3. Advanced JAVA Kogent learning Solution DreamTech Press
4. Java server Programming Black Book Kogent learning Solution DreamTech Press
Teaching Aids:
Black board, chalk, Transparencies, PowerPoint presentations, References, Books,
notes, LCD Projector.
33
PPTs:
1. www.cs.kau.se/cs/education/courses/davd11/.../java_event_handling.ppt
2. web.njit.edu/~gblank/cs602/GUI%20Event%20Handling.ppt
Websites
1. www.tutorialspoint.com/awt/awt_event_handling.htm
2. www.studytonight.com/java/event-handling-in-java.php
A source generates an event and sends it to one or more listeners. In this scheme, the
listener simply waits until it receives an event. Once received, the listener processes
the event and then returns. The advantage of this design is that the application logic
that processes events is cleanly separated from the user interface logic that generates
those events.
Event Sources
A source is an object that generates an event. This occurs when the internal state of
that object changes in some way
Event Listeners
A listener is an object that is notified when an event occurs. It has two major
requirements. First, it must have been registered with one or more sources to receive
notifications about specific types of events. Second, it must implement methods to
receive and process these notifications.
Event classes
The classes that represent events are at the core of Java’s event handling mechanism.
34
3 The Mouse Event class
These are generated by text fields and text areas when characters are entered by a user
or program
The Window Event class.
The delegation event model has two parts: sources and listeners. Listeners are created
by implementing one or more of the interfaces defined by the java.awt.event package.
When an event occurs, the event source invokes the appropriate method defined by the
listener and provides an event object as its argument.
The ActionListener Interface
This interface defines the actionPerformed( ) method that is invoked when an action
event occurs. Its general form is shown here:
void actionPerformed(ActionEvent ae)
The ComponentListener Interface
This interface defines four methods that are invoked when a component is resized,
moved, shown, or hidden. Their general forms are shown here:
void componentResized(ComponentEvent ce)
void componentMoved(ComponentEvent ce)
void componentShown(ComponentEvent ce)
void componentHidden(ComponentEvent ce)
The ContainerListener Interface
35
6 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.
void keyPressed(KeyEvent ke)
void keyReleased(KeyEvent ke)
void keyTyped(KeyEvent ke)
36
focus. Their general forms are shown here.
void windowGainedFocus(WindowEvent we)
void windowLostFocus(WindowEvent we)
Adapter class can simplify the creation of event handlers in certain situations.
An adapter class provides an empty implementation of all methods in an event
listener interface. Adapter classes are useful when you want to receive and
process only some of the events that are handled by a particular event listener
interface.
10 2.3 The Inner classes
(Complete reference Java 2 – 5th Edition) (page nos 682 to 685)
Inner class is a class defined within other class, or even within an expression.
After covering AWT components, a teacher may cover the portion of event handling
from second chapter. Remaining portion of chapter 1 may be covered after event
handling so that students may get more exposure to application and remember level
questions
Topic Name: Networking & Security
III Specific Objectives: (As per Curriculum)
1. To learn the java’s built in support for network programming
2. To write program to demonstrate the connectivity through software sockets,
TCP. IP, URL and java security packages.
37
APPLICATI Chat Use of appropriate PPT
ON Applicaio
n
Learning Resources:
Books:
Title: Books:
1. Complete Reference Herbert Schildt 5th Edition Mc Graw Hill
2. Java EE6 for Beginners Sharnam Shah & Vaishali Shah SPD
3. Advanced JAVA Kogent learning Solution DreamTech Press
4. Java server Programming Black Book Kogent learning Solution DreamTech
Press
Teaching Aids:
Black board, chalk, Transparencies, PowerPoint presentations, References, Books,
notes, LCD Projector.
Lectur
e Topic/ Subtopic to be covered
No.
1 Basics of Networking
Socket, IP, TCP, UDP, Proxy Server, Internet Addressing
Socket Overview, Client/Server ,Reserved Sockets ,Proxy Servers ,Internet
Addressing
Socket: A socket can be used to connect Java’s I/O system to other programs that
may reside either on the local machine or on any other machine on the Internet.
TCP: Transmission Control Protocol (TCP) is a higher-level protocol that
manages to robustly string together these packets, sorting and retransmitting
them as necessary to reliably transmit your data.
UDP :A third protocol, User Datagram Protocol (UDP), sits next to TCP and can
be used directly to support fast, connectionless, unreliable transport of packets.
Proxy Server: A proxy server speaks the client side of a protocol to another
server. This is often required when clients have certain restrictions on which
servers they can connect to.
Thus, a client would connect to a proxy server, which did not have such
restrictions, and the proxy server would in turn communicate for the client. A
proxy server has the additional ability to filter certain requests or cache the
results of those requests for future use.
38
www.cse.unr.edu/~mgunes/cpe401/cpe401sp09/Lecture11.ppt
http://docs.oracle.com/javase/7/docs/api/java/net/class-use/InetAddress.html
http://docs.oracle.com/javase/7/docs/api/java/net/class-use/InetAddress.html
4 TCP/IP Sockets
TCP/IP sockets are used to implement reliable, bidirectional, persistent, point-to-
point, stream-based connections between hosts on the Internet.
Server Socket
The ServerSocket class is designed to be a “listener,” which waits for clients to
connect before doing anything. The Socket class is designed to connect to server
sockets and initiate protocol exchanges.
http://www.cs.rutgers.edu/~pxk/rutgers/notes/sockets/
TCP/IP Sockets Methods
A socket can be examined at any time for the address and port information
associated with it, by use of the following methods:
InetAddress getInetAddress( ) Returns the InetAddress associated with the
Socket object.
int getPort( ) Returns the remote port to which this Socket
object is connected.
int getLocalPort( ) Returns the local port to which this Socket object
is connected.
(Complete reference Java 2 – 5th Edition) (page nos 594 to 595)
http://www.tutorialspoint.com/java/java_networking.htm
39
5 URL: The URL provides a reasonably intelligible form to uniquely identify or
address information on the Internet. URLs are ubiquitous; every browser uses
them to identify information on the Web.
Two examples of URLs are http://www.osborne.com/ and
http://www.osborne.com:80/index.htm.
URL Connection: URL Connection is a general-purpose class for accessing the
attributes of a remote resource. Once you make a connection to a remote server,
you can use URL Connection to inspect the properties of the remote object
before actually transporting it locally.
These attributes are exposed by the HTTP protocol specification and, as such,
only make sense for URL objects that are using the HTTP protocol.
http:http is the protocol that web browsers and servers use to transfer hypertext
pages and images. It is quite a simple protocol for a basic page-browsing web
server.
URLConnection methods: URLConnection is a general-purpose class for
accessing the attributes of a remote resource. Once you make a connection to a
remote server, you can use URLConnection to inspect the properties of the
remote object before actually transporting it locally.
openConnection( )
(Complete reference Java 2 – 5th Edition) (page nos 597 to 601)
www.cse.unr.edu/~mgunes/cpe401/cpe401sp09/Lecture11.ppt
40
length of 50.
ServerSocket(int port, int maxQueue): Creates a server socket on the specified
port with a maximum queue length of maxQueue.
ServerSocket(int port, int maxQueue,InetAddress localAddress):Creates
a server socket on the specified port with a maximum queue length of
maxQueue. On a multihomed host,
localAddress specifies the IP address to which this socket binds.
(Complete reference Java 2 – 5th Edition) (page nos 601 to 602)
http://www.bogotobogo.com/Java/tutorial/tcp_socket_server_client.php
http://docstore.mik.ua/orelly/java-ent/jnut/ch17_01.htm
Revision
8
Topic Name: Interacting with Database
IV Specific objectives(as mentioned in curriculum)
1. To create database driven business applications using the database API’S two tier and
three tier models and the Java.sql package.
Additional objectives
Able to write and execute the program.
41
Types of Methods of ResultSet, Statement interface and
drivers prepared statement interface
All types of drivers.
http://www.javatpoint.com/PreparedStatement-
interface
http://www.tutorialspoint.com/jdbc/jdbc-
statements.htm
Write the program using statement and
Stepwise
preapared statement interface in classroom
procedure to
PROCEDURE write code
and execute
the java
program
e.g. Railway Useful in client server and web Application.
Reservation Practice the MCQ’s in Laboratory.
APPLICATION System, Practice the program in Laboratory.
banking
System etc.
Reference Material:
Books: -
Title 1) Advanced Java ,Kogent learning Solution,Dream The Press
2)Java EE6 for Beginners , Sharnam Shah &Vaishali Shah, SPD
3) Java Server Programming Black Book, Kogent learning Solution, DreamTech
Press
Teaching Aids:
Websites:
http://docs.oracle.com/javase/tutorial/jdbc/overview/
Lectur
e Topic/ Subtopic to be covered
No.
1 4.1 JDBC,ODBC and Others APIS
42
programming activities:
o Connect to a data source, like a database
o Send queries and update statements to the database
o Retrieve and process the results received from the database in
answer to your query
43
Client layer: Here we design the form using textbox, label etc.
Business layer:
It is the intermediate layer which has the functions for client layer
It is used to make communication faster between client and data
layer.
It provides the business processes logic and the data access.
When one tier fails there is no data loss, because you are always secure by accessing
the other tier
Disadvantages of three tier Architecture
It is more complex structure
More difficult to set up and maintain it as well
3 Types of driver
44
Type1(Jdbc-Odbc Bridge driver)
Jdbc-Odbc Bridge driver converts JDBC call to ODBC calls .
ODBC is an open standard API to communicate with database.
It enables a java application to use any database that supports
ODBC driver .
It is an interface between java application and the ODBC driver.
It is usually used in stand-alone application.
Type2(Java to Native API)
It uses the local native libraries provided by the database vendors
to access databases.
It does not have an ODBC intermediate layer.
it is used for network-based application.
Type3(Java to network protocol)
It translates the JDBC calls into a database-server-independent
and middleware server-specific calls.
With the help of middleware server, the translated JDBC calls are
further translated into database server specific calls.
Type4(Java to Database Protocol)
It is pure java driver, which implements the database protocol to
interact directly with a database.
It does not require any native database library to retrieve the
records from the database.
. It translates JDBC calls into database specific network calls.
45
Syntax:intexecuteUpdate(String str);
e..g.
Statement st=con.createStatement();
String str=”insert into table1 values(11,’xyz’)”;
int count=st.executeUpdate(str);
Methods Description
boolean first() Shift the control of a result set cursor to
the first row of the result set
booleanisFirst() Determines whether the result set cursor
points to the first row of the result set
Boolean beforeFirst() Shift the control of a result set cursor
before the first row of the result set
booleanisBeforeFirst() Determines whether the result set cursor
points before the first row of the result
set
Boolean last() Shift the control of a result set cursor to
the last row of the result set.
Syntax:booleanexecute(String str)
Statement st=con.createStatement();
String str=”create table product (prod_idint , prod_name char) ”;
st.execute(str);
46
PreparedStatement object allows to pass runtime parameters to the SQL
Statements to query and modify the data in a table
The prepareStatement() method of Connection object take an SQL Statement as
a parameter.The sql statement can contain ‘?’ symbol as a place holder that can
be replaced by input parameters at runtime.
Methods of prepared statement
intexecuteUpdate();
ResultSetexecuteQuery();
Boolean execute()
Methods Description
Void setByte(int index, byte value) Set the java byte type value for the
parameter corresponding to index passed as
parameter.
Void setBoolean(int index, boolean Set the java Boolean type value for the
value) parameter corresponding to index passed as
parameter.
Void setDouble(int index, double Set the java double type value for the
value) parameter corresponding to index passed as
parameter.
Void setInt(int index, int value) Set the java int type value for the parameter
corresponding to index passed as parameter.
Void setString(int index, string value) Set the java string type value for the
parameter corresponding to index passed as
parameter.
(Java 7 Programming Kogent Learning Solutions Inc)(Page nos. 1002, 1015)
47
Knowledge Example Teaching methodology
Category /s of
category
FACT Definitio Use of appropriate PPT
n of www.calstatela.edu/faculty/areed2/CIS561/PPTs/Chapter
Servlet 5Slides.ppt
CONCEPT Types of Use of appropriate PPT
Servlet www.calstatela.edu/faculty/areed2/CIS561/PPTs/Chapter
5Slides.ppt
PROCEDUR Life Use of appropriate PPT;
E Cycle of www.calstatela.edu/faculty/areed2/CIS561/PPTs/Chapter
Servlets, 5Slides.ppt
Steps Refer manual experiment number 14 for steps for
for execution of program
executio
n of
Progra
m
APPLICATI Designin Show working of websites like www.flipkart.com, online
ON g cricket score, share market.
websites
like
flipkart,
amazon
for
online
shoppin
g, online
cricket
Learning Resources:
Books:
Title:
1. Complete Reference Herbert Schildt 5th Edition Mc Graw Hill
2. Java EE6 for Beginners Sharnam Shah & Vaishali Shah SPD
3. Advanced JAVA Kogent learning Solution DreamTech Press
4. Java server Programming Black Book Kogent learning Solution DreamTech Press
Teaching Aids:
Black board, chalk, Transparencies, PowerPoint presentations, References, Books, notes,
LCD Projector.
48
Lect Topic/ Subtopic to be covered
ure
No.
5.1 Servlet
Everyone things of purchasing of some material from online shopping
sites.Designing such site can be done with the help of servlets. So servlets are
useful for designing web based applications. Type of Servlets:
In the early days of the Web, a server could dynamically construct a page by
creating a separate process to handle each client request. The process would open
connections to one or more databases in order to obtain the necessary
information. It communicated with the Web server via an interface known as the
Common Gateway Interface (CGI).
CGI allowed the separate process to read data from the HTTP request and write
data to the HTTP response. A variety of different languages were used to build
CGI programs.
These included C, C++, and Perl.
Servlets offer several advantages in comparison with CGI. First, performance is
significantly better. Servlets execute within the address space of a Web server. It
is not necessary to create a separate process to handle each client request. Second,
servlets are platform-independent because they are written in Java. A number of
Web servers from different vendors offer the Servlet API. Programs developed
for this API can be moved to any of these environments without recompilation.
Third, the Java security manager on the server enforces a set of restrictions to
protect the resources on a server machine. You will see that some servlets are
trusted and others are untrusted.
49
plete referencce Java 2 – 5th Edition) (ppage nos 951))
(Comp
2 5.2 Using
U servletts, response redirection
n.
50
(Complete reference Java 2 – 5th Edition) (page nos 961 to 962)
Session:
After completion of work with mail account, user of that account performs sign
out. So time taken by an account holder from sign in to sign out is called as
session.
Describe HttpSessionEvent Class and HttpSessionBindingEvent Class and there
methods
Pg nos. 971
Cookies:
A cookie is stored on a client and contains state information. Cookies are
valuable for tracking user activities. For example, assume thata user visits an
online store. A cookie can save the user’s name, address, and otherinformation.
The user does not need to enter this data each time he or she visits the store.
A servlet can write a cookie to a user’s machine via the addCookie( ) method of
the HttpServletResponse interface. The data for that cookie is then included in the
header of the HTTP response that is sent to the browser.
(Complete reference Java 2 – 5th Edition) (page nos 976 to 978)
5 Session tracking:
Administrator of a system can keep tracking of users on any computer. Person can
keep record ofwho has used the computer.This task can be achieved using concept of
session tracking.
51
http://docstore.mik.ua/orelly/java-ent/servlet/ch02_05.htm
http://books.google.co.in/books?id=YUXyUmGpAh8C&pg=PA383&source=gbs_toc_r
&cad=2#v=onepage&q&f=false
Compilation
Initialization
Execution
Cleanup
The four major phases of JSP life cycle are very similar to Servlet Life Cycle and they are as follows:
52
JSP Compilation:
When a browser asks for a JSP, the JSP engine first checks to see whether it needs to compile the page. If
the page has never been compiled, or if the JSP has been modified since it was last compiled, the JSP
engine compiles the page.
JSP Initialization:
When a container loads a JSP it invokes the jspInit() method before servicing any requests. If you need to
perform JSP-specific initialization, override the jspInit() method:
publicvoidjspInit(){
// Initialization code...
}
Typically initialization is performed only once and as with the servlet init method, you generally initialize
database connections, open files, and create lookup tables in the jspInit method.
JSP Execution:
This phase of the JSP life cycle represents all interactions with requests until the JSP is destroyed.
Whenever a browser requests a JSP and the page has been loaded and initialized, the JSP engine invokes
the _jspService() method in the JSP.
The _jspService() method takes an HttpServletRequest and an HttpServletResponse as its parameters
as follows:
void _jspService(HttpServletRequest request,
HttpServletResponse response)
53
{
// Service handling
h cod
de...
}
The
T _jspServicee() method of a JSP is invoked once per a request and d is responsiblle for generatin
ng the
re
esponse for tha
at request and
d this method is
s also responssible for genera
ating responsees to all seven of the
HTTP
H methods ie. GET, POST T, DELETE etc c.
JSP
J Cleanup
p:
The
T destruction
n phase of the
e JSP life cyc
cle represents when a JSP is being remo
oved from use
e by a
container.
The
T jspDestroy y() method is the
t JSP equiv
valent of the d estroy method
d for servlets. Override jspD Destroy
when
w you need to perform any
y cleanup, such
h as releasing d
database conn
nections or clossing open files.
The
T jspDestroy(() method has the
t following fo
orm:
publicvoidjs
p spDestroy()
{
// Your clea
anup code go
oes here.
}
Please
P see:htttp://www.tutorialspoin nt.com/jsp/jjsp_life_cyccle.htm
JAVABeans
J s:( Only intrroduction)
JavaBeans is an object-orriented programming intterface fromm Sun Microssystems that lets
you
y build re-u useable appllications or program
p buiilding blockss called com
mponents thatt can
be
b deployed ini a networkk on any major operatingg system plattform.
This
T is an exa
ample of a sim
mple JavaBe
ean type with
h the propertiies int age
e and Strin
ng
color
c .
Code listing 9.12: Puppy
y.java
1.
1 class Puuppy imple a.io.Seria
ementsjava alizable{
2.
2
3.
3
4.
4
5.
5 privatesstaticfina ialVersion
allongseri nUID= 3486652158488L
L;
6.
6
7.
7
8.
8
9.
9 privateSString collor;
10.
1
11.
1
12.
1
13.
1 teint age;
privat ;
14.
1
15.
1
16.
1
17.
1 cStringget
public tColor(){
18.
1
19.
1 n color;
return
54
20.
21. }
22.
23.
24.
25. publicvoidsetColor(String color){
26.
27. this.color= color;
28.
29. }
30.
31.
32.
33. publicintgetAge(){
34.
35. return age;
36.
37. }
38.
39.
40.
41. publicvoidsetAge(int age){
42.
43. this.age= age;
44.
45. }
46. }
a) The time table and sample test paper for the test should be displayed minimum 10 days
before the test.
b) Each test will be of 25 marks.
c) First test should cover about 40% of curriculum and second test should cover remaining
curriculum.
d) Format for question paper should be as per the sample question paper supplied by
MSBTE.
After completion of each chapter one assignment in the form of MCQs should be given.
Assignment question shall be given from sample question paper,.
It shall be assessed by subject teacher before giving next Assignment.
55
Evaluation of Assignment should be done effectively.
Sample question paper of Advanced Java Programming to be solved by every student
At the beginning of the semester teacher/lab assistant should check and ensure that the
Computers and JDK software used for the experiments is installed.
Before start of any practical Teachers should explain the specific objective of that
particular practical.
Teacher should divide total students into number of group as given in practical manual.
Teacher should refer the guidelines given in the lab manual.
Teacher should make the students aware of instructions given in the lab manual.
Teacher should ensure that the activities given in the Lab Manual are performed by the
student.
Teacher shall assess the performance of students continuously as per norms prescribed by
MSBTE CIAAN norms.
During assessment teacher is expected to ask questions to the students to tap their
achievements regarding related knowledge and skills so that students can prepare while
submitting record of the practical. Focus should be given on development of enlisted
skills rather than theoretical / codified knowledge.
56
. layout showing four buttons at four sides of an applet
with captions “left”, “right”, “top” and “bottom”.
Teacher shall explain working of Layout Manager and
30 Min.
types of layouts
Teacher shall demonstrate sample program on board. 30 Min.
Students should type and execute sample program on pc. 20 Min.
Group of two students should perform one allotted
40 Min.
programs from student activity.
Student should observe the output and get assessed by
30 Min.
teacher.
Students should write observations after execution of
30 Min.
programs and take the programs and attach in manuals.
Students should write answers to 3 questions allotted by
20 Min.
teacher.
Teacher should assess the experiment as per CPA table 40 Min.
6. Mode of assessment:
6.1.1Class Test:
There will be two tests each of 25 marks.
The tests will be conducted as per the MSBTE schedule.
Teacher should prepare model answer of class test question papers.
After completion of test, subject teacher should display model answer on
Department Notice Board.
Teacher should show the answer paper of class test to the student and discuss
about the mistakes.
Teacher should maintain the record of class test as per MSBTE norms
(CIAAN)
57
Scheme – G
Sample Question Paper Unit Test 1
Course Name: ‐ Computer Engineering Group
Course Code:‐ CO/CD/CM/CW/IF
Semester: ‐ Sixth
Subject Title: ‐ Advanced Java Programming
Marks: ‐ 25 Marks 17625
Q5. What is an event in delegation event model used by Java programming language? 1M
a) An event is an object that describes a state change in a source.
b) An event is an object that describes a state change in processing.
c) An event is an object that describes any change by the user and system.
58
d) An event is a class used for defining object, to create events.
Q6. Which of these methods are used to register a mouse motion listener? 1M
a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()
Q.7 Which of these methods can be used to determine the type of event? 1M
a) getID()
b) getSource()
c) getEvent()
d) getEventObject()
59
Q10. Select the missing statement in given code 2M
mouseX = 0;
mouseY = 10;
msg = "Mouse clicked.";
repaint();
}
// Handle mouse entered.
public void mouseEntered(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse entered.";
repaint();
}
// Handle mouse exited.
public void mouseExited(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse exited.";
repaint();
}
// Handle button pressed.
60
public void mousePressed(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Down";
repaint();
}
// Handle button released.
public void mouseReleased(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Up";
repaint();
}
// Handle mouse dragged.
public void mouseDragged(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "*";
showStatus("Dragging mouse at " + mouseX + ", " + mouseY);
repaint();
}
// Handle mouse moved.
public void mouseMoved(MouseEvent me)
{
showStatus("Moving mouse at " + me.getX() + ", " + me.getY());
}
// Display msg in applet window at current X,Y location.
public void paint(Graphics g)
{
g.drawString(msg, mouseX, mouseY);
}
}
a)addMouseListener(this);
b)addMouseListener(this);
addMouseMotionListener(this);
import java.awt.event.*;
c) addMouseListener();
d) all of above
61
Q11. Which of these events will be notified if scroll bar is manipulated? 2M
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent
importjava.awt.event.*;
import java.awt.*;
importjava.applet.*;
public class checkbackg extends Applet implements ItemListener
{
Checkbox m1,m2,m3;
public void init()
{
m1=new Checkbox("A");
m2=new Checkbox("B");
m3=new Checkbox("C");
add(m1);
add(m2);
add(m3);
m1.addItemListener(this);
m2.addItemListener(this);
}
</applet>*/
a)
62
b)
c)
d)
63
Q13. Select proper code for given output 2M
a) import java.awt.*;
import java.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/
b)
import java.awt.*;
import java.applet.*;
public class choice11 extends Applet
64
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
add(os);
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/
c) import java.awt.*;
import java.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}
d)
import java.awt.*;
import java.applet.*;
public class choice11 extends Applet
{
65
Q14. select the proper output for following code 2M
import java.awt.*;
import java.applet.*;
public class list2 extends Applet
{
public void init()
{
List l= new List(2,true);
l.add("java");
l.add("c++");
l.add("kkk");
add(l);
}
}
/*<applet code=list2.class height=200 width=200>
</applet>*/
a)
b)
c)
66
d)
import java.awt.*;
import javax.swing.*;
/*
<applet code="JTableDemo" width=400 height=200>
</applet>
*/
public class JTableDemo extends JApplet
{
public void init() {
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
final String[] colHeads = { "emp_Name", "emp_id", "emp_salary" };
final Object[][] data = {
{ "Ramesh", "111", "50000" },
{ "Sagar", "222", "52000" },
{ "Virag", "333", "40000" },
{ "Amit", "444", "62000" },
{ "Anil", "555", "60000" },
67
};
JTable table = new JTable(data);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(table, v, h);
contentPane.add(jsp, BorderLayout.CENTER);
}
}
a. Error in statement in which JTable is created
b. Error in statement in which JScrollPane is created
c. Error in statement in which applet tag is declared
d. None of the above
import java.awt.*;
import java.applet.*;
public class LayoutDemo5 extends Applet
{
public void init()
{
int i,j,k,n=4;
setLayout(new BorderLayout());
Panel p1=new Panel();
Panel p2=new Panel();
p1.setLayout(new FlowLayout());
p1.add(new TextField(20));
p1.add(new TextField(20));
p2.setLayout(new GridLayout(5,3));
p2.add(new Button("OK"));
p2.add(new Button("Submit"));
add(p1,BorderLayout.EAST);
add(p2,BorderLayout.WEST);
}
}
/*<applet code=LayoutDemo5.class width=300 height=400>
</applet>*/
A. The output is obtained in Frame with two layouts: Frame layout and Flow Layout.
B. The output is obtained in Applet with two layouts: Frame layout and Flow Layout.
C. The output is obtained in Applet with two layouts: Frame layout and Border Layout.
D. The output is obtained in Applet with two layouts: Border layout and Flow Layout.
68
Scheme – G
Sample Question Paper Unit Test 2
Course Name: ‐ Computer Engineering Group
Course Code:‐ CO/CD/CM/CW/IF
Semester: ‐ Sixth
Subject Title: ‐ Advanced Java Programming
Marks: ‐ 25 Marks 17625
Q 1.Which of these methods of DatagramPacket is used to find the port number? 1M
A. port()
B. getPort()
C. findPort()
D. recievePort()
Q5.What is servlet? 1M
A. Servlets are small program used for developing and executing web applications.
B. Servlets are small program used for database applications
C. Servlets are used for intranet programming
D. Servlets are programs written in C and C++
69
Q6.Which of these is a return type of getAddress() method of DatagramPacket class?
2M
A. DatagramPacket
B. DatagramSocket
C. InetAddress
D. ServerSocket
Q.7 Select the proper method to retrieve the host name of local machine. 2M
Q11. Consider the following program what will be displayed in the output? 2M
import java.net.*;
class myAddress
{
public static void main (String args[])
{
70
try
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
}
catch (UnknownHostException e)
{
System.out.println("Could not find this computer's address.");
}
}
}
Q12. Choose the correct option to establish a connection to database named student
and display its contents. 2M
A.
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
B.
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
71
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
C.
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
D.
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
72
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(1)+" \t \t"+rs.getDouble(1));
}
s.close();
c.close();
}
}
import java.sql.*;
public class db15
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN","","");
PreparedStatement s=c.prepareStatement( "update db3 set Name=? where Roll_no=?");
Statement s=c.createStatement( );
s.setString(1,*);
s.setString(2,*);
s.setString(3,*);
s.executeUpdate();
73
C. public static Connection getConnection(String url, String name, String password) throws
SQLException
D. public static Connection getConnection(String url, String name) throws SQLException
<html>
<body>
<center>
<form name="Form1"
action="http://localhost:8080/servlets-examples/ColorGetServlet">
<B>Color:</B>
<select name="color" size="1">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<br><br>
<input type=submit value="Submit">
</form>
</body>
</html>
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
74
After clicking on Submit button :
16. A JSP page called test.jsp is passed a parameter name in the URL
using http://localhost/test.jsp?name="John". The test.jsp contains the
following code.
<%! String myName=request.getParameter();%>
<% String test= "welcome" + myName; %>
<%= test%>
A. The program prints "Welcome John"
B. The program gives a syntax error because of the statement
<%! String myName=request.getParameter();%>
C. The program gives a syntax error because of the statement
<% String test= "welcome" + myName; %>
D. The program gives a syntax error because of the statement
<%= test%>
75
MSBTE Sample Question Paper
Course Name: Computer Engineering Group
Course Code: CO/CM/CD/IF/CW Semester: SIXTH
Subject:- ADVANCED JAVA PROGRAMMING Subject Code :-(17085)
Marks:- 100 Hours :- 2 Hrs
Remember Level 1M
Chapter 1
1. Which class can be used to represent the Checkbox with a textual label that can appear
in a menu?
A. MenuBar
B. MenuItem
C. CheckboxMenuItem
D. Menu
76
7. Which of the following is not a constructor of JTree
A. JTree(Object obj[])
B. JTree(TreeNodetn)
C. JTree(Vector v)
D. JTree(int x)
Chapter 2
1. Which of these methods is used to obtain the object that generated a WindowEvent?
A. getMethod()
B. getWindow()
C. getWindowEvent()
D. getWindowObject()
Chapter 3
1. Which of these is a return type of getAddress method of DatagramPacket class?
A. DatagramPacket
B. DatagramSocket
C. InetAddress
D. ServerSocket
2. In the format for defining the URL what is the last part?
A. Protocol.
B. File path.
C. Port number.
77
D. Host name.
3. What is the first part of URL address?
A. Host name.
B. Port number.
C. File path.
D. Protocol.
4. Which of these methods of DatagramPacket is used to obtain the byte array of data
contained in a datagram?
A. getData()
B. getBytes()
C. getArray()
D. recieveBytes()
Chapter 4
1. Native – protocol pure Java converts ……….. in to the ………… used by DBMSs
directly.
A. JDBC calls, network protocol
B. ODBC class, network protocol
C. ODBC class, user call
D. JDBC calls, user call
3. For execution of DELETE SQL query in JDBC, ............. method must be used.
A. executeQuery()
B. executeDeleteQuery()
C. executeUpdate()
D. executeDelete()
Chapter 5
1. Name the class that includes the getSession() method that is used to get the HttpSession
object
A. HttpServletRequest
B. HttpServletResponse
C. SessionContext
78
D. SessionConfiig
4. in a web
w applicatiion, running
g in a webseerver, who iis responsib
ble for creatting requestt and
responsee object,
A. Web
W server
B. Servlet
C. Container
C
D. Client
C
Undersstand Leveel 2M
M
Chapterr 1
1. Which
W comp
ponents are used in the following ooutput?
A. Label,
L TextFiield, Button
79
B. Applet,
A Labell
C. Applet,
A Butto
on
D. G Layout, Label, Butto
Grid on
3. Which
h method is used to disp play icon on
n a componeent?
A. ro
ollOverIcon((ImageIcon i)i
B. seetIcon(ImageIcon i)
C. displayIcon(IImageIcon i))
D. reemoveIcon (ImageIconi
( )
4. Which componen
nts will be needed
n to geet following output?
A. Label,
L TabbedPane, ChecckBox
B. TabbedPane,
T List, Applett
C. Panel, Tabbed
dPane, List
D. Applet,
A TabbedPane, Pannel
Chapterr 2
importjavva.awt.*;
importjavva.applet.*;
/*
<applet code="mous
c e" width=30
00 height=10
00>
</applet>
>
*/
public claass mouse extends
e Applet implemennts MouseListener, MouuseMotionLiistener
{
String mssg = "";
intmouseeX = 0, mousseY = 0
public vo
oid init()
{
80
}
public void mouseClicked(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse clicked.";
repaint();
}
public void mouseEntered(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse entered.";
repaint();
}
public void mouseExited(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse exited.";
repaint();
}
public void mousePressed(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Down";
repaint();
}
public void mouseReleased(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Up";
repaint();
}
public void mouseDragged(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "*";
showStatus("Dragging mouse at " + mouseX + ", " + mouseY);
repaint();
}
public void mouseMoved(MouseEvent me)
{
showStatus("Moving mouse at " + me.getX() + ", " + me.getY());
}
public void paint(Graphics g)
81
{
g.drawSttring(msg, mouseX,
m mou
useY);
}
}
a) addMMouseMotion nListener(thhis);
b) addM MouseListeneer(this);
c) imporrt java.awt.eevent.*;
d) all of above
a))
b)
82
c))
d)
3. To
T get the fo
ollowing outtput complete the code given below
w.
83
im
mport java.aw wt.*;
im
mport javax.swing.*;
/*
*
<applet
< code= ="jscroll" wiidth=300 heiight=250>
</applet>
<
*//
puublic class jsscroll extend
ds JApplet
{
puublic void in
nit()
{
Container
C conntentPane = getContentP Pane();
co
ontentPane.ssetLayout(neew BorderLaayout());
}
}
nt v = ScrollP
in PaneConstan nts.VERTIC CAL_SCROL LLBAR_AL
LWAYS;
in
nt h = ScrollP PaneConstan nts.HORIZO ONTAL_SCR ROLLBAR__AS_NEED
DED;
JS
ScrollPanejssp = new JSccrollPane(jp,, v, h);
co
ontentPane.aadd(jsp, BorrderLayout.C CENTER);
}
}
A)
A Containerr contentPanne = getContentPane();
contentPaane.setLayou
ut(new GridL
Layout());
B)
B JPaneljp = new JPaneel();
jp.setLayo
out(new GridLayout(20,, 20));
C)
C int b = 0;
for(int i = 0; i < 20; i+
++) {
for(int j = 0; j < 20; j+
++) {
84
jp.add(new JButton("Button " + b));
++b;
Chapter 3
1. Select the proper method to retrieve the host name of local machine
85
{
System.out.println("Could not find this computer's address.");
}
}
}
Chapter 4
Chapter 5
86
3. Differencee between doGet()
d and doPost() mmethods is_____________________. S Select
any of given options
A.
A In doG
Get() the parrameters are appended too the URL annd sent alonng with headeer
inform
mation.
B.
B In doP
Post(),will seend the inforrmation throough a sockeet back to thee webserver and
itt won't show
w up in the URL bar.
C.
C doGett() is a requeest for inform
mation;
D.
D doPosst() provides information n (such as pl acing an ordder) that the server is
expected to remem mber
A.
A All ab
bove are vallid differencces
B.
B Only A and B
C.
C Only C and D
D.
D A, B, C are valid
d differencess.
Apply
A Level M
2M
Chapter
C 1
A.
A
im
mportjava.aw wt.*;
im
mportjava.ap pplet.*;
puublic class app1
a extendss Applet
{
puublic void in
nit()
{
87
TextFieldtf = new TextField();
TextArea t1=new TextArea(3,20);
Checkbox c=new Checkbox("a",true);
Checkbox c1=new Checkbox("b",false);
add(t1);
add(c);
add(tf);
add(c1);
}
}
/*<applet code=app1.class width=200 height=200>
</applet>*/
B.
importjava.awt.*;
importjava.applet.*;
public class app1 extends Applet
{
public void init()
{
TextFieldtf = new TextField();
TextArea t1=new TextArea(3,20);
Checkbox c=new Checkbox("a",true);
Checkbox c1=new Checkbox("b",false);
add(tf);
add(t1);
add(c);
add(c1);
}
}
/*<applet code=app1.class width=200 height=200>
</applet>*/
C.
importjava.awt.*;
importjava.applet.*;
public class app1 extends Applet
{
public void init()
{
TextFieldtf = new TextField();
TextArea t1=new TextField();
Checkbox c=new Checkbox("a",true);
Checkbox c1=new Checkbox("b",false);
88
add(tf);
add(t1);
add(c);
add(c1);
}
}
D. All of above
importjava.awt.*;
importjavax.swing.*;
/*
<applet code="JTableDemo" width=400 height=200>
</applet>
*/
public class JTableDemo extends JApplet
{
public void init() {
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
final String[] colHeads = { "emp_Name", "emp_id", "emp_salary" };
final Object[][] data = {
{ "Ramesh", "111", "50000" },
{ "Sagar", "222", "52000" },
{ "Virag", "333", "40000" },
{ "Amit", "444", "62000" },
{ "Anil", "555", "60000" },
};
JTable table = new JTable(data);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPanejsp = new JScrollPane(table, v, h);
contentPane.add(jsp, BorderLayout.CENTER);
}
}
A. Error in statement in which JTable is created
B. Error in statement in which JScrollPane is created
C. Error in statement in which applet tag is declared
D. None of the above
89
/*
<applet code="combodemo11" width=300 height=100>
</applet>
*/
public class combodemo11 extends JApplet
{
public void init()
{
Container co = getContentPane();
co.setLayout(new FlowLayout());
JComboBoxjc=new JComboBox();
jc.addItem("cricket");
jc.addItem("football");
jc.addItem("hockey");
jc.addItem("tennis");
co.add(jc);
}
}
A. Javac combodemo11.java
B. java combodemo11
C. appletviewer combodemo11.java
D. All of above
importjava.awt.*;
importjava.applet.*;
public class LayoutDemo5 extends Applet
{
public void init()
{
inti,j,k,n=4;
setLayout(new BorderLayout());
Panel p1=new Panel();
Panel p2=new Panel();
p1.setLayout(new FlowLayout());
p1.add(new TextField(20));
p1.add(new TextField(20));
p2.setLayout(new GridLayout(5,3));
p2.add(new Button("OK"));
p2.add(new Button("Submit"));
90
dd(p1,BordeerLayout.EA
ad AST);
ad
dd(p2,BordeerLayout.WE
EST);
}
}
/*
*<applet cod
de=LayoutDemo5.class width=300
w hheight=400>
>
</applet>*/
<
E.
E The outpu
ut is obtained
d in Frame with
w two layoouts: Frame layout and F Flow Layouut.
F. The outpu
ut is obtained
d in Applet with
w two layyouts: Framee layout and Flow Layouut.
G.
G The outpu
ut is obtained
d in Applet with
w two layyouts: Framee layout and Border Layoout.
H.
H The outpu
ut is obtained
d in Applet with
w two layyouts: Bordeer layout andd Flow Layouut.
Chapter
C 2
A.
A
im
mportjava.aw wt.*;
im
mportjava.ap pplet.*;
puublic class choice11
c exteends Applet
{
puublic void in
nit()
{
Choice
C os=new Choice());
os.add("wnn1 18");
os.add("wnnx xp");
os.add("wnnn nt");
os.add("win 2000");
2
dd(os);
ad
}
}
*<applet cod
/* de="choice11" height=20 00 width=3000>
</applet>*/
<
91
B.
importjava.awt.*;
importjava.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
add(os);
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/
C.
importjava.awt.*;
importjava.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}
D.
importjava.awt.*;
importjava.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/
92
2. Select the miissing statem
ment in the program too get the folllowing outp
put
im
mportjava.aw wt.*;
im
mportjava.aw wt.event.*;
im
mportjavax.sswing.*;
/*
*
<applet
< code= ="combodem mo" width=3 300 height=1100>
</applet>
<
*//
pu ublic class combodemo
c extends JAp pplet
im
mplementsItemListener
{
JLLabeljl;
ImmageIconfraance, german ny, italy, japaan;
pu ublic void in
nit()
{
Container
C conntentPane = getContentP Pane();
co ontentPane.ssetLayout(neew FlowLay yout());
JCComboBoxjc = new JCo omboBox();
jcc.addItem("F France");
jcc.addItem("G Germany");
jcc.addItem("Italy");
jcc.addItem("JJapan");
jcc.addItemLisstener(this);
co ontentPane.aadd(jc);
co ontentPane.aadd(jl);
}
pu ublic void ittemStateChaanged(ItemE Eventie)
{
String s = (Sttring)ie.getItem();
jll.setIcon(neww ImageIcon n(s + ".gif"));
93
}
}
A. jl = new JLabel(new ImageIcon("star.gif"));
B. jl = new JLabel("star.gif");
C. jl = new JLabel( ImageIcon("star.gif"));
D. JLabel(new ImageIcon("star.gif"));
import java.awt.*;
public class MenuDemo extends Frame
{
public static void main(String args[])
{
MenuDemo m = new MenuDemo();
m.setVisible(true);
MenuBar mbr = new MenuBar();
m.setMenuBar(mbr);
Menu filemenu = new Menu("File");
Menu editmenu = new Menu("Edit");
Menu viewmenu = new Menu("View");
mbr.add(filemenu);
mbr.add(editmenu);
MenuItem new1 = new MenuItem("New");
MenuItem open1 = new MenuItem("Open");
filemenu.add(new1);
filemenu.add(open1);
}
}
A. mbr.add(view);
B. mbr.add(menu);
94
C. mbr.add(vieweditmenu);
D. mbr.add(viewmenu);
4. Consider the following output. Find the missing statement in the program.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
/*
<applet code="SimpleKey1" width=300 height=100>
</applet>
*/
public class SimpleKey1 extends JApplet
implements KeyListener
{
String msg = "";
int X = 10, Y = 20; public void init()
{
addKeyListener(this);
requestFocus();
}
public void keyPressed(KeyEvent ke)
{
showStatus("Key Down");
}
public void keyReleased(KeyEvent ke)
{
showStatus("Key Up");
public void keyTyped(KeyEvent ke)
{
msg += ke.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg, X, Y);
}
95
}
A. Missing Semicolon
B. }
C. {
D. ()
5. For the following code select the method that can be used to handle event.
importjava.awt.event.*;
import java.awt.*;
importjava.applet.*;
public class checkbackg extends Applet implements ItemListener
{
Checkbox m1,m2,m3;
public void init()
{
m1=new Checkbox("A");
m2=new Checkbox("B");
m3=new Checkbox("C");
add(m1);
add(m2);
add(m3);
m1.addItemListener(this);
m2.addItemListener(this);
}
A. actionPerformed(ActionEvent ae)
B. itemStateChanged(ActionEvent ie)
C. itemStateChanged(ItemEvent ie)
D. adjustmentPerformed(AdjustmentEvent ae)
Chapter 3
1. Consider the following program
What will be displayed in the output?
import java.net.*;
96
class myAddress
{
public static void main (String args[])
{
try
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
}
catch (UnknownHostException e)
{
System.out.println("Could not find this computer's address.");
}
}
}
Chapter 4
1. Consider the following program.
What should be the correction done in the program to get correct output?
import java.sql.*;
class Ddemo1
97
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
s.close();
c.close();
}
}
A. Missing semicolon
B. Missing {
C. Missing }
D. Missing statement.
A. Missing semicolon
B. Missing {
C. Missing }
D. Missing statement.
98
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception;
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. Error in main()
B. Error in loop
C. Error in connection statement
D. Error in close()
A. Missing semicolon
B. Missing {
C. Missing }
D. Missing package statement.
99
5. Consider the following program
Select the statement that should be added to the program to get correct output.
import java.sql.*;
public class db15
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN","","");
PreparedStatement s=c.prepareStatement( "update db3 set Name=? where Roll_no=?");
Statement s=c.createStatement( );
s.setString(1,args[0]);
s.setString(2,args[1]);
s.setString(3,args[2]);
ResultSet rs=s.executeQuery("select* from db3");
System.out.println("Name"+"\t"+"Roll no"+"\t"+"Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. s.executeUpdate()
B. c.createStatement( )
C. s.close()
D. c.close()
Chapter 5
1. Choose missing statements in following code from given options.
100
pw.println("Current date: " + date);
}
}
2. In following Java program fill statement showing ***.Select any one option fro
given options
import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throwsServletException, IOException
{
String data = request.getParameter("data");
Cookie cookie = ***************
response.addCookie(cookie);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
}
}
3. Consider the following program. Identify the exception that might be thrown
import java.net.*;
class URLDemo
{
public static void main(String args[]) throws ______________________
{
URL netAddress= new URL(“http://www.sun.com:8080//index.html”);
System.out.println(“Protocol :”+netAddress.getProtocol());
System.out.println(“Port :”+netAddress.getPort());
System.out.println(“Host :”+netAddress.getHost());
101
System.out.println(“File :”+netAddress.getFile());
}
}
A. IoException
B. MalformedURLException
C. Arithmetic Exception
D. UnknownHostException
4. Consider the following program. Identify the missing statement from the output.
import java.net.*;
class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
URL netAddress= new URL(“http://www.sun.com: //index.html”);
System.out.println(“Protocol :”+netAddress.getProtocol();
System.out.println(“Port :”+netAddress.getPort());
System.out.println(“Host :”+netAddress.getHost());
System.out.println(“File :”+netAddress.getFile());
}
}
A. Port :8080
B. Port :1024
C. Port: -1
D. None of the above
class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
URL netAddress= new URL("http://www.sun.com:/index.html");
System.out.println("Protocol :"+netAddress.getProtocol());
System.out.println("Port :"+netAddress.getPort());
System.out.println("Host :"+netAddress.getHost());
System.out.println("File :"+netAddress.getFile());
}
}
A. Missing semicolon
B. Missing package statement
102
C. Missing initialization
D. None of the above
103
6.2.3 Answer Key
Answer key for Unit test I
1. Answer : C: remove()
2. Answer: A: Controls or components allow users to interact with application
3. Answer: A: Windows, Panel, ScrollPane
4. Answer :A: CheckboxGroup
5. Answer: A : An event is an object that describes a state change in a source.
6. Answer: C: addMouseMotionListner()
7. Answer: A getID()
8. Answer: B: List, Button
9. Answer : C: Panel, TabbedPane, List
10. Answer: B: addMouseListener(this);
addMouseMotionListener(this);
import java.awt.event.*;
11. Answer:C:AdjustmentEvent
12. Answer: B
13. Answer: A:
import java.awt.*;
import java.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}
104
/*<applet code="choice11" height=200 width=300>
</applet>*/
14. Answer: C:
105
Answer key for Unit test II
1. Answer : B: getPort()
2. Answer: B: File path
3. Answer: C: Structured Query Language
4. Answer :D: Parametrized
5. Answer: A : Servlets are small program used for developing and executing web
applications.
6. Answer: C: InetAddress
7. Answer: A static InetAddressgetLocalHost( )throws UnknownHostException
8. Answer: D: All of above
9. Answer : B: d-a-e-b-c
10. Answer: C: Browser will interpret content as HTML source code.
11. Answer: C: The internet address of the host
12. Answer: A
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
106
Answer Key for AJP 100 marks Paper
Remember Level
Chapter 1
1. Answer: C: CheckboxMenuItem
2. Answer: A: Labels, Push buttons, Check boxes, Choice lists.
3. Answer: A: FlowLayout
4. Answer: A: AWT Components create a process where as Swing Component create a thread
5. Answer: D: setBorderLayout()
6. Answer: B: Cotent
7. Answer: D: JTree(int x)
8. Answer: B: Platform Independent
Chapter 2
1. Answer: B: getWindow()
2. Answer: B: getXCoordinate()
3. Answer: D: All of the mentioned
4. Answer: B: ComponentEvent
Chapter 3
1. Answer: C: InetAddress
2. Answer: B: File path.
3. Answer: D: Protocol.
4. Answer: A: getData()
Chapter 4
1. Answer: A: JDBC calls, network protocol
2. Answer: A: JDBC call, ODBC call
3. Answer: C: executeUpdate()
4. Answer: D: Parameterized
Chapter 5
1. Answer: A: HttpServletRequest
2. Answer: A: GET method
3. Answer: A: TCIP/IP
4. Answer: B: Servlet
Understand Level
Chapter 1
1. Answer: A: Label, TextField, Button
2. Answer: C: JTable object displays rows and columns of data.
3. Answer: B: setIcon(ImageIcon i)
4. Answer: C: Panel, TabbedPane, List
Chapter 2
1. Answer: D: All of the above.
107
2. Answer: C:
A
3. Answer: D:
A
JP
Paneljp = new
n JPanel(();
jp.setLay yout(new GridLayout(3
G 3,3));
int b = 0;
0
for(int i = 0; i <3; i++)
{
for(int j = 0; j <3; j++)
j
{
jp.add(new JButton n("Button " + b));
++b;
Chapter
C 3
1. Answer: A: static InetAdddressgetLocaalHost( )thro
ows Unknown nHostException.
2. Answer: D: All of above
3. Answer: A: ServerSocke et(int port, intt maxQueue))
4. Answer: C: The internett address of the host
Chhapter 4
1. Answer: B: ResultSet ob
bject
2. Answer: B: Statement
3. Answer: C: Integer
Chhapter 5
1. Answer: A: void service((ServletRequestreq, ServlletResponse rres)
2. Answer: B: JSP is web paage scripting language an d servlets aree Java prograams
3. Answer: A: All above are e valid differeences
App ply Level
Cha apter 1
108
1. Answer : B
importjava.awt.*;
importjava.applet.*;
public class app1 extends Applet
{
public void init()
{
TextFieldtf = new TextField();
TextArea t1=new TextArea(3,20);
Checkbox c=new Checkbox("a",true);
Checkbox c1=new Checkbox("b",false);
add(tf);
add(t1);
add(c);
add(c1);
}
}
/*<applet code=app1.class width=200 height=200>
</applet>*/
2. Answer : A: Error in statement in which JTable is created
3. Answer: C: appletviewer combodemo11.java
4. Answer: D: The output is obtained in Applet with two layouts: Border layout and Flow
Layout.
Chapter 2
1. Answer: A
importjava.awt.*;
importjava.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/
109
2. Answer: A: jl = new JLabel(new ImageIcon("star.gif"));
3. Answer: D: mbr.add(viewmenu);
4. Answer C: {
5. Answer: C: itemStateChanged(ItemEvent ie)
Chapter 3
1. Answer: C: The internet address of the host
2. Answer: D: Use of created object not correct
Chapter 4
1. Answer: C: Missing }
2. Answer: D: Missing statement.
3. Answer: A: Error in main()
4. Answer: D: Missing package statement.
5. Answer: A: s.executeUpdate()
Chapter 5
110