Java Programming Using Linux, Semester 5 - 2018-21, Model Examination, January 2021

 Section A

Answer any 10 questions. Each question carries 2 marks.

  1. List out the OOPs Concepts.

Classes

Methods

Inheritance 

Polymorphism

Data abstraction

  1. Expand WORA

Write Once Run Anywhere

  1. Define inheritance

Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object. ... The idea behind inheritance in Java is that you can create new classes that are built upon existing classes

  1. Define abstract class and methods

Data abstraction is the process of hiding certain details and showing only essential information to the user.Abstraction can be achieved with either abstract classes or interfaces (which you will learn more about in the next chapter).

The abstract keyword is a non-access modifier, used for classes and methods:

  • Abstract class: is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class).

  • Abstract method: can only be used in an abstract class, and it does not have a body. 

  1. What is a package

Package in Java is a mechanism to encapsulate a group of classes, sub packages and interfaces. Packages are used for: Preventing naming conflicts. ... Providing controlled access: protected and default have package level access control. A protected member is accessible by classes in the same package and its subclasses.

  1. Define exception in Java

An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted and the program/Application terminates abnormally, which is not recommended, therefore, these exceptions are to be handled.

  1. List out two features of Java.

Simple-Java is very easy to learn, and its syntax is simple, clean and easy to understand.

Platform Independent  Java is platform independent because it is different from other languages like CC++, etc

  1. Define polymorphism

Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance

  1. Explain the syntax to draw a string using applets.

Using drawstring method

10 Expand JDBC.

Java database connectivity

  1. Define Delegation event model

  2. The delegation event model defines standard and consistent mechanisms to generate and process events. ... Its concept is quite simple: a source generates an event and sends it to one or more listeners. In this scheme, the listener simply waits until it receives an event.

12 Define an event

An event in Java is an object that is created when something changes within a graphical user interface. If a user clicks on a button, clicks 

(10 x 2 = 20 Marks)

Section B

Answer any 6 questions. Each question carries 5 marks.

13. Summarize the data types in JAVA


There are 8 types of primitive data types:

  • boolean data type

  • byte data type

  • char data type

  • short data type

  • int data type

  • long data type

  • float data type

  • double data type



14.  Outline the java program structure

  • Documentation Section

  • Package Declaration

  • Import Statements

  • Interface Section

  • Class Definition

  • Class Variables and Variables

  • Main Method Class

  • Methods and Behaviors


15. Summarise the benefits of constructor with an example.

Java, a constructor is a block of codes similar to the method. It is called when an instance of the class is created. At the time of calling constructor, memory for the object is allocated in the memory.

It is a special type of method which is used to initialize the object.

Every time an object is created using the new() keyword, at least one constructor is called.



16.  Compare final finalize and finally keyword.

Final class can't be inherited, final method can't be overridden and final variable value can't be changed. Finally is used to place important code, it will be executed whether exception is handled or not. Finalize is used to perform clean up processing just before object is garbage collected. ... Finalize is a method.


17.  Briefly explain the string methods


Java String Methods

Here are the list of the methods available in the Java String class. These methods are explained in the separate tutorials with the help of examples. Links to the tutorials are provided below:

  1. char charAt(int index): It returns the character at the specified index. Specified index value should be between 0 to length() -1 both inclusive. It throws IndexOutOfBoundsException if index<0||>= length of String.

  2. boolean equals(Object obj): Compares the string with the specified string and returns true if both matches else false.

  3. boolean equalsIgnoreCase(String string): It works same as equals method but it doesn’t consider the case while comparing strings. It does a case insensitive comparison.

  4. int compareTo(String string): This method compares the two strings based on the Unicode value of each character in the strings.

  5. int compareToIgnoreCase(String string): Same as CompareTo method however it ignores the case during comparison.


18. Explain the components of event handling

Components in Event Handling

  • Events

  • Event Sources

  • Event Listeners/Handlers

Events

  • The events are defined as an object that describes a change in the state of a source object.

  • The Java defines a number of such Event Classes inside java.awt.event package

  • Some of the events are ActionEvent, MouseEvent, KeyEvent, FocusEvent,  ItemEvent and etc.

Event Sources

  • A source is an object that generates an event.

  • An event generation occurs when an internal state of that object changes in some way.

  • A source must register listeners in order for the listeners to receive the notifications about a specific type of event.

  • Some of the event sources are Button, CheckBox, List, Choice, Window and etc.

Event Listeners

  • A listener is an object that is notified when an event occurs.

  • A Listener has two major requirements, it should be registered to one more source object to receiving event notification and it must implement methods to receive and process those notifications.

  • Java has defined a set of interfaces for receiving and processing the events under the java.awt.event package.

  • Some of the listeners are ActionListener, MouseListener, ItemListener, KeyListener, WindowListener and etc.


19. Demonstrate any two Mouse event handling methods

Methods of MouseListener interface

The signature of 5 methods found in MouseListener interface are given below:

  1. public abstract void mouseClicked(MouseEvent e);  

  2. public abstract void mouseEntered(MouseEvent e);  

  3. public abstract void mouseExited(MouseEvent e);  

  4. public abstract void mousePressed(MouseEvent e);  

  5. public abstract void mouseReleased(MouseEvent e);  


20. Make use of the applet life cycle and explain the applet skeleton model.

Lifecycle of Java Applet

  1. Applet is initialized.

  2. Applet is started.

  3. Applet is painted.

  4. Applet is stopped.

  5. Applet is destroyed.


21 Classify the different methods used in graphics programming

Commonly used methods of Graphics class:

  1. public abstract void drawString(String str, int x, int y): is used to draw the specified string.

  2. public void drawRect(int x, int y, int width, int height): draws a rectangle with the specified width and height.

  3. public abstract void fillRect(int x, int y, int width, int height): is used to fill rectangle with the default color and specified width and height.

  4. public abstract void drawOval(int x, int y, int width, int height): is used to draw oval with the specified width and height.

  5. public abstract void fillOval(int x, int y, int width, int height): is used to fill oval with the default color and specified width and height.

  6. public abstract void drawLine(int x1, int y1, int x2, int y2): is used to draw line between the points(x1, y1) and (x2, y2).

  7. public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): is used draw the specified image.

  8. public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used draw a circular or elliptical arc.




(6 x 5 = 30 Marks)



Section C

Answer any 2 questions. It carries 15 marks.

22. Compare the decision making statements in java with examples

1

if statement

An if statement consists of a boolean expression followed by one or more statements.

2

if...else statement

An if statement can be followed by an optional else statement, which executes when the boolean expression is false.

3

nested if statement

You can use one if or else if statement inside another if or else if statement(s).

4

switch statement

A switch statement allows a variable to be tested for equality against a list of values.

The ? : Operator

We have covered conditional operator ? : in the previous chapter which can be used to replace if...else statements. It has the following general form −


23. Demonstrate inheritance with examples

Single Inheritance

Multilevel inheritance

Hierarchical Inheritance

24.  Define exception handling in detail

Try

Catch

Throw

Throws

Finally


25.  Explain the swing architecture with examples

(2 x 15 = 30 Marks)

hierarchy of javax swing















Comments

Popular posts from this blog

UG, S1 BCA, First internal examination, Introduction to Problem Solving and Web Designing, September 2024