0% found this document useful (0 votes)
14 views3 pages

Java and C++ Programming Questions Bank

The document is a Java Questions Bank for the Faculty of Engineering & Technology's Department of Computer Science & Engineering, organized into five modules. Each module contains various questions and programming tasks covering topics such as Object-Oriented Programming, Java features, inheritance, threading, and applet development. The questions aim to assess knowledge and practical skills in Java programming and related concepts.

Uploaded by

anmolsimpi63
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)
14 views3 pages

Java and C++ Programming Questions Bank

The document is a Java Questions Bank for the Faculty of Engineering & Technology's Department of Computer Science & Engineering, organized into five modules. Each module contains various questions and programming tasks covering topics such as Object-Oriented Programming, Java features, inheritance, threading, and applet development. The questions aim to assess knowledge and practical skills in Java programming and related concepts.

Uploaded by

anmolsimpi63
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

Faculty of Engineering & Technology (Coed)

Department of Computer Science & Engineering

Java Questions Bank

Module I

1. Distinguish between Procedure Oriented and Object Oriented Programming.


2. What is OOP? Explain three principles of Object oriented programming.
3. Compare C, C++ and JAVA.
4. Explain console input and output.
5. Implement a C++ program to find area of rectangle (area=base*height),Area of circle
(area=pi*r*r)and area of triangle(area=1/2*base*height) using function overloading concepts. Call
these functions from main with suitable inputs.
6. Define variable? Explain reference variables in C++ with programming example.
7. What is function prototyping? Explain with syntax and example.
8. Define function overloading? Explain with an example.
9. Develop a program to show the working of scope resolution operator.
10. Write a note on scope resolution operator and this pointer.
11. Discuss the declaration and usage of static data member?
12. What is an inline function? What are the advantages of inline function? Give a suitable example.
13. Why friend functions are required? Write a C++ program to illustrate the use of friend function.

Module II

1. List and explain the features of JAVA


2. Explain scope and life time of variables with example.
3. Discuss primitive data types used in JAVA.
4. Explain bit-wise logical operators consider a=3 and b=6 apply bit wise logical operator on their
operands and print suitable results.
5. Explain Boolean logical operators with example.
6. With an example explain ternary operators? Write a program to find biggest among 3 members
using ternary operator.
7. What is type conversion and type casting in java? Write a java program to illustrate type casting
of the data type and type conversion.
8. What are access specifiers? Explain them.
9. Explain the concept of array in java with an example.

10. With syntax and example explain if,if-else and nested if statements.
11. With suitable example explain the jump statements.
12. Explain with an example while and do-while loop.
13. How for each is different from for loop? Develop a program to show the working of for each
loop.
14. What is class? How to declare the object for the class explain with an example.
15. Define constructor? What are the rules to write constructors? Give an example.
16. Discuss the following
1) Default constructor
2) parameterized constructor
17. Explain the following
1) use of this keyword
2) Garbage collection.

Module III

1. Define inheritance? Explain with suitable example.


2. Develop a program to show the use of super keyword.
3. Explain method overriding with an example?
4. Write a program in Java that implements multi-level inheritance.
5. Distinguish between method overloading and method overriding in java with suitable example.
6. What is an exception? Explain the following
i)try
ii)catch
iii)throw
iv)throws
v) finally
7. What is an interface? Explain how to define and implement by taking suitable example.
8. What is package? How to create and import package in java. Explain with an example.
9. Describe the levels of access protection available for packages.
10. Differentiate between class and interface.
11. Explain nested interface with an example.
12. Explain the following with example
a) Creating a multilevel-hierarchy.
b) Variables in interface.
13. What is nested try? Explain with an example.

Module IV

1. What is thread? Explain two ways of creating a Thread in java.


2. Define Synchronization? Explain synchronization method.
3. Write a java program for Producer and Consumer problems in threads.
4. Write a java program that creates threads by extending tread class.
a. First thread display “Good Morning” every 1 sec.
b. Second thread displays “Hello “every 2 seconds.
c. Third display “Welcome” every 3 seconds.
5. Explain with an example inter-thread communication.
6. How to change state of thread. Explain with an example?
7. What is event handling? List out the available event classes and explain it.
8. Briefly explain delegation event model.
9. List and explain event-listener interfaces.
10. Discuss about following using delegation event model.
a) Handling mouse events.
b) Handling keyboard events.
11. Explain the following
a) ActionEvent Class
b) AdjustmentEvent Class
c) ContainerEvent Class
d) InputEvent Class
e) MouseEvent Class

Module V

1. What is an applet? Explain two types of applets.


2. Describe any 5 methods defined by Applet.
3. Explain Paint() and Repaint() methods of an applet.
4. Explain the skeleton of an Applet.
5. Write a simple Applet program to print the message “This is my simple Applet” with suitable
steps to execute an Applet.
6. Discuss the HTML Applet Tag with its syntax.
7. How to pass parameters to Applet? Explain with an example.
8. Explain the concept of getDocumentBase() and getCodeBase() with examples.
9. How do applet different from application? Explain with an example.
10. Define InputStream? Explain the methods defined by InputStream.
11. Define OutputStream? Explain the methods defined by OutputStream.
12. Explain FileInputStream with an example.
13. Explain FileOutputStream with an example.
14. Briefly explain PrintStream.

Common questions

Powered by AI

