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

Java Programming Model Question Paper

This document is a model question paper for the Java Programming course at Adichunchanagiri University, designed for sixth semester B.E students. It consists of five modules, each containing multiple questions that cover various Java concepts, including Object-Oriented Programming, constructors, packages, exception handling, and applet life cycles. Students are instructed to answer five full questions, selecting one from each module, within a time limit of three hours for a maximum of 100 marks.

Uploaded by

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

Java Programming Model Question Paper

This document is a model question paper for the Java Programming course at Adichunchanagiri University, designed for sixth semester B.E students. It consists of five modules, each containing multiple questions that cover various Java concepts, including Object-Oriented Programming, constructors, packages, exception handling, and applet life cycles. Students are instructed to answer five full questions, selecting one from each module, within a time limit of three hours for a maximum of 100 marks.

Uploaded by

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

MODEL QUESTION PAPER-I

ADICHUNCHANAGIRI UNIVERSITY
BGS Institute of Technology
Sixth Semester B.E
(CBCS Scheme)

Time: 3 Hours Max Marks: 100


SUBJECT: Java Programming 22CSOE63
Instructions: 1. Answer five full questions.
2. Choose one full question from each module.
3. Your answer should be specific to the questions asked.
4. Write the same question numbers as they appear in this question paper.
5. Write Legibly.

Module - 1
1) a. Explain the Java program compilation and execution process with a neat diagram. - 10M-
b. Describe the concept of Object-Oriented Programming in Java. Explain the five main OOP
principles with suitable examples. - 10M-

OR
2) a. Explain different data types in Java with examples and memory size. -10M-
b. Explain Various Control Statements used in Java with Example. -10M-
Module – 2
3) a. Write a Java program to demonstrate the use of instance variables and methods in a class.
-10M-
b. Explain with examples:
Default Constructor
Parameterized Constructor -10M-

OR

4) a. Explain the ‘this’ keyword and Finalize () method with an example. -10M-

b. Define Inheritance and explain types of Inheritance with example. -10M-

Module – 3
5) a. Explain the concept of Java packages. Discuss the types of packages in Java with suitable examples.
-10M-
b. What is CLASSPATH in Java? Explain its role in package handling. Also, explain how to set
and use CLASSPATH. -10M-

OR
6) a. What is an interface in Java? How does it support abstraction and multiple inheritance? Illustrate
with examples. -10M-

b. Write a Java program to implement multiple interfaces in a single class. Explain how Java handles
multiple inheritance using interfaces. -10M-

Module – 4
7) a. Discuss the use of try, catch, and finally blocks in Java with a suitable example. What is the
importance of the finally block? -10M-

b. What is the significance of multiple catch blocks in exception handling? Explain with a Java
program handling more than one exception. -10M-

OR

8) a. Describe the life cycle of a thread in Java. How do different methods like sleep(), start(), wait(),
and notify() affect it? -10M-

b. Explain two different ways to create threads in Java. Provide complete code examples using both
Thread class and Runnable interface. -10M-

Module – 5
9) a. Explain the life cycle of a Java Applet with suitable method descriptions. Illustrate the order of
method execution with a neat diagram. -10M-
b. Write a Java Applet program to draw basic shapes like line, rectangle, oval, arc, and demonstrate
the usage of Graphics class methods. Also, explain each method used. -10M-

OR
10) a. Write a Java program using Swing components to create a simple GUI form with labels, text fields,
and a submit button. Explain how components are initialized and events are handled. -10M-

b. Explain how controls like Button, Label, and TextField are added to a Java Applet using AWT. Write a
complete program to demonstrate these controls along with event handling. -10M-

********************

Common questions

Powered by AI

The Java program compilation process begins with the Java source code being saved in a file with a .java extension. This source file is compiled by the Java compiler (javac) into bytecode, which is saved in a .class file. The Java Virtual Machine (JVM) then interprets or compiles this bytecode into machine code suitable for the host operating system. This process can be represented in a diagram showing the flow from source code (.java) to bytecode (.class) to execution by JVM. The diagram also includes stages such as loading, linking, and initializing classes before program execution .

