(OOP) (APY Material) - Merged - Merged
(OOP) (APY Material) - Merged - Merged
Bachelor of Engineering
Subject Code: 3140705
Semester – IV
Subject Name: Object Oriented Programming -I
Type of course: core course
Prerequisite: None
Rationale: Object oriented Programming has become a fundamental part of software development. OOP
facilitates Reuse of code, flexibility, effective problem solving. It provides a modular structure for programs
and implementation details are hidden. Reuse of code lowers the cost of development.
Content:
w.e.f. AY 2018-19
GUJARAT TECHNOLOGICAL UNIVERSITY
Bachelor of Engineering
Subject Code: 3140705
objects and classes, scope of variable and the this reference.
Page 2 of 5
w.e.f. AY 2018-19
GUJARAT TECHNOLOGICAL UNIVERSITY
Bachelor of Engineering
Subject Code: 3140705
Note: This specification table shall be treated as a general guideline for students and teachers. The actual
distribution of marks in the question paper may vary slightly from above table.
Reference Books:
2) Object oriented programming with Java , Rajkumar Buyya,S Thamarai Selvi, Xingchen Chu,
McGrawHill
Course Outcomes:
CO-1 Use various Java constructs, features and libraries for simple problems. 20
CO-2 Demonstrate how to define and use classes, interfaces, create objects and 20
methods, how to override and overload methods, compile and execute
programs.
CO-4 Write a program using Files, binary I/O, collection Frameworks for a 30
given problem.
CO-5 Design and develop GUI based applications in a group using modern 10
tools and frameworks.
List of Experiments:
(1) Write a Program that displays Welcome to Java, Learning Java Now and Programming is fun.
Page 3 of 5
w.e.f. AY 2018-19
GUJARAT TECHNOLOGICAL UNIVERSITY
Bachelor of Engineering
Subject Code: 3140705
Write a program that solves the following equation and displays the value x and y:
(2) 1) 3.4x+50.2y=44.5 2) 2.1x+.55y=5.9 (Assume Cramer’s rule to solve equation
ax+by=e x=ed-bf/ad-bc
cx+dy=f y=af-ec/ad-bc )
(3) Write a program that reads a number in meters, converts it to feet, and displays the result.
Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your
(4) weight in kilograms and dividing by the square of your height in meters. Write a program that
prompts the user to enter a weight in pounds and height in inches and displays the BMI.
Note:- 1 pound=.45359237 Kg and 1 inch=.0254 meters.
(5) Write a program that prompts the user to enter three integers and display the integers in decreasing
order.
(6) Write a program that prompts the user to enter a letter and check whether a letter is a vowel or
constant.
(7) Assume a vehicle plate number consists of three uppercase letters followed by four digits. Write a
program to generate a plate number.
(8) Write a program that reads an integer and displays all its smallest factors in increasing order. For
example if input number is 120, the output should be as follows:2,2,2,3,5.
Write a method with following method header.
(9)
public static int gcd(int num1, int num2)
Write a program that prompts the user to enter two integers and compute the gcd of two integers.
(10) Write a test program that prompts the user to enter ten numbers, invoke a method to reverse the
numbers, display the numbers.
(11) Write a program that generate 6*6 two-dimensional matrix, filled with 0’s and 1’s , display the
matrix, check every raw and column have an odd number’s of 1’s.
(12) Write a program that creates a Random object with seed 1000 and displays the first 100 random
integers between 1 and 49 using the NextInt (49) method.
Write a program for calculator to accept an expression as a string in which the operands and
(13)
operator are separated by zero or more spaces.
For ex: 3+4 and 3 + 4 are acceptable expressions.
Write a program that creates an Array List and adds a Loan object , a Date object , a string, and a
(14)
Circle object to the list, and use a loop to display all elements in the list by invoking the object’s to
String() method.
Write the bin2Dec (string binary String) method to convert a binary string into a decimal number.
(15)
Implement the bin2Dec method to throw a NumberFormatException if the string is not a binary
string.
Write a program that prompts the user to enter a decimal number and displays the number in a
(16) fraction.
Hint: Read the decimal number as a string, extract the integer part and fractional part from the
string.
(17) Write a program that displays a tic-tac-toe board. A cell may be X, O, or empty. What to display at
each cell is randomly decided. The X and O are images in the files X.gif and O.gif.
(18) Write a program that moves a circle up, down, left or right using arrow keys.
(19) Write a program that displays the color of a circle as red when the mouse button is pressed and as
blue when the mouse button is released.
Page 4 of 5
w.e.f. AY 2018-19
GUJARAT TECHNOLOGICAL UNIVERSITY
Bachelor of Engineering
Subject Code: 3140705
(20) Write a GUI program that use button to move the message to the left and right and use the radio
button to change the color for the message displayed.
Write a program to create a file name 123.txt, if it does not exist. Append a new data to it if it
(21)
already exist. write 150 integers created randomly into the file using Text I/O. Integers are
separated by space.
(22) Write a recursive method that returns the smallest integer in an array. Write a test program that
prompts the user to enter an integer and display its product.
(23) Write a generic method that returns the minimum elements in a two dimensional array.
(24) Define MYPriorityQueue class that extends Priority Queue to implement the Cloneable interface
and implement the clone() method to clone a priority queue.
(25) Write a program that reads words from a text file and displays all the nonduplicate words in
descending order.The text file is passed as a command-line argument.
Major Equipment:
Computer, Laptop
https://www.tutorialspoint.com/java/
https://www.javatpoint.com/java-programs
Page 5 of 5
w.e.f. AY 2018-19
Enrolment No./Seat No_______________
MARKS
Q.1 (a) Answer in one word:(one mark for each) 03
I. Which integral type in Java has the exact range from -
2147483648 (-231) to 2147483647 (231-1).
II. The software for developing and running Java
programs.
III. It is similar to machine instructions but is
architecture neutral and can run on any platform that has
a Java Virtual Machine (JVM).
(b) Write a program that reads an integer and adds all the 04
digits in the integer. For example, if an integer is 932, the
sum of all its digits is 14.
Hint: Use the % operator to extract digits, and use the /
operator to remove the extracted digit. For instance, 932
% 10 = 2 and 932 / 10 = 93.
int m= 1;
int s= 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] > m) {
s = m;
m = nums[i];
} else if (nums[i] > s && nums[i] != m) {
s = nums[i];
}
}
System.out.println("s is: " + s);
P
A
G
III. int i=1,j=0,k=0;
if (i > k) {
if (j > k)
System.out.println("i and j are greater than k");
}
else
System.out.println("i is less than or equal to k");
IV. int x = 3, y = 3;
switch (x + 3) {
case 6: y = 1;
default: y += 1;
}
System.out.println("y is " + y);
V. class HelloWorld {
public static void main(String[] args) {
int[] numbers = new int[1];
numbers[0]=0;
m(numbers);
System.out.println("numbers[0] is" +
numbers[0]);
}
public static void m(int[] y) {
y[0] = 3;
}
}
VI. StringBuffer s1 = new StringBuffer("Complete");
s1.setCharAt(1,'i');
s1.setCharAt(7,'d');
System.out.println(s1);
VII. int Integer = 24;
char String ='I';
System.out.print(Integer);
System.out.print(String);
P
A
G
(b) i. Analyze following code pieces and write the 04
output/error and briefly justify output:
public class Test {
public static void main(String[] args) {
new Person().printPerson();
new Student().printPerson();
}
}
class Person {
public String getInfo() {
return "Person";
}
P
A
G
Q.4 (a) How do keyword throw differ from throws in Exception 03
handling?
(b) Differentiate between a byte oriented and a character- 04
oriented stream.
(c) Explain binary I/O classes. Demonstrate java file I/O with 07
any I/O class to read a text file.
OR
Q.4 (a) Compare JavaFX with Swing and AWT. 03
(b) i. List any four UI controls in JavaFX. 04
ii. List any two Panes for Containing and Organizing
Nodes
(c) Write a program to demonstrate GUI application 07
development using JavaFX.
Q.5 (a) What are the differences between ArrayList and 03
LinkedList? Which list should you use to insert and delete
elements at the beginning of a list?
(b) What is Java Collection Framework? List four collection 04
classes?
(c) Give the name of class or interface that provides following 07
facility (Do not elaborate)(one mark for each)
i. Dynamic array to store the duplicate element of different
data types. It maintains the insertion order.
ii. Implements the last-in-first-out data structure.
iii. Implements the first-in-first-out data structure.
iv. Implements the first-in-first-out data structure and it
holds the elements or objects which are to be processed by
their priorities.
v. It represents the unordered set of elements which
doesn't allow us to store the duplicate items.
vi. It is a red-black tree-based implementation. It provides
an efficient means of storing key-value pairs in sorted
order.
vii. It allows us to store key and value pair, where keys
should be unique.
OR
Q.5 (a) Explain thread life cycle. 03
(b) What is the package? Explain steps to create a package 04
with example.
(c) Declare a class called Employee having employee_Id and 07
employee_Name as members.
Extend class Employee to have a subclass called
SalariedEmployee having designation and
monthly_salary as members. Define following:
- Required constructors
- Methods to insert, update and display all details of
employees.
- Method main for creating an array for storing these
details given as command line arguments and showing
usage of above methods.
***********
P
A
G
Seat No.: ________ Enrolment No.___________
MARKS
Q.1 (a) What is the Java bytecode, and what is the extension of Java bytecode file? 03
Which software is needed to run Java bytecode?
(b) Describe syntax errors (compile errors), runtime errors, and logic errors by 04
giving suitable examples?
(c) Answer in brief (within 50 words): 07
I. Justify Java enables high performance.
II. Differentiate between while and do while loop?
III. How many times is the println statement executed?
for (int i = 0; i < 10; i++)
for (int j = 0; j < i; j++)
System.out.println(i * j);
IV. If the value of variable x is 1 then what will be returned by the
following expression:
x%2==0
Q.2 (a) What is the use of this keyword? How it is different from super keyword? 03
(b) (i) Given that Thing is a class, how many objects and how many reference 04
variables are created by the following code?
Thing item, stuff;
item = new Thing();
Thing entity = new Thing();
(ii) Examine following code. Write and justify output.
public class MyClass {
public static void main(String[] args) {
C c = new C();
System.out.println(c.max(12, 29));
}
}
class A {
int max(int x, int y) { if (x>y) return x; else return y; }
}
class B extends A{
int max(int x, int y) { return super.max(y, x) - 10; }
}
class C extends B {
int max(int x, int y) { return super.max(x+10, y+2); }
}
(c) Write a program that defines class named StopWatch. The class contains: 07
• Private data fields startTime and endTime with getter methods.
1
• no-arg constructor that initializes startTime with the current time.
• A method named start() that resets the startTime to the current time.
• A method named stop() that sets the endTime to the current time.
• A method named getElapsedTime() that returns the elapsed time for
the stopwatch in milliseconds.
• Declare object of StopWatch to demonstrate stop watch.
Hint: Use System.currentTimeMillis() to get current time in milliseconds.
OR
(c) Create a class called Employee that includes: 07
I. Three instance variables— id (type String), name (type String) and
monthly_salary (double).
II. A default constructor that initializes the three instance variables.
III. A setter and a getter method for each instance variable (for example
for id variable void setId(String id), String getId( )).
IV. displayEmployee() method for displaying employee details.
Write a driver class named EmployeeTest that demonstrates class Employee’s
capabilities. Create two Employee objects and display each object’s yearly
salary. Then give each Employee a 10% raise and display each Employee’s
yearly salary again.
Q.1 (a) How java supports platform independency? What is the role of JVM in it? 03
(b) Write a program which displays first n prime number? Where is n provided 04
by user as command line argument?
(c) Write a program which declare integer array of 10 elements? Initialize array 07
and define following methods with the specified header:
(i) public static int add(int [] array) print addition of all element of array.
(ii) public static int max(int [] array) print maximum element of array.
(ii) public static int search(int [] array, int key) search element key in array
and return index of it. If element is not found method will return -1.
Q.2 (a) Describe the relationship between an object and its defining class? 03
(b) Analyze following code. Validate and explain output of code. If any error 04
exists, indicate portion. Suggest code to eliminate error:
public class Circle {
private double radius;
public static void main(String args[]){
Circle c1=new Circle(2);
System.out.println("Area "+c1.getArea());
B b1=new B(2, 2);
System.out.println("Area "+b1.getArea());
}
public Circle(double radius) {
radius = radius;
}
public double getRadius() {
return radius;
}
public double getArea() {
return radius * radius * Math.PI;
}
}
1
OR
(c) Answer in brief(within two lines): 07
(i) If a method defined in a subclass has the same signature as a method in its
superclass with the
same return type, is the method overridden or overloaded?
(ii) How do you invoke an overridden superclass method from a subclass?
(iii) What is the purpose of "this" keyword?
(iv) Differentiate between following statements:
int a=3;
Integer b=new Integer(3);
(v) Which java keyword is used to prevent inheritance (prevent class to be
extended)?
(vi) Can we create reference of interface. If we can create, then what is the
use of it?
(vii) What is the difference between a String in Java and String in C/C++?
Q.4 (a) Write a program to find out whether the given number is palindrome or not? 03
(b) Outline the use of throw in exception handling with example. 04
(c) Give Definitions: static, finalize, final 07
OR
Q.4 (a) Elaborate the role of java garbage collector. 03
(b) State four similarities between Interfaces and Classes. 04
(c) Differentiate between ArrayList and LinkedList? Which list should you use 07
to insert and delete elements at the beginning of a list? What methods are in
LinkedList but not in ArrayList?
***********
3
Seat No.: ________ Enrolment No.___________
Q.3 (a) What is the final class? Why they are used? 03
(b) Write exception handling mechanisms in JAVA. 04
(c) Explain Overloading and Overriding with example. 07
OR
Q.3 (a) How can you create packages in Java? 03
(b) What is Inheritance? List out the different forms of Inheritance and 04
explain any one with example.
(c) Explain the words super, static, final and this with the help of an 07
example.
*************
2
Seat No.: ________ Enrolment No.___________
MARKS
Q.1 (a) What are syntax errors (compile errors), runtime errors, and logic 03
errors?
(b) What is Type Casting? Explain widening and narrowing type 04
casting.
(c) Explain Data Types in detail with example. 07
1
Q.5 (a) Compare List and Set. 03
(b) Explain static variable and static method with example. 04
(c) Explain Thread Synchronization with example. 07
*************
2
Seat No.: ________ Enrolment No.___________
Q.1 (a) What is the difference between oop and procedural oriented language? 03
(b) Explain type-conversion in java. 04
(c) Explain class and object with respect to java. 07
*************
1
Seat No.: ________ Enrolment No.___________
MARKS
Q.1 (a) Define object oriented concepts. 03
(b) What is the difference between the StringBuffer and StringBuilder 04
classes?
(c) Define constructor. How objects are constructed? Explain constructor 07
overloading with an example.
Q.2 (a) Explain about arrays, Type of arrays and arrays methods. 03
(b) Explain about Encapsulation, Abstraction. 04
(c) State the design hints for class and inheritance. 07
Also discuss the working and meaning of the “static” modifier with
suitable examples.
OR
(c) Explain in detail how inheritance and polymorphism are supported in 07
java with necessary examples.
Q.3 (a) Explain about different types of string methods. 03
(b) Write short notes on access specifiers and modifiers in java. 04
(c) What is an Exception? Explain the exception hierarchy. Explain how 07
to throw, catch and handle Exceptions.
OR
Q.3 (a) Explain about Final class, Fields, Methods. 03
(b) What is a Package? What are the benefits of using packages? Write 04
down the steps in creating a package and using it in a java program
with an example.
(c) Explain the concept of inner classes and explain the types of inner 07
classes with an example program.
Q.4 (a) What is Dynamic binding? Show with an example how dynamic 03
binding works.
(b) Write short notes about I/O stream classes. 04
(c) Explain the thread state, thread properties and thread synchronization. 07
OR
Q.4 (a) Explain the concept of finalization. 03
(b) What is reflection and how does it help to manipulate java code. 04
(c) Write a java program to implement the multiple inheritance concepts 07
for calculating area of circle and square.
Q.5 (a) Explain about callback 03
(b) Explain the interface with an example program. 04
(c) What is Generic programming and why is it needed? Explain with 07
example. List the limitations and restrictions of generic programming
1
OR
Q.5 (a) Explain about Proxy class, Interface and Methods. 03
(b) Explain about adapter classes and mouse events with an example. 04
(c) With a neat diagram explain the Model view controller design pattern 07
and list out the advantages and disadvantages of using it in designing
an application.
*************
2
Seat No.: ________ Enrolment No.___________
GUJARAT TECHNOLOGICAL UNIVERSITY
BE - SEMESTER– IV EXAMINATION – SUMMER 2020
Subject Code: 3140705 Date:26/10/2020
Subject Name: Object Oriented Programming -I
Time: 10:30 AM TO 01:00 PM Total Marks: 70
Instructions:
1. Attempt all questions.
2. Make suitable assumptions wherever necessary.
3. Figures to the right indicate full marks.
MARKS
Q.1 (a) Explain JRE, JDK and JIT. 03
(b) Explain static keyword with example. 04
(c) Explain inheritance with its types and give suitable example. 07
1
Seat No.: ________ Enrolment No.___________
GUJARAT TECHNOLOGICAL UNIVERSITY
BE - SEMESTER– IV EXAMINATION – SUMMER 2020
Subject Code: 3140705 Date:26/10/2020
Subject Name: Object Oriented Programming -I
Time: 10:30 AM TO 01:00 PM Total Marks: 70
Instructions:
1. Attempt all questions.
2. Make suitable assumptions wherever necessary.
3. Figures to the right indicate full marks.
MARKS
Q.1 (a) Explain JRE, JDK and JIT. 03
(b) Explain static keyword with example. 04
(c) Explain inheritance with its types and give suitable example. 07
1
Seat No.: ________ Enrolment No.___________
Q.1 (a) What is the difference between oop and procedural oriented language? 03
(b) Explain type-conversion in java. 04
(c) Explain class and object with respect to java. 07
*************
1
Seat No.: ________ Enrolment No.___________
MARKS
Q.1 (a) Define object oriented concepts. 03
(b) What is the difference between the StringBuffer and StringBuilder 04
classes?
(c) Define constructor. How objects are constructed? Explain constructor 07
overloading with an example.
Q.2 (a) Explain about arrays, Type of arrays and arrays methods. 03
(b) Explain about Encapsulation, Abstraction. 04
(c) State the design hints for class and inheritance. 07
Also discuss the working and meaning of the “static” modifier with
suitable examples.
OR
(c) Explain in detail how inheritance and polymorphism are supported in 07
java with necessary examples.
Q.3 (a) Explain about different types of string methods. 03
(b) Write short notes on access specifiers and modifiers in java. 04
(c) What is an Exception? Explain the exception hierarchy. Explain how 07
to throw, catch and handle Exceptions.
OR
Q.3 (a) Explain about Final class, Fields, Methods. 03
(b) What is a Package? What are the benefits of using packages? Write 04
down the steps in creating a package and using it in a java program
with an example.
(c) Explain the concept of inner classes and explain the types of inner 07
classes with an example program.
Q.4 (a) What is Dynamic binding? Show with an example how dynamic 03
binding works.
(b) Write short notes about I/O stream classes. 04
(c) Explain the thread state, thread properties and thread synchronization. 07
OR
Q.4 (a) Explain the concept of finalization. 03
(b) What is reflection and how does it help to manipulate java code. 04
(c) Write a java program to implement the multiple inheritance concepts 07
for calculating area of circle and square.
Q.5 (a) Explain about callback 03
(b) Explain the interface with an example program. 04
(c) What is Generic programming and why is it needed? Explain with 07
example. List the limitations and restrictions of generic programming
1
OR
Q.5 (a) Explain about Proxy class, Interface and Methods. 03
(b) Explain about adapter classes and mouse events with an example. 04
(c) With a neat diagram explain the Model view controller design pattern 07
and list out the advantages and disadvantages of using it in designing
an application.
*************
2
Seat No.: ________ Enrolment No.___________
MARKS
Q.1 (a) What are syntax errors (compile errors), runtime errors, and logic 03
errors?
(b) What is Type Casting? Explain widening and narrowing type 04
casting.
(c) Explain Data Types in detail with example. 07
1
Q.5 (a) Compare List and Set. 03
(b) Explain static variable and static method with example. 04
(c) Explain Thread Synchronization with example. 07
*************
2
Seat No.: ________ Enrolment No.___________
*************
2
Seat No.: ________ Enrolment No.___________
Q.3 (a) What is the final class? Why they are used? 03
(b) Write exception handling mechanisms in JAVA. 04
(c) Explain Overloading and Overriding with example. 07
OR
Q.3 (a) How can you create packages in Java? 03
(b) What is Inheritance? List out the different forms of Inheritance and 04
explain any one with example.
(c) Explain the words super, static, final and this with the help of an 07
example.
MARKS
Q.1 (a) What is the Java bytecode, and what is the extension of Java bytecode file? 03
Which software is needed to run Java bytecode?
(b) Describe syntax errors (compile errors), runtime errors, and logic errors by 04
giving suitable examples?
(c) Answer in brief (within 50 words): 07
I. Justify Java enables high performance.
II. Differentiate between while and do while loop?
III. How many times is the println statement executed?
for (int i = 0; i < 10; i++)
for (int j = 0; j < i; j++)
System.out.println(i * j);
IV. If the value of variable x is 1 then what will be returned by the
following expression:
x%2==0
Q.2 (a) What is the use of this keyword? How it is different from super keyword? 03
(b) (i) Given that Thing is a class, how many objects and how many reference 04
variables are created by the following code?
Thing item, stuff;
item = new Thing();
Thing entity = new Thing();
(ii) Examine following code. Write and justify output.
public class MyClass {
public static void main(String[] args) {
C c = new C();
System.out.println(c.max(12, 29));
}
}
class A {
int max(int x, int y) { if (x>y) return x; else return y; }
}
class B extends A{
int max(int x, int y) { return super.max(y, x) - 10; }
}
class C extends B {
int max(int x, int y) { return super.max(x+10, y+2); }
}
(c) Write a program that defines class named StopWatch. The class contains: 07
• Private data fields startTime and endTime with getter methods.
1
• no-arg constructor that initializes startTime with the current time.
• A method named start() that resets the startTime to the current time.
• A method named stop() that sets the endTime to the current time.
• A method named getElapsedTime() that returns the elapsed time for
the stopwatch in milliseconds.
• Declare object of StopWatch to demonstrate stop watch.
Hint: Use System.currentTimeMillis() to get current time in milliseconds.
OR
(c) Create a class called Employee that includes: 07
I. Three instance variables— id (type String), name (type String) and
monthly_salary (double).
II. A default constructor that initializes the three instance variables.
III. A setter and a getter method for each instance variable (for example
for id variable void setId(String id), String getId( )).
IV. displayEmployee() method for displaying employee details.
Write a driver class named EmployeeTest that demonstrates class Employee’s
capabilities. Create two Employee objects and display each object’s yearly
salary. Then give each Employee a 10% raise and display each Employee’s
yearly salary again.
Q.1 (a) How java supports platform independency? What is the role of JVM in it? 03
(b) Write a program which displays first n prime number? Where is n provided 04
by user as command line argument?
(c) Write a program which declare integer array of 10 elements? Initialize array 07
and define following methods with the specified header:
(i) public static int add(int [] array) print addition of all element of array.
(ii) public static int max(int [] array) print maximum element of array.
(ii) public static int search(int [] array, int key) search element key in array
and return index of it. If element is not found method will return -1.
Q.2 (a) Describe the relationship between an object and its defining class? 03
(b) Analyze following code. Validate and explain output of code. If any error 04
exists, indicate portion. Suggest code to eliminate error:
public class Circle {
private double radius;
public static void main(String args[]){
Circle c1=new Circle(2);
System.out.println("Area "+c1.getArea());
B b1=new B(2, 2);
System.out.println("Area "+b1.getArea());
}
public Circle(double radius) {
radius = radius;
}
public double getRadius() {
return radius;
}
public double getArea() {
return radius * radius * Math.PI;
}
}
1
OR
(c) Answer in brief(within two lines): 07
(i) If a method defined in a subclass has the same signature as a method in its
superclass with the
same return type, is the method overridden or overloaded?
(ii) How do you invoke an overridden superclass method from a subclass?
(iii) What is the purpose of "this" keyword?
(iv) Differentiate between following statements:
int a=3;
Integer b=new Integer(3);
(v) Which java keyword is used to prevent inheritance (prevent class to be
extended)?
(vi) Can we create reference of interface. If we can create, then what is the
use of it?
(vii) What is the difference between a String in Java and String in C/C++?
Q.4 (a) Write a program to find out whether the given number is palindrome or not? 03
(b) Outline the use of throw in exception handling with example. 04
(c) Give Definitions: static, finalize, final 07
OR
Q.4 (a) Elaborate the role of java garbage collector. 03
(b) State four similarities between Interfaces and Classes. 04
(c) Differentiate between ArrayList and LinkedList? Which list should you use 07
to insert and delete elements at the beginning of a list? What methods are in
LinkedList but not in ArrayList?
***********
3
Enrolment No./Seat No_______________
MARKS
Q.1 (a) Answer in one word:(one mark for each) 03
I. Which integral type in Java has the exact range from -
2147483648 (-231) to 2147483647 (231-1).
II. The software for developing and running Java
programs.
III. It is similar to machine instructions but is
architecture neutral and can run on any platform that has
a Java Virtual Machine (JVM).
(b) Write a program that reads an integer and adds all the 04
digits in the integer. For example, if an integer is 932, the
sum of all its digits is 14.
Hint: Use the % operator to extract digits, and use the /
operator to remove the extracted digit. For instance, 932
% 10 = 2 and 932 / 10 = 93.
int m= 1;
int s= 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] > m) {
s = m;
m = nums[i];
} else if (nums[i] > s && nums[i] != m) {
s = nums[i];
}
}
System.out.println("s is: " + s);
P
A
G
III. int i=1,j=0,k=0;
if (i > k) {
if (j > k)
System.out.println("i and j are greater than k");
}
else
System.out.println("i is less than or equal to k");
IV. int x = 3, y = 3;
switch (x + 3) {
case 6: y = 1;
default: y += 1;
}
System.out.println("y is " + y);
V. class HelloWorld {
public static void main(String[] args) {
int[] numbers = new int[1];
numbers[0]=0;
m(numbers);
System.out.println("numbers[0] is" +
numbers[0]);
}
public static void m(int[] y) {
y[0] = 3;
}
}
VI. StringBuffer s1 = new StringBuffer("Complete");
s1.setCharAt(1,'i');
s1.setCharAt(7,'d');
System.out.println(s1);
VII. int Integer = 24;
char String ='I';
System.out.print(Integer);
System.out.print(String);
P
A
G
(b) i. Analyze following code pieces and write the 04
output/error and briefly justify output:
public class Test {
public static void main(String[] args) {
new Person().printPerson();
new Student().printPerson();
}
}
class Person {
public String getInfo() {
return "Person";
}
P
A
G
Q.4 (a) How do keyword throw differ from throws in Exception 03
handling?
(b) Differentiate between a byte oriented and a character- 04
oriented stream.
(c) Explain binary I/O classes. Demonstrate java file I/O with 07
any I/O class to read a text file.
OR
Q.4 (a) Compare JavaFX with Swing and AWT. 03
(b) i. List any four UI controls in JavaFX. 04
ii. List any two Panes for Containing and Organizing
Nodes
(c) Write a program to demonstrate GUI application 07
development using JavaFX.
Q.5 (a) What are the differences between ArrayList and 03
LinkedList? Which list should you use to insert and delete
elements at the beginning of a list?
(b) What is Java Collection Framework? List four collection 04
classes?
(c) Give the name of class or interface that provides following 07
facility (Do not elaborate)(one mark for each)
i. Dynamic array to store the duplicate element of different
data types. It maintains the insertion order.
ii. Implements the last-in-first-out data structure.
iii. Implements the first-in-first-out data structure.
iv. Implements the first-in-first-out data structure and it
holds the elements or objects which are to be processed by
their priorities.
v. It represents the unordered set of elements which
doesn't allow us to store the duplicate items.
vi. It is a red-black tree-based implementation. It provides
an efficient means of storing key-value pairs in sorted
order.
vii. It allows us to store key and value pair, where keys
should be unique.
OR
Q.5 (a) Explain thread life cycle. 03
(b) What is the package? Explain steps to create a package 04
with example.
(c) Declare a class called Employee having employee_Id and 07
employee_Name as members.
Extend class Employee to have a subclass called
SalariedEmployee having designation and
monthly_salary as members. Define following:
- Required constructors
- Methods to insert, update and display all details of
employees.
- Method main for creating an array for storing these
details given as command line arguments and showing
usage of above methods.
***********
P
A
G
GUJARAT TECHNOLOGICAL UNIVERSITY
Bachelor of Engineering
Subject Code: 3140705
Semester – IV
Subject Name: Object Oriented Programming -I
Type of course: core course
Prerequisite: None
Rationale: Object oriented Programming has become a fundamental part of software development. OOP
facilitates Reuse of code, flexibility, effective problem solving. It provides a modular structure for programs
and implementation details are hidden. Reuse of code lowers the cost of development.
Content:
w.e.f. AY 2018-19
GUJARAT TECHNOLOGICAL UNIVERSITY
Bachelor of Engineering
Subject Code: 3140705
objects and classes, scope of variable and the this reference.
Page 2 of 5
w.e.f. AY 2018-19
GUJARAT TECHNOLOGICAL UNIVERSITY
Bachelor of Engineering
Subject Code: 3140705
Note: This specification table shall be treated as a general guideline for students and teachers. The actual
distribution of marks in the question paper may vary slightly from above table.
Reference Books:
2) Object oriented programming with Java , Rajkumar Buyya,S Thamarai Selvi, Xingchen Chu,
McGrawHill
Course Outcomes:
CO-1 Use various Java constructs, features and libraries for simple problems. 20
CO-2 Demonstrate how to define and use classes, interfaces, create objects and 20
methods, how to override and overload methods, compile and execute
programs.
CO-4 Write a program using Files, binary I/O, collection Frameworks for a 30
given problem.
CO-5 Design and develop GUI based applications in a group using modern 10
tools and frameworks.
List of Experiments:
(1) Write a Program that displays Welcome to Java, Learning Java Now and Programming is fun.
Page 3 of 5
w.e.f. AY 2018-19
GUJARAT TECHNOLOGICAL UNIVERSITY
Bachelor of Engineering
Subject Code: 3140705
Write a program that solves the following equation and displays the value x and y:
(2) 1) 3.4x+50.2y=44.5 2) 2.1x+.55y=5.9 (Assume Cramer’s rule to solve equation
ax+by=e x=ed-bf/ad-bc
cx+dy=f y=af-ec/ad-bc )
(3) Write a program that reads a number in meters, converts it to feet, and displays the result.
Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your
(4) weight in kilograms and dividing by the square of your height in meters. Write a program that
prompts the user to enter a weight in pounds and height in inches and displays the BMI.
Note:- 1 pound=.45359237 Kg and 1 inch=.0254 meters.
(5) Write a program that prompts the user to enter three integers and display the integers in decreasing
order.
(6) Write a program that prompts the user to enter a letter and check whether a letter is a vowel or
constant.
(7) Assume a vehicle plate number consists of three uppercase letters followed by four digits. Write a
program to generate a plate number.
(8) Write a program that reads an integer and displays all its smallest factors in increasing order. For
example if input number is 120, the output should be as follows:2,2,2,3,5.
Write a method with following method header.
(9)
public static int gcd(int num1, int num2)
Write a program that prompts the user to enter two integers and compute the gcd of two integers.
(10) Write a test program that prompts the user to enter ten numbers, invoke a method to reverse the
numbers, display the numbers.
(11) Write a program that generate 6*6 two-dimensional matrix, filled with 0’s and 1’s , display the
matrix, check every raw and column have an odd number’s of 1’s.
(12) Write a program that creates a Random object with seed 1000 and displays the first 100 random
integers between 1 and 49 using the NextInt (49) method.
Write a program for calculator to accept an expression as a string in which the operands and
(13)
operator are separated by zero or more spaces.
For ex: 3+4 and 3 + 4 are acceptable expressions.
Write a program that creates an Array List and adds a Loan object , a Date object , a string, and a
(14)
Circle object to the list, and use a loop to display all elements in the list by invoking the object’s to
String() method.
Write the bin2Dec (string binary String) method to convert a binary string into a decimal number.
(15)
Implement the bin2Dec method to throw a NumberFormatException if the string is not a binary
string.
Write a program that prompts the user to enter a decimal number and displays the number in a
(16) fraction.
Hint: Read the decimal number as a string, extract the integer part and fractional part from the
string.
(17) Write a program that displays a tic-tac-toe board. A cell may be X, O, or empty. What to display at
each cell is randomly decided. The X and O are images in the files X.gif and O.gif.
(18) Write a program that moves a circle up, down, left or right using arrow keys.
(19) Write a program that displays the color of a circle as red when the mouse button is pressed and as
blue when the mouse button is released.
Page 4 of 5
w.e.f. AY 2018-19
GUJARAT TECHNOLOGICAL UNIVERSITY
Bachelor of Engineering
Subject Code: 3140705
(20) Write a GUI program that use button to move the message to the left and right and use the radio
button to change the color for the message displayed.
Write a program to create a file name 123.txt, if it does not exist. Append a new data to it if it
(21)
already exist. write 150 integers created randomly into the file using Text I/O. Integers are
separated by space.
(22) Write a recursive method that returns the smallest integer in an array. Write a test program that
prompts the user to enter an integer and display its product.
(23) Write a generic method that returns the minimum elements in a two dimensional array.
(24) Define MYPriorityQueue class that extends Priority Queue to implement the Cloneable interface
and implement the clone() method to clone a priority queue.
(25) Write a program that reads words from a text file and displays all the nonduplicate words in
descending order.The text file is passed as a command-line argument.
Major Equipment:
Computer, Laptop
https://www.tutorialspoint.com/java/
https://www.javatpoint.com/java-programs
Page 5 of 5
w.e.f. AY 2018-19