The three primary principles of object-oriented programming are encapsulation, inheritance, and polymorphism. Encapsulation involves binding data and functions that manipulate the data into a single unit or class, thus protecting it from outside interference and misuse. Inheritance allows a new class to inherit properties and behaviors from an existing class, facilitating code reuse and the creation of a more hierarchical structure. Polymorphism allows objects to be treated as instances of their parent class, with method overriding enabling specific behaviors in subclasses. These principles help in managing complexity, promoting code reuse, and enhancing maintainability .

Function overloading in C++ is the ability to create multiple functions of the same name with different implementations. These functions must differ in the number or types of their parameters. The correct function is selected based on the arguments provided at the call site. For example, consider the following C++ program: ```cpp #include <iostream> using namespace std; int area(int base, int height) { return base * height; } double area(double radius) { return 3.14159 * radius * radius; } double area(double base, double height) { return 0.5 * base * height; } int main() { cout << "Area of Rectangle: " << area(5, 10) << endl; cout << "Area of Circle: " << area(3.0) << endl; cout << "Area of Triangle: " << area(4.0, 5.0) << endl; return 0; } ``` This example demonstrates overloading by defining three `area` functions differing in parameter type and number .

Inter-thread communication in Java is used to avoid busy waiting and allows threads to communicate with each other by waiting, notifying, or notifying all threads in a synchronized context. The `wait`, `notify`, and `notifyAll` methods of the `Object` class are used to achieve this. A thread can release the lock it holds on an object by calling `wait`, allowing other threads to acquire the lock. A simple example is the Producer-Consumer problem: ```java class Main { private int count = 0; public synchronized void produce() throws InterruptedException { while (count == 10) wait(); count++; notify(); } public synchronized void consume() throws InterruptedException { while (count == 0) wait(); count--; notify(); } } ``` In this case, `produce` and `consume` manage `count`, using `wait` and `notify` to signal when an action like production or consumption can proceed safely .

C is a procedural programming language emphasizing function calls, limited to procedural-based paradigms, and lacks support for object-oriented programming natively. C++ extends C by introducing object-oriented features such as classes and objects, enabling encapsulation, inheritance, and polymorphism directly. Java, while syntactically similar to C++, is object-oriented from the ground up, enforcing OOP principles and simplifying memory management through automatic garbage collection. Java offers platform independence through the Java Virtual Machine (JVM), which is not available in C or C++ .

Procedure-oriented programming (POP) is structured around procedures or functions. In POP, the primary focus is on writing procedures or functions that operate on data, often leading to the global appearance of data, which can inadvertently modify data all over the program. Object-oriented programming (OOP), on the other hand, structures the program around objects rather than functions. It treats data as a critical element and ties it within the objects to which they belong, thereby encapsulating data and functions together. OOP uses principles such as encapsulation, inheritance, and polymorphism to create a more modular architecture .

Synchronization in Java is a mechanism that ensures that two or more concurrent threads do not simultaneously execute some particular program segment, known as critical section. The `synchronized` keyword is used to lock an object for any shared resource. Synchronized methods or blocks prevent issues like data inconsistency and thread interference. For instance, ```java class SyncCounter { private int count = 0; public synchronized void increment() { count++; } public int getCount() { return count; } } ``` In this example, the `increment` method is synchronized to prevent simultaneous access by multiple threads, which could otherwise lead to incorrect count updates .

Method overloading in Java is creating multiple methods in the same class with the same name but different parameter lists, enabling different implementations based on the argument sets provided. For example, ```java class MathUtils { int multiply(int a, int b) { return a * b; } double multiply(double a, double b) { return a * b; } } ``` Method overriding, in contrast, occurs when a subclass provides a specific implementation for a method that is already defined in its superclass, allowing polymorphic behavior. For instance, ```java class Animal { void sound() { System.out.println("Animal sound"); } } class Dog extends Animal { void sound() { System.out.println("Bark"); } } ``` Here, `Dog` overrides the `sound` method of `Animal` to provide its own functionality .

The `this` keyword in Java is used to refer to the current object within a method or a constructor. It is predominantly used to resolve naming conflicts, most commonly in constructor and method overloading. When instance variables and parameters share names, the `this` keyword helps differentiate them. For example: ```java class Car { private String model; public Car(String model) { this.model = model; // 'this' differentiates the instance variable from the parameter } public void printModel() { System.out.println("Model: " + this.model); } } ``` Here, `this.model` refers to the instance variable, helping avoid confusion and ensuring clarity in object-oriented design by maintaining a clear reference to the current object instance .

Function prototyping in C++ involves declaring a function before its actual implementation, specifying its name, return type, and parameters. It allows the compiler to check the function calls for correct number and types of arguments, thus catching errors at compile time rather than run time. For instance, a prototype might be declared as `int add(int, int);` followed by its definition: ```cpp #include <iostream> using namespace std; int add(int a, int b); // Function prototype int main() { cout << "Sum: " << add(5, 10) << endl; return 0; } int add(int a, int b) { // Function definition return a + b; } ``` This program uses a function prototype to ensure correct add function usage .

Access specifiers in Java control the accessibility of classes, methods, and variables, enhancing security by restricting unauthorized access. The four main specifiers are `public`, `protected`, `default` (package-private), and `private`. `Public` allows access from any other class, `protected` allows access within the same package and by subclasses, `default` restricts visibility to the package, and `private` restricts access to within the same class only. For example, marking a variable `private` in a class ensures it cannot be accessed directly from outside, enforcing encapsulation and allowing controlled access through methods, thereby protecting class integrity .

You might also like