Gujarat Technological UniversitySummer 2024 Examination

GTU 3140705 Object Oriented Programming -I (Java) Summer 2024 Paper Solution & PDF

B.E. · Computer Engineering · Semester 4 · Subject Code: 3140705
Download Official GTU PDF
Share:
Total Marks70 MarksExternal theory exam
Passing Marks23 Marks33% minimum cutoff
Exam Duration2.5 Hours10:30 AM – 1:00 PM
Paper Structure5 QuestionsWith internal OR choices
Jump toQ1Q2Q3Q4Q5

Question 1

14 MarksMedium
(a)

Answer in one word:(one mark for each)

IWhich integral type in Java has the exact range from - 2147483648 (-231) to 2147483647 (231-1).
IIThe software for developing and running Java programs.
IIIIt is similar to machine instructions but is architecture neutral and can run on any platform that has a Java Virtual Machine (JVM).
3 Marks
(b)

Write a program that reads an integer and adds all the 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.

4 Marks
(c)

Analyze following code pieces (assume they are properly enclosed in class and main function) and write the output/error (No justification is required): (one mark for each)

Iint num = 5; int x = 1; for (int i = 1; i <= num; i++) { x *= i; } System.out.println("x is " +
x); II. int[] nums = {1, 5, 3, 9, 7}; 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); 07 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);
7 Marks

Question 2

14 MarksMedium
(a)

Describe the relationship between an object and its defining class.

3 Marks
(b)
Write java statements for following class:

public class Counter { int c; }

iDeclare a parameterized constructor to initialize variable c.
iiDeclare instance method to increment c and return updated value of c.
4 Marks
(c)
Justify following:
iIn general, constructors should be public.
iiWhy main is declared as static.
iiiWhy we do not declare destructors in java.
ivThere is no pointer in java.
7 Marks
OR OPTION
(c)
Differentiate between following:
ithis keyword vs super keyword
iiabstract class vs interface
7 Marks

Question 3

14 MarksMedium
(a)

Give definition of method overloading. P A G

3 Marks
(b)
iAnalyze following code pieces and write the

output/error and briefly justify output: public class Test { public static void main(String[] args) { new Person().printPerson(); new Student().printPerson(); } } class Student extends Person { @Override public String getInfo() { return "Student"; } } class Person { public String getInfo() { return "Person"; } public void printPerson() { System.out.println(getInfo()); } }

iiGiven the following source code, which comment line can be uncommented without introducing errors? abstract class MyClass { abstract void f(); final void g() {} //final void h() {} // comment (1) } final class MyOtherClass extends MyClass { public static void main(String[] args) { MyClass mc = new MyOtherClass(); } void f() {} void h() {} //void g() {} // comment (2) }
i)Analyze following code pieces and write the output/error and briefly justify output: public class Test { public static void main(String[] args) { new Person().printPerson(); new Student().printPerson(); } } class Student extends Person { @Override public String getInfo() { return "Student"; } } class Person { public String getInfo() { return "Person"; } public void printPerson() { System.out.println(getInfo()); } } ii. Given the following source code, which comment line can be uncommented without introducing errors? abstract class MyClass { abstract void f(); final void g() {} //final void h() {} // comment
1)} final class MyOtherClass extends MyClass { public static void main(String[] args) { MyClass mc = new MyOtherClass(); } void f() {} void h() {} //void g() {} // comment
2)}
4 Marks
(c)

Discuss public, private, protected and default access modifiers with examples.

7 Marks
OR OPTION
(a)

What is the final keyword? Give different uses of the final keyword.

3 Marks
(b)

Declare an interface called Function that has a method named evaluate that takes an int parameter and returns an

intvalue.
Createa class called Half that implements the Function
interface.The implementation of the method evaluate()
shouldreturn the value obtained by dividing
theint argument by 2.
4 Marks
(c)

What is an Exception? Explain Exception handling in JAVA with the help of example. 07 P A G

7 Marks

Question 4

14 MarksMedium
(a)

How do keyword throw differ from throws in Exception handling?

3 Marks
(b)

Differentiate between a byte oriented and a character- oriented stream.

4 Marks
(c)

Explain binary I/O classes. Demonstrate java file I/O with any I/O class to read a text file.

7 Marks
OR OPTION
(a)
Compare JavaFX with Swing and AWT.
3 Marks
(b)
iList any four UI controls in JavaFX.
iiList any two Panes for Containing and Organizing Nodes
4 Marks
(c)

Write a program to demonstrate GUI application development using JavaFX.

7 Marks

Question 5

14 MarksMedium
(a)

What are the differences between ArrayList and LinkedList? Which list should you use to insert and delete elements at the beginning of a list?

3 Marks
(b)

What is Java Collection Framework? List four collection classes?

4 Marks
(c)

Give the name of class or interface that provides following facility (Do not elaborate)(one mark for each)

iDynamic array to store the duplicate element of different data types. It maintains the insertion order.
iiImplements the last-in-first-out data structure.
iiiImplements the first-in-first-out data structure.
ivImplements the first-in-first-out data structure and it holds the elements or objects which are to be processed by their priorities.
vIt represents the unordered set of elements which doesn't allow us to store the duplicate items.
viIt is a red-black tree-based implementation. It provides an efficient means of storing key-value pairs in sorted order.
viiIt allows us to store key and value pair, where keys should be unique.
7 Marks
OR OPTION
(a)
Explain thread life cycle.
3 Marks
(b)

What is the package? Explain steps to create a package with example.

4 Marks
(c)

Declare a class called Employee having employee_Id and 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.
7 Marks
College Exam Groups

Studying for Object Oriented Programming -I?

Circulate this solved paper with KaTeX formulas and 1-click AI step solvers to your batchmates on WhatsApp or Telegram.

About this Examination Paper & Attribution

Official Gujarat Technological University (GTU) examination paper and step-by-step solutions for Object Oriented Programming -I (Java) (Summer 2024, B.E. · Computer Engineering, Sem 4). Features complete 70-mark regular & remedial examination pattern, official marking distribution across all 5 questions, and direct 1-click official PDF download.

Transcribed for student exam preparation from Gujarat Technological University official examination archives. Questions, syllabus guidelines, and curriculum marking schemes remain the intellectual property of Gujarat Technological University.

Download PDF