The CLASSPATH variable in Java specifies the directories or JAR files where the JVM should look for classes and packages when running a program. It affects package handling by ensuring the JVM locates the required classes during runtime. CLASSPATH can be set using the '-cp' or '-classpath' option in the command line or by setting the environment variable directly, e.g., 'set CLASSPATH=.;C:\libs\myLib.jar;'. Properly configuring CLASSPATH is crucial for JVM to resolve class dependencies correctly .

In Java, an interface is a reference type that can contain abstract methods and constants. It supports abstraction by allowing classes to implement the interface through its methods without revealing the implementation details. Java interfaces enable multiple inheritance because a class can implement multiple interfaces, allowing a class to inherit behavior from more than one parent type. For example, 'public class Car implements Vehicle, Electric { }' uses two interfaces. Unlike classes, interfaces allow different types to interact polymorphically with no knowledge of underlying implementations, achieving decoupling and high levels of abstraction .

In Java, a default constructor is a no-argument constructor automatically provided by the compiler if no constructors are explicitly defined. It initializes an object with default values. For example, 'public class Car { }' will work with 'Car myCar = new Car();'. A parameterized constructor, on the other hand, accepts arguments, allowing objects to be initialized with specific values. For example, 'public Car(String model) { this.model = model; }' allows 'Car myCar = new Car("Tesla");'. These constructors provide flexibility in object creation and initialization .

In Java, the 'this' keyword is used to refer to the current object in a method or constructor. It differentiates instance variables from parameters with the same name. For instance, 'this.variable' references the instance variable when it is shadowed by a method parameter or local variable. The 'finalize()' method is called by the garbage collector on an object before it is destroyed, allowing cleanup operations. However, reliance on 'finalize()' is discouraged due to unpredictability and performance concerns; it's better managed using try-with-resources or cleaner constructs .

Java packages are used to group related classes and interfaces, helping manage a large codebase by providing namespace management and access protection. There are two main types: built-in packages (like java.util, java.io) and user-defined packages. For example, a user-defined package can be created with 'package com.myapp;' at the beginning of a Java file. Classes within the same package can access each other's package-private members, promoting encapsulation and logical grouping of functionality. Packages also help avoid naming conflicts; for instance, two classes with the same name can exist in different packages .

In a Java Applet using AWT, controls such as Button, Label, and TextField are added by creating instances of these components and adding them to the applet's layout. For instance, 'Button b = new Button("Click Me"); add(b);'. Event handling is implemented by attaching listeners to these components. Listeners are interfaces with methods like 'actionPerformed(ActionEvent e)' to handle events (e.g., button clicks). An event handler is registered using 'b.addActionListener(this);' where the applet class implements 'ActionListener'. This approach allows dynamic and interactive UI behavior in Java applets .

The five main OOP principles in Java are Encapsulation, Abstraction, Inheritance, Polymorphism, and Class/Object. Encapsulation involves wrapping data (variables) and code (methods) together as a single unit (e.g., a class with private fields and public methods). Abstraction means hiding complex implementation details and showing only the necessary features of an object, often achieved with interfaces and abstract classes. Inheritance allows a new class to inherit properties and behavior from an existing class (e.g., 'extends' keyword usage). Polymorphism enables a single function to behave differently based on the object type (e.g., method overriding and overloading). Finally, classes and objects are fundamental building blocks, where a class is a blueprint for creating objects (instances).

A Java thread can be in one of several states: New, Runnable, Blocked, Waiting, Timed Waiting, and Terminated. The 'start()' method moves a thread from New to Runnable, where the OS's thread scheduler allocates CPU. The 'sleep()' method causes the thread to be in a Timed Waiting state for a specified duration, freeing CPU for other threads. 'wait()' puts the thread in a Waiting state, releasing the lock it holds, and it remains inactive until another thread calls 'notify()' or 'notifyAll()' on the same object, shifting it back to Runnable. Each state transition reflects control strategies over threading and resource allocation in concurrent programming .

The 'finally' block in Java is crucial for executing code that must run regardless of whether an exception is thrown in the associated 'try' block. Unlike 'catch' blocks, which handle specific exceptions, 'finally' ensures that cleanup code, such as closing resources, executes without being interrupted by exceptions. For example, a file opened in 'try' can be closed in 'finally', ensuring resource release even if an error occurs. 'Finally' enhances reliability by guaranteeing the execution of critical code sequences beyond error handling .

You might also like