Object Oriented Programming I focuses on fundamental concepts of OOP, including classes, objects, inheritance, and polymorphism. This course material is designed for students enrolled in the Gujarat Technological University, specifically for the Summer 2023 semester. Key topics include Java bytecode, error types, exception handling, and the Java Collections Framework. The document features programming exercises and examples to enhance understanding of OOP principles. Ideal for students preparing for exams or seeking to solidify their programming skills in Java.

Key Points

  • Explains Java bytecode and its execution environment.
  • Describes syntax errors, runtime errors, and logic errors with examples.
  • Covers exception handling using try-catch blocks and throw/throws clauses.
  • Includes programming exercises on classes, inheritance, and polymorphism.
Jeen Covey
2 pages
Language:English
Type:Study Guide
Jeen Covey
2 pages
Language:English
Type:Study Guide
425
/ 2
1
Seat No.: ________ Enrolment No.___________
GUJARAT TECHNOLOGICAL UNIVERSITY
BE - SEMESTER IV(NEW) EXAMINATION SUMMER 2023
Subject Code:3140705 Date:25-07-2023
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.
4. Simple and non-programmable scientific calculators are allowed.
MARKS
Q.1
(a)
What is the Java bytecode, and what is the extension of Java bytecode file?
Which software is needed to run Java bytecode?
03
(b)
Describe syntax errors (compile errors), runtime errors, and logic errors by
giving suitable examples?
04
(c)
Answer in brief (within 50 words):
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
07
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
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); }
}
04
(c)
Write a program that defines class named StopWatch. The class contains:
Private data fields startTime and endTime with getter methods.
07
2
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:
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.
07
Q.3
(a)
Differentiate between checked and unchecked exception?
03
(b)
Exemplify throw and throws clause of exception handling?
04
(c)
Demonstrate use of try catch block by catching ArithmeticExceptions and
InputMismatchExceptions?
07
OR
Q.3
(a)
Describe thread life cycle with block diagram?
03
(b)
Differentiate between Thread class and Runnable interface for implementing
Threads?
04
(c)
Write a program to make calculator that accepts input from commandline?
Use java’s exception handling mechanism to handle abnormal situation?
07
Q.4
(a)
Define Queue interface of java collection classes?
03
(b)
Explain types of polymorphism?
04
(c)
What are the differences between ArrayList and LinkedList? Demonstrates
use of ArrayList with example?
07
OR
Q.4
(a)
Define Object Serialization?
03
(b)
What are the differences between text I/O and binary I/O?
04
(c)
Describe and demonstrate Binary I/O classes of java?
07
Q.5
(a)
Answer in one line:
(i) Write the name of package in which all collection classes and interface are
grouped.
(ii) Write the name of collection interface or abstract class which store and
process object in a first-in, first-out fashion.
(iii) Write the name of method that checks whether the collection contains the
specified element.
03
(b)
List JavaFX UI controls?
04
(c)
What do you understand by event source and event object? Explain how to
register an event handler object and how to implement a handler interface?
07
OR
Q.5
(a)
Enlist various Layout panes available in JavaFX?
03
(b)
Discuss JavaFX benefits?
04
(c)
Illustrate basic structure of JavaFX program?
07
*************
/ 2
End of Document
425

FAQs

What are the main concepts covered in Object Oriented Programming I?
Object Oriented Programming I covers essential concepts such as classes, objects, inheritance, encapsulation, and polymorphism. Students learn how to create and manipulate objects in Java, understand the significance of constructors, and utilize access modifiers. The course emphasizes the importance of design patterns and best practices in OOP, preparing students for real-world programming challenges.
How does exception handling work in Java?
Exception handling in Java is managed through the use of try-catch blocks, which allow developers to gracefully handle runtime errors. When an exception occurs, the code within the try block is skipped, and control is transferred to the catch block, where the error can be processed. This mechanism helps maintain the program's flow and prevents crashes, making applications more robust.
What is the difference between compile-time errors and runtime errors?
Compile-time errors occur during the compilation of the program, often due to syntax mistakes or type mismatches, preventing the code from running. Runtime errors, on the other hand, happen during program execution, often due to invalid operations such as dividing by zero or accessing an out-of-bounds array index. Understanding these differences is crucial for debugging and writing effective code.
What is the role of the 'this' keyword in Java?
'this' is a reference variable in Java that refers to the current object within a class. It is commonly used to resolve naming conflicts between instance variables and parameters, ensuring clarity in code. Additionally, 'this' can be used to invoke other constructors within the same class, enhancing code organization and readability.
How do polymorphism and inheritance work together in Java?
Polymorphism allows methods to perform differently based on the object that invokes them, while inheritance enables a new class to inherit properties and methods from an existing class. Together, these concepts facilitate code reusability and flexibility, allowing developers to create more dynamic and adaptable applications. For instance, a superclass can define a method, and subclasses can override it to provide specific implementations.