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

Java Programming Exam Questions

This document outlines the examination structure for the I Semester B.A./B.Sc. in Computer Science, focusing on Object Oriented Programming using Java. It includes three parts with varying question formats, covering topics such as inheritance, constructors, Java features, and applet life cycles. The exam is scheduled for February/March 2024, with a total of 60 marks available.

Uploaded by

yashwanth k
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)
137 views2 pages

Java Programming Exam Questions

This document outlines the examination structure for the I Semester B.A./B.Sc. in Computer Science, focusing on Object Oriented Programming using Java. It includes three parts with varying question formats, covering topics such as inheritance, constructors, Java features, and applet life cycles. The exam is scheduled for February/March 2024, with a total of 60 marks available.

Uploaded by

yashwanth k
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

Illlfllililflflrflfililrflilflut

z6
NP - 27A
I Semester B.A-/8. Sc. Exami nation, February/Ma rch 2A24
II
s-
NFP) (F+R)
COMPUTER SCIENCE
Object Oriented Prograrnming using Java
Time :21/z Hours Max. Marks : 60

lnstruction : Answer all the Parts.

PART _ A
:,* \
l. Answer any four questions. Each que@n carries ._iIL
(4x2=$)
1) What is inheritance ? '%
.i
2) Define constructor. Give an example.
3) Explain the features of Java.
4) What are unary operators ?

5) What is an applet ?
6) What are exceptions ?

, PART-B
ll. Answer any four questions. Each question carries five marks. (4x5=20)
7) Explain the features of object oriented programming.
8) Bring out the differences between C programming and Java programming.
9) Explain methodpveriding with an example.
10) What are iteration statements ? Explain with an example.
11) EXplain the life cycle of a thread with a neat diagram.
12) What is the layout manager in Java ? Explain any two layouts briefly.

PART _ C

lll. Answer any four questions. Each carries eight marks. (4x8=32)
13) a) Explain all the access specifiers in Java. ,4
b) Write a note on Java data types. 4

P.T.O.
NP - 270 ffirflffi]iltflflltflfllflllil

14) Write a note on event handling'in Java. g


15) Explain applet life cycle with neat diagram. g
16) a) Explain any five methods of graphic class with an exampre. s
b) Mention any six GUI components in Java. g
17) a) Explain string methods in detail with an example. 6
b) Write difference between string and string butfer. 2
1s) a) what is package ? write a simple program and exprain the steps to
create a package. 6
b) Define user defined package. 2

j,'' I
'J

t,
/'b
fl
'r.,,f)

Common questions

Powered by AI

Exception handling in Java allows programs to deal with unexpected errors during execution, enhancing robustness and reliability. Java provides several mechanisms such as 'try', 'catch', 'finally', 'throw', and 'throws' to manage exceptions. 'try' blocks contain code that might throw exceptions, 'catch' blocks handle them, and 'finally' ensures cleanup actions. This structured handling prevents abrupt program termination, supports error logging, and allows recovery strategies .

An applet in Java is a small application that runs within a web browser environment, downloaded from a server, and executed under strict security constraints to prevent unauthorized operations. Unlike standalone applications executed directly by the Java Runtime Environment (JRE), applets cannot make arbitrary system-level operations or access local filesystem due to sandboxing. This makes them suitable for small, dynamic web interactions but limits functionality and flexibility compared to full applications .

In Java, 'String' objects are immutable, meaning they cannot be altered after creation, which enhances security and performance in multithreading. Conversely, 'StringBuffer' is mutable, allowing modifications without creating new objects, being thread-safe, and suitable for scenarios with frequent string manipulations. 'StringBuffer' operations can be slower due to synchronization overhead; use 'StringBuilder' if synchronization is not required .

Creating a package in Java involves defining a package name at the top of Java source files with the 'package' keyword. Compile the file, ensuring the package directory structure matches the package's fully qualified name. To use a package, import it using the 'import' keyword in a consuming class. User-defined packages encapsulate related classes, enhancing code organization and reducing naming conflicts among project libraries .

The applet life cycle in Java consists of four main stages: initialization (init), starting (start), stopping (stop), and destruction (destroy). Upon applet loading, the 'init()' method is called for setup activities. 'start()' is called to start or resume execution, for example when an applet is re-visited. 'stop()' pauses the applet when it is not visible. Finally, 'destroy()' is invoked to perform clean-up before unloading. This sequential lifecycle is crucial for managing resources effectively in applet-based applications .

Java provides different layout managers for GUI arrangement, including 'BorderLayout' and 'FlowLayout'. 'BorderLayout' arranges components in five areas: north, south, east, west, and center, ideal for responsive resizing. 'FlowLayout' places components in a left-to-right order, wrapping to the next line if necessary. As an example, 'FlowLayout' is used for casual alignment in small GUIs, while 'BorderLayout' is suited for more structured apps like a centralized control panel .

Inheritance in Java allows a class (subclass) to inherit fields and methods from another class (superclass), facilitating code reusability and logical hierarchy structuring. It supports polymorphism by enabling subclass instances to be treated as superclass instances, thereby promoting extensibility and maintenance ease. However, improper use can lead to complex dependencies, making systems harder to understand and change, which demands careful planning in design .

Unary operators in Java include increment (++), decrement (--), unary plus (+), unary minus (-), logical complement (!), and bitwise complement (~). For example, using 'int x = 10; ++x;' will increment the value of x by one, resulting in 11. Similarly, 'boolean flag = true; !flag;' will return false as the logical complement of true. These operators work directly on a single operand to produce a new value .

Iteration statements in Java, such as 'for', 'while', and 'do-while', are used to execute a block of code repeatedly. An example of a 'for' loop is 'for(int i = 0; i < 5; i++) { System.out.println(i); }', which prints numbers 0 to 4. These loops continue until a specified condition turns false, allowing for efficient repetition without manually writing each iteration, demonstrating their utility in tasks like traversing arrays .

Java offers features such as platform independence, support for object-oriented programming, automatic memory management, and a rich API that are not inherently available in C programming. C is procedure-oriented with direct memory access through pointers, whereas Java emphasizes security and portability without pointers. Java's object-oriented features include inheritance, encapsulation, and polymorphism, allowing for more robust and maintainable code structures compared to procedural C programming .

You might also like