[Go to site: main page, start]

0% found this document useful (0 votes)
20 views2 pages

OOP in Java: Assignment Questions for B.Tech

The document outlines assignment questions for the OOP through Java course at St. Ann's College of Engineering & Technology for the academic year 2025-26. It covers various units including primitive data types, object memory allocation, inheritance, exception handling, multithreading, and JDBC database connections. Each unit contains multiple questions requiring explanations, program illustrations, and examples related to Java programming concepts.

Uploaded by

snonline786
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

OOP in Java: Assignment Questions for B.Tech

The document outlines assignment questions for the OOP through Java course at St. Ann's College of Engineering & Technology for the academic year 2025-26. It covers various units including primitive data types, object memory allocation, inheritance, exception handling, multithreading, and JDBC database connections. Each unit contains multiple questions requiring explanations, program illustrations, and examples related to Java programming concepts.

Uploaded by

snonline786
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ST.

ANN’S COLLEGE OF ENGINEERING &TECHNOLOGY :: CHIRALA


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
ASSIGNMENT QUESTIONS
Subject : OOP THROUGH JAVA Year/Sem: II [Link] – I Sem
Academic Year: 2025-26 Regulation : R-23

UNIT-1 :
1. a) What are the different primitive data types in java? Give their sizes in bits. How they
are different from reference data types?
b) How to use break and continue statements in java?
2. a)Write a java program to illustrate the usage of conditional statements and looping
statements.
b) Write a java program that inputs an integer, ‘n’ from the command line and displays
the string “1+2+3+…+n=sum” and also compute the sum.
3. a) Write the importance of command line arguments. Write a Java program which
accepts the input from keyboard to display Fibonacci series.
b) Explain various Operators in Java with examples.

UNIT-2 :
1. What is an Object? How to allocate memory for objects? How to assign the values to
the variables in the class during the time of creation of an object to that class? Explain
with an example.
2. What is the difference between ‘static’ and ‘non-static’ methods in JAVA? ) Describe
the usage of static members and nesting members with suitable example programs in
java.
3. a) What is a Constructor? What is the main purpose of Constructors? How to invoke a
constructor in JAVA?
b) Write a java program to illustrate the Methods by passing arguments by Value and
passing arguments by reference.

UNIT-3 :
1. a) Explain about class Array and its methods. How can we implement dynamic array
with Vector?
b) Write a java program to illustrate various Vector operations.
2. a) List the types of Inheritances in Java. Discuss briefly about Access Control in
inheritance.
b) What is method overriding? Illustrate the concept of method overriding with an
example.
3. a) What is interface? Write briefly about types of interfaces. How does it supports
multiple inheritance in java?
b) Write two Java Programs to illustrate the use of default methods and static methods
in interfaces.

UNIT-4 :
1. a) How to create user defined packages and import them to java application program.
Illustrate with simple example.
b) What is the significance of the CLASSPATH environment variable in creating or
using a package?
2. a) Give the syntax of exception handling and also handle exception occurred during the
execution of divide by zero
b) What is the importance of Exception Handling in Java? Define and distinguish
between checked and unchecked exceptions.
3. a) What is the difference between finally and finalize in Java. Illustrate with example
b) Write about throw and throws keywords. Illustrate an example to rethrow a caught
exception.
.
UNIT-5 :

1. a) Explain about StringBuffer class with example program?


b) What are the different ways to create Threads? Explain with example program.
2. a) How Thread synchronization plays an important role resource sharing? Explain.
b) How Producer-Consumer problem can be addressed in multithreading? Explain with
example Program.
3. a) Explain about Establishing JDBC Database Connections to mysql database with
example program?
b) Write a JDBC program to search for an attribute in a table and display the entire
tuple to the user. For example, display all the details of the student given his/her roll
number.

Common questions

Powered by AI

Method overriding in Java allows a subclass to provide a specific implementation of a method already provided by its parent class. The method in the subclass must have the same name, return type, and parameter list as in the parent class . Example: ``` class Animal { void sound() { System.out.println("Animal sound"); } } class Dog extends Animal { @Override void sound() { System.out.println("Bark"); } } ```

Thread synchronization in Java ensures that only one thread can access a resource at a time to prevent data inconsistency and conflicts. It is achieved using synchronized methods or blocks, allowing safe resource sharing between threads by enforcing a mutual exclusion rule .

Primitive data types in Java include byte (8 bits), short (16 bits), int (32 bits), long (64 bits), float (32 bits), double (64 bits), char (16 bits), boolean (1 bit). They are predefined by the language and named by a reserved keyword. Unlike reference data types, which store references to actual data, primitive data types store actual values .

Exception handling in Java ensures the smooth execution of a program by managing runtime errors. Checked exceptions (e.g., IOExceptions) must be declared in a method or constructor's throws clause if they can be thrown by the execution, while unchecked exceptions (runtime exceptions, e.g., NullPointerException) are not checked at compile time. Developers should handle checked exceptions to prevent system crashes and enhance fault tolerance .

Static methods belong to the class, not instances, and can be called without an object. Non-static methods belong to an instance of the class and require an object for invocation. Example: ```java class Example { static void staticMethod() { System.out.println("Static Method"); } void nonStaticMethod() { System.out.println("Non-static Method"); } } Example.staticMethod(); // No object needed Example obj = new Example(); obj.nonStaticMethod(); // Object needed ```

The 'break' statement terminates the loop or switch statement, while 'continue' skips the current iteration of the loop. Example: ```java for (int i = 0; i < 10; i++) { if (i == 5) break; // exits loop when i is 5 if (i % 2 == 0) continue; // skips even numbers System.out.println(i); // prints odd numbers till 5 } ```

'finally' is a block associated with a try-catch structure that executes mandatory code after try/catch blocks, regardless of whether an exception is thrown. 'finalize' is a method that the garbage collector calls before object deletion to perform cleanup operations. Example of 'finally': ```java try { /* risky code */ } finally { /* cleanup code */ } ``` Example of 'finalize': ```java @Override protected void finalize() throws Throwable { /* cleanup code */ } ```

A Java interface is an abstract type used to specify a behavior that classes must implement. It supports multiple inheritance by allowing a class to implement multiple interfaces. This way, an object can use functionalities defined in multiple interfaces, overcoming the multiple inheritance limitation in class hierarchies .

The Producer-Consumer problem can be addressed using multithreading by managing shared resources with synchronization. A common approach uses wait() and notify() methods. Example: ```java class SharedResource { private int content; private boolean empty = true; public synchronized void produce(int value) throws InterruptedException { while (!empty) wait(); content = value; empty = false; notify(); } public synchronized int consume() throws InterruptedException { while (empty) wait(); empty = true; notify(); return content; } } ```

The CLASSPATH environment variable in Java specifies the path where the Java Runtime Environment (JRE) looks for classes and packages during execution. If CLASSPATH is set incorrectly, the Java programs may not find required classes or packages, leading to runtime errors .

You might also like