24ebcc205 Java
24ebcc205 Java
FMTH0301/Rev.5.3
Course Plan
Semester: 4 Semester Year: 2024-25
1
DEPARTMENT OF COMPUTER APPLICATIONS
2. Apply exception H M M
handling, Interfaces
and Inheritance
multithreaded concepts
to implement a given
scenario.
2
DEPARTMENT OF COMPUTER APPLICATIONS
PI Code: 2.4.2 Produces and validates results through skillful use of contemporary
computing tools and models.
Competency: 3.1 3.1 Demonstrate an ability to define a complex open-ended problem in
computing terms.
PI Code:3.1.1 3.1.1: Realize the necessity of good problem statements in the
design/development of solutions.
Competency: 3.2 Demonstrate an ability to generate a diverse set of alternative design
solutions
PI Code: 3.2.2 Build models, prototypes, etc., to develop diverse set of design
solutions.
Competency: 3.3 3.3 Demonstrate an ability to select the optimal design scheme for
further development.
PI Code:3.3.1 3.3.1 Apply formal multi-criteria decision-making tools to select
optimal computing design solutions.
Competency: 5.1 5.1Demonstrate an ability to identify/ create modern computing
tools, techniques and resources
PI Code: 5.1.1 5.1.1Identify modern computing tools, techniques and resources for
computing activities
Competency: 5.2 Select and apply domain-specific tools, techniques, and resources
PI Code:5.2.2 Demonstrate proficiency in using domain-specific tools
Competency: 7.1 Demonstrate an ability to identify gaps in knowledge and a strategy
to close these gaps
PI Code:7.1.2 Identify deficiencies or gaps in knowledge and demonstrate an ability
to source information to close this gap.
Competency: 13.1 Demonstrate computing skills relevant to application domain.
13.1
PI Code:13.1.1
Ability to design, develop software systems by considering
requirements, performance, integrity and security aspects of different
domains.
Eg: 1.2.3: Represents program outcome ‘1’, competency ‘2’ and performance indicator ‘3’.
3
DEPARTMENT OF COMPUTER APPLICATIONS
Chapter 1: Introduction
4
DEPARTMENT OF COMPUTER APPLICATIONS
5
DEPARTMENT OF COMPUTER APPLICATIONS
Chapter 3 Inheritance
6
DEPARTMENT OF COMPUTER APPLICATIONS
7
DEPARTMENT OF COMPUTER APPLICATIONS
Topics: Exception Fundamentals, try, catch, throw blocks, Throwing and Re-
throwing Exception, Exception subclasses.
Course Outcome- 02 Apply exception handling, Interfaces and Inheritance
multithreaded concepts to implement a given scenario .
8
DEPARTMENT OF COMPUTER APPLICATIONS
9
DEPARTMENT OF COMPUTER APPLICATIONS
Chapter 7: Collections
Topics: Collection Interfaces, Linked Lists, ArrayLists, Hash Sets, TreeSets, Object
Comparison, Queues and Dequeues, Priority Queues, Maps.
Course Outcome-CO 3 - Design and implement real-world applications using object-
oriented principles of java language.
10
DEPARTMENT OF COMPUTER APPLICATIONS
11
DEPARTMENT OF COMPUTER APPLICATIONS
Course Content
Content Hrs.
Unit – 1
Chapter 1: Introduction 5
Java Fundamentals, The History, and Philosophy of Java, Java’s Magic: The Byte
code, The Java Buzzwords, The Java Development Kit, A First Simple Program,
Data Types, Variables, Constants, Operators, Control Statements
Chapter 2: Introducing Classes, Objects, and Methods 8
Class Fundamentals, Object Creation, Reference Variables and Assignment,
Methods, Constructors and its types, the new Operator Revisited, Garbage
Collection, This Keyword, Java’s Access Modifiers, Pass Objects to Methods,
Method Overloading, Constructors Overloading, static keyword, Static Blocks,
Introducing Nested and Inner Classes.
Unit - 2
Chapter 3: Inheritance 6
Inheritance basics, constructors and Inheritance, understanding super keyword
and super class, creating a Multilevel Hierarchy, Superclass References and
Subclass Objects, Method Overriding, Using Abstract Classes, using final: To
prevent overriding and inheritance, Using final with Data Members, the Object
Class.
Chapter 4: Packages and Interfaces 6
Working with Package, packages and member access, Understanding Protected
Members, Importing Packages, Implementing Interfaces, Using Interface
References, default method example, Multiple Inheritance Issues, Use static
Methods in an Interface, Private Interface Methods.
Chapter 5: Exception Handling 5
The Exception Hierarchy, Exception Handling Fundamentals, Using Try and catch
blocks, the consequences of an uncaught exception, using multiple catch
statements, catching subclass exceptions, Throwing an Exception, Rethrowing an
Exception, A Closer Look at Throwable, Java’s Built-in Exceptions, Creating
Exception Subclasses.
Unit – 3
Chapter 6: Multithread Programming 5
Multithreading Fundamentals, The Thread Class and Runnable Interface, creating
a Thread, Creating Multiple Threads, Determining When a Thread Ends, Thread
Priorities, Synchronization, Using Synchronized Methods.
12
DEPARTMENT OF COMPUTER APPLICATIONS
Chapter 7: Collections 5
Collection Interfaces, Collection and Iterator Interfaces in the Java Library, Linked
Lists, Array Lists, Hash Sets, Tree Sets, Object Comparison, Queues and Dequeues,
Priority Queues, Maps.
Text Books
1. Herbert Schildt, Java: A Beginner’s Guide Ninth Edition, 9th Edition, McGraw Hill;
Eighth edition(2022).
2. Herbert Schildt, JAVA The Complete Reference 11th edition, Tata McGraw Hill 2019.
References
1. Kathy Sierra: Head First Java: A Brain-Friendly Guide, Third Edition, Shroff/O'Reilly;
Third edition (1 June 2022).
Evaluation Scheme
1. In Semester Assessment (ISA)
Assessment Marks
ISA- 1 20
ISA- 2 20
Activities 10
ISA 50
ESA 50
Total 100
13
DEPARTMENT OF COMPUTER APPLICATIONS
Unit I
1. Introduction 5 1 - 1 1
2. Introducing
Classes, Objects, 8 1 - 1 1
and Methods
Unit II
3. Inheritance 6 - 1 1 1
4. Packages and 6 - 1 1 1
Interfaces
5. Exception
5 - 1 1 1
Handling
Unit III
6. Multithread 5 - - 1 1
Programming
7. Collections 5 - - 1 1
Note:
1. Each Question carries 20 marks and may consist of sub-questions.
2. Mixing of sub-questions from different chapters within a unit (only for Unit I and Unit II)
is allowed in Minor I, II and ESA
3. Answer 5 full questions of 20 marks each (two full questions from Unit I, II and one
full question from Unit III) out of 8 questions in ESA.
14
DEPARTMENT OF COMPUTER APPLICATIONS
15
DEPARTMENT OF COMPUTER APPLICATIONS
Learning Outcomes: -
At the end of the topic, the student should be able to:
Lesson Schedule
Class No. - Portion covered per hour
1. Java Fundamentals, The History and Philosophy of Java,
2. The Byte code, The Java Buzzwords,
3. The Java Development Kit, A First Simple Program,
4. Data Types, Variables, Constants,
5. Operators, Control Statements
Review Questions
[Link]. - Questions TLOs BL PI Code
1. Explain JDK. Which part of JVM will allocate memory
TLO1 L2 5.2.2
for Java program?
2. Write a Java Program to Read the Number from
TLO2 L3 1.3.1
Standard Input.
3. What are Data Types? Explain different types of Data TLO1 L2 1.3.1
Types with examples.
4. Write a Java Program to Swap Two values using third TLO2 L3 5.2.2
variable
16
DEPARTMENT OF COMPUTER APPLICATIONS
Learning Outcomes: -
At the end of the topic the student should be able to:
Lesson Schedule
Class No. - Portion covered per hour
1. Class Fundamentals, Object Creation,
2. Reference Variables and Assignment,
3. Methods, Constructors and its types,
4. the new Operator Revisited, Garbage Collection, This Keyword,
5. Java’s Access Modifiers, Pass Objects to Methods,
6. Method Overloading, Constructors Overloading,
7. static keyword, Static Blocks,
8. Introducing Nested and Inner Classes.
Review Questions
[Link]. - Questions TLOs BL PI Code
1. How do you design classes and instantiate them in Java?
TLO1 L2 1.3.1
Give code example.
17
DEPARTMENT OF COMPUTER APPLICATIONS
Learning Outcomes: -
At the end of the topic, the student should be able to:
Topic Learning Outcomes COs BL CA Code
1. Design and build classes on the concept of Inheritance CO2 L3 3.2.1
2. Design and Implementing Method Overloading and Method
Overriding with the support of Polymorphism and using CO2 L2 3.3.1
Abstract classes
3. Write programs using the final keyword with Data members
CO2 L3 13.1.1
and Object class.
Lesson Schedule
Class No. - Portion covered per hour
18
DEPARTMENT OF COMPUTER APPLICATIONS
Review Questions
[Link]. - Questions TLOs BL PI Code
1. What is Inheritance? Why is multiple inheritance not
TLO1 L2 3.2.1
supported in java?
2. What is the output of this following code snippet?
class A
{
int i = 10;
}
class B extends A
{
int i = 20;
}
TLO1 L3 3.2.1
public class MainClass
{
public static void main(String[] args)
{
A a = new B();
[Link](a.i);
}
}
3. Write a program to access the superclass instance variable
TLO1 L3 3.2.1
and superclass method directly in the subclass using the
super keyword.
4. Explain Method Overloading. Distinguish between Method TLO2 L2 3.3.1
Overloading and Method Overriding
5. Write a program where the superclass's calculate () method
3.3.1
is overridden by the calculate() method of the subclass. The TLO1 L3
behavior of the calculate() method is dynamically decided.
Learning Outcomes:-
At the end of the topic, the student should be able to:
Topic Learning Outcomes COs BL CA Code
1. Building packages and Designing classes with Access Specifiers CO2 L3 3.1.1
2. Design interfaces for implementing the techniques of Multiple CO2 L3 13.1.1
Inheritance
19
DEPARTMENT OF COMPUTER APPLICATIONS
Lesson Schedule
Class No. - Portion covered per hour
1. Introduction to Package, Defining Package, Working with Package,
2. Packages and Member access,
3. Understanding Protected Members, Importing Packages,
4. Interfaces, Implementing Interfaces, Using Interface References,
5. Default method example, Multiple Inheritance Issues,
6. Use static Methods in an Interface, Private Interface Methods.
Review Questions
[Link]. - Questions TLOs BL PI Code
1. What are Interfaces? Why are the methods of Interface
TLO2 L2 3.1.1
public and abstract by default?
2. Write a Java program to create a Animal interface with a
method called bark() that takes no arguments and returns
TLO2 L3 13.1.1
void. Create a Dog class that implements Animal and
overrides speak() to print "Dog is barking".
3. What will be the output of the following code snippet?
interface A {
int x = 10;
}
interface B {
int x = 20;
}
interface C extends A, B{
TLO2 L3 13.1.1
int x = 30;
public static void main(String[] args){
int a = A.x; int b = B.x;
int c = C.x;
[Link](a);
[Link](b);
[Link](c);
}
}
4. Write a Java program to create an interface Shape with the
getArea() method. Create three classes Rectangle, Circle,
and Triangle that implement the Shape interface. TLO1 L3 13.1.1
Implement the getArea() method for each of the three
classes.
5. Can I import the same package/class twice? Will the JVM
TLO1 L2 13.1.1
load the package twice at runtime?
20
DEPARTMENT OF COMPUTER APPLICATIONS
Learning Outcomes: -
At the end of the topic, the student should be able to:
Topic Learning Outcomes COs BL CA Code
1. Build custom exception handlers using the Java Exception CO2 L3 3.1.1
class and its members.
2. Use Additional features in building Exception Handling CO2 L3 5.1.1
programs, including keywords, Built-in exceptions finally.
3. Creating Exception sub-class. CO2 L3 13.1.1
Lesson Schedule
Class No. - Portion covered per hour
1. The Exception Hierarchy, Exception Handling Fundamentals, Using Try and catch
2. Simple Exception Handling example, Consequences of Uncaught Exception, Exception
enables to handle the error.
3. Using Multiple catch statements, Catching Subclass Exceptions
4. Try Blocks can be Nested, Throwing an Exception, Rethrowing an Exception, Closer look
at Throwable.
5. Finally, Using Throws, Additional features, Java’s Built-in Exceptions, and Creating
Exception Subclasses.
Review Questions
[Link]. - Questions TLOs BL PI Code
1. How can you handle Exceptions in Java? Why do we need
TLO1 L2 3.1.1
Exception Handling in Java?
2. What will be the output of the following code snippet?
class Main {
public static void main(String args[]) {
try {
throw 10;
} TLO1 L3 5.1.1
catch(int e) {
[Link]("Got the Exception " + e);
}
}
}
21
DEPARTMENT OF COMPUTER APPLICATIONS
try
{
int a = 1/0;
[Link]("a = "+a);
}
catch(Exception e){[Link](e);}
catch(ArithmeticException
ex){[Link](ex);}
}
}
4. Write a Java program to create a method that takes an
integer as a parameter and throws an exception if the TLO2 L3 5.1.1
number is odd.
5. Write a program that shows how to handle the
ArithematicException and TLO2 L3 13.1.1
ArrayIndexOutOfBoundsException
Learning Outcomes:-
At the end of the topic, the student should be able to:
Topic Learning Outcomes COs BL CA Code
1. Explain the advantages and potential problems of threading
CO2 L2 3.1.1
and identify the critical sections.
2. Write synchronized Thread code using Thread class and by CO2 L3 13.1.1
implementing the Runnable Interface
Lesson Schedule
Class No. - Portion covered per hour
1. Multithreading Fundamentals, The Thread class, and Runnable Interface
2. Creating Thread, One improvement, and two Simple Variations,
3. Creating multiple Threads, determining when a Thread ends
4. Thread priorities, Synchronization
5. Using Synchronized Methods, The Synchronized Statement.
Review Questions
[Link]. - Questions TLOs BL PI Code
1. What are the uses of threads? Explain the creation of Threads TLO1 L2 3.1.1
and how you run it.
22
DEPARTMENT OF COMPUTER APPLICATIONS
Learning Outcomes: -
At the end of the topic, the student should be able to:
Topic Learning Outcomes COs BL CA Code
1. To store, retrieve, manipulate, and communicate aggregate
CO3 L2 1.1.1
data.
2. What is an ArrayList in Java? How does it differ from an Array CO3 L3 1.4.1
and a Collection in Java?
Lesson Schedule
Class No. - Portion covered per hour
1. Collection Interfaces, Collection and Iterator Interfaces in the Java Library,
2. Linked Lists, Array Lists,
3. Hash Sets, Tree Sets,
4. Object Comparison, Queues and Dequeues,
5. Priority Queues, Maps.
Review Questions
[Link]. - Questions TLOs BL PI Code
1. What is Collection in Java? What are the various interfaces TLO1 L2 1.1.1
used in Java Collections Framework?
2. What is ArrayList in Java? What is the difference between
TLO1 L3 1.4.1
Array and Collection in Java?
3. Write a Java program to search for an element in an array
TLO2 L3 5.1.1
list.
23
DEPARTMENT OF COMPUTER APPLICATIONS
24
DEPARTMENT OF COMPUTER APPLICATIONS
25
DEPARTMENT OF COMPUTER APPLICATIONS
class B extends A
{
int i = 20;
}
[Link](a.i);
}
}
2a Write a Java program to create a class called 10 CO2 L3 3 3.3.1
Shape with a method called getArea(). Create a
subclass called Rectangle that overrides the
getArea() method to calculate the area of a
rectangle.
26
DEPARTMENT OF COMPUTER APPLICATIONS
2b 10 CO2 L3 3 3.1.1
Assume you have written some classes.
Belatedly, you decide they should be split
into three packages, as listed in the following
table. Furthermore, assume the classes are
currently in the default package (they have
no package statements).
Package Name Class Name
[Link] Server
[Link] Utilities
[Link] Client
27
DEPARTMENT OF COMPUTER APPLICATIONS
public Main(){
28
DEPARTMENT OF COMPUTER APPLICATIONS
a=10;
}
}
2c Explain method overloading?What are rules of 10 CO1 L3 3 3.3.1
method overloading?
Predict output of below program:
public class MethodOverloadingExample {
Unit 2
29
DEPARTMENT OF COMPUTER APPLICATIONS
[Link] Server
[Link] Utilities
[Link] Client
Unit 3
7a Write a program to create two threads so one 10 CO2 L3 3 3.1.1
thread will print ascending numbers whereas
second thread will print descending numbers
between sequence 1 to 15 numbers.
7b How to implement thread using runnable 10 CO2 L3 3 5.1.1
Interface in Java, With example.
8a What are the main differences between array 10 CO3 L3 3 1.4.1
and collection?Explain various interfaces used
in Collection framework?
Lab Activities
Demonstration
Q1 Java fundamentals
Q2 Inheritance
Q3 Interfaces and packages
Q4 Exception handling and collections
Exercises
A bank maintains two kinds of accounts – Savings account and Current account.
The savings account provides simple interest, deposit and withdrawal facilities. The
current account only provides deposit and withdrawal facilities. Current account
holders should also maintain minimum balance. If balance falls below minimum level
a service charge is imposed. Create an abstract class Account that stores customer
name, account number type of account and abstract methods. From this derive the
classes CurrAccount(double balance,doublemin_bal,doubleserviceCharge/penalty)
and SavAccount (double balance). Include the necessary methods in order to achieve
the following:
Q5 a. Define parameterized constructor in a class hierarchy.
b. Allow deposit and update the balance (cerditAmount(amt), debitAmt(amt)).
c. Display the balance (printBAlance()).
d. Compute interest and add to balance (computeInterest()).
e. Apply polymorphism if required for methods in class hierarchy.
f. Create an array of super class / object and populate with subclass objects
and call the overridden / object methods.
g. Write a test program to demonstrate the above said implementations.
31
DEPARTMENT OF COMPUTER APPLICATIONS
empType=Dean/Professor/Instructor
Write a java program to model a point object on a 2D plane. The point is described
by x and y coordinates. The point object can be moved to any location in a 2D plane
and the coordinates can be reset (0,0). The java program shall also print the
coordinates of a point object.
32
DEPARTMENT OF COMPUTER APPLICATIONS
Develop a banking system that allows users to perform transactions like deposit and
withdrawal. Implement an "Account" class with appropriate exception handling for
invalid transactions.
Problem solving frame work:
a. Identify object/class: Account
b. Identify the properties: accountNumber, accountHolderName, balance
c. Identify functions: Account (), deposit (), withdraw () and getbalance()
d. Implement the “InvalidAmountException” custom exceptions as follows:
Q10
class Name: InvalidAmountException
Data Members: message
Methods: InvalidAmountException(String message), getMessage()
e. Implement the “InsufficientFundsException” custom exceptions as follows:
Class Name:
Data Members: message
Methods: InsufficientFundsException(String message), getMessage()
Structured Enquiry
Scenario
Consider the Bank Account of type Savings account, current account and money can
be debited or credited to bank accounts. The number of transactions is limited to 5
Q11 on both the accounts, if it exceeds a penalty has to be imposed and the penalty
amount has to be automatically debited from account. The details of the bank
accounts shall be printed. Identify base class and derived classes, attributes and
functions in a class hierarchy. Write a java program to simulate the.
33