22100311 Java Scheme-2022

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

QP CODE: 22100311

B.Sc DEGREE (CBCS ) REGULAR / REAPPEARANCE EXAMINATIONS,JANUARY 2022


Fifth Semester
CORE COURSE - CS5CRT14 - JAVA PROGRAMMING USING LINUX
Part A
Answer any six questions.
Each question carries 3 marks.

1. Differentiate between object oriented and procedure oriented programming.


Procedural Programming:based upon the concept of calling procedure. Procedures, also known as
routines, subroutines or functions, simply consist of a series of computational steps to be carried out.
During a program’s execution, any given procedure might be called at any point, including by other
procedures or itself.
Object Oriented Programming: can be defined as a programming model which is based upon the concept
of objects. Objects contain data in the form of attributes and code in the form of methods. In object
oriented programming, computer programs are designed using the concept of objects that interact with
real world. Object oriented programming languages are various but the most popular ones are class-
based, meaning that objects are instances of classes, which also determine their types.
2. Explain the use of continue statement.
The continue statement passes control to the next iteration of the nearest enclosing do , for , or while
statement in which it appears, bypassing any remaining statements in the do , for , or while statement
body.
3. Define classes and objects.
Class is a user-defined datatype that has its own data members and member functions whereas an object
is an instance of class by which we can access the data members and member functions of the class.
4. What are constructors?
A constructor in Java is a special method that is used to initialize objects. The constructor is called
when an object of a class is created. A constructor has the same name as that of the class and does
not have any return type.
5. What is the use of protected keyword in java?
Protected keyword in Java refers to one of its access modifiers. The methods or data members declared
as protected can be accessed from:
Within the same class.
Subclasses of same packages.
Different classes of same packages.
Subclasses of different packages.
6. What is two dimensional array?
A 2D array is an array of one-dimensional arrays. In Java, a two-dimensional array is stored in the
form of rows and columns and is represented in the form of a matrix.
7. What is nested try statement?
A try-catch-finally block can reside inside another try-catch-finally block that is known as nested try
statement in Java.When you have nested try statements in your code, in case an exception is thrown
the inner most try-catch block gets the first chance to handle that exception, if that try-catch block can
not handle the exception, the exception goes up the hierarchy (next try-catch block in the stack) and
the next try statement's catch block handlers are inspected for a match. If no catch block, with in the
hierarchy, handles the thrown exception then the Java run-time system will handle the exception.
8. Why swing component are called lightweight components?
Swing is considered lightweight because it is fully implemented in Java, without calling the native
operating system for drawing the graphical user interface components.
9. Define Window Event Class
The object of this class represents the change in state of a window. This event is generated by a
Window object when it is opened, closed, activated, deactivated, iconified, or deiconified, or when
focus is transferred into or out of the Window.
10. Diffrentiate between swing and Jpanel.
JPanel is a lightweight container generally used to organize Graphic user interface components.
JPanels are added on top of JFrame. It inherits the JComponents class of Swing. Swing are used to
develop window-based applications in Java. The javax.swing API provides all the component classes
like JButton, JTextField, JCheckbox, JMenu, etc. The components of Swing are platform-
independent.
11. Distinguish between init() and distroy() methods in applet.
The init() method is the first method to run that initializes the applet. It can be invoked only once at
the time of initialization. The web browser creates the initialized objects, i.e., the web browser (after
checking the security settings) runs the init() method within the applet.
The destroy() method destroys the applet after its work is done. It is invoked when the applet window
is closed or when the tab containing the webpage is closed. It removes the applet object from memory
and is executed only once. We cannot start the applet once it is destroyed.
12. How parameters can be passed to applet using tag?
Parameters are passed to applets in NAME=VALUE pairs in <PARAM> tags between the opening
and closing APPLET tags. Inside the applet, we can read the values passed through the PARAM tags
with the getParameter() method of the java. applet. Applet class.
Part B
Answer any four questions.
Each question carries 8 marks.
13. Explain the characterset of Java Program
The character set is a set of alphabets, letters and some special characters that are valid in Java
language.The smallest unit of Java language is the characters need to write java tokens.
These character set are defined by Unicode character set.Explain each.
14. Write a Java program to find the smallest among 3 numbers
public class Smallest {
public static void main(String[] args) {
int a = 20;
int b = 10;
int c = 30;
int smallest;
if(a<b) {
if(c<a) { smallest = c; }
else { smallest = a; }
}
else { if(b<c) { smallest = b; }
else { smallest = c; }
}
System.out.println(smallest + " is the smallest.");
}
}

OR

public class Smallest {


public static void main(String[] args) {
int a = 20;
int b = 10;
int c = 30;
int smallest;
if(a<b) {
smallest=a
else smallest=b;
}
If(c<smallest) smallest=c;
System.out.println(smallest + " is the smallest.");
}
15. Explain method overloading with example
Method Overriding - Method overriding, in object-oriented programming, is a language feature that
allows a subclass or child class to provide a specific implementation of a method that is already provided
by one of its superclasses or parent classes. (Explanation with its syntax and a suitable example )
16. How will you implement hierarchical inheritance in Java?
In Hierarchical Inheritance, the multiple child classes inherit the single class or the single class is
inherited by multiple child class.Syntax of Hierarchical Inheritance in Java:
class Subclassname1 extends Superclassname
{
// variables and methods
}
class Subclassname2 extends Superclassname
{
// variables and methods
}
Explanation with an example program.
17. Explain about user defined packages.
User-defined packages are those packages that are designed or created by the developer to categorize
classes and packages. It can be imported into other classes and used the same as we use built-in
packages.
Steps to create package in Java
1. First create a directory within name of package.
2. Create a java file in newly created directory.
3. In this java file you must specify the package name with the help of package keyword.
4. Save this file with same name of public class
Give a simple example
18. Write a Java program to demonstrate thread priorities.
public class A implements Runnable
{
public void run()
{
System.out.println(Thread.currentThread());
}
public static void main(String[] args)
{
A a = new A();
Thread t = new Thread(a, "NewThread");
System.out.println("Priority of Thread: " +t.getPriority());
System.out.println("Name of Thread: " +t.getName());
t.start();
}
}
(Any program which demonstrate thread priorities)
19. Develop a simple program to implement KeyEvent class.
import java.awt.*;
import java.awt.event.*;
public class KeyListenerExample extends Frame implements KeyListener {
Label l;
TextArea area;
KeyListenerExample() {
l = new Label();
l.setBounds (20, 50, 100, 20);
area = new TextArea();
area.setBounds (20, 80, 300, 300);
area.addKeyListener(this);
add(l);
add(area);
setSize (400, 400);
setLayout (null);
setVisible (true);
}
public void keyPressed (KeyEvent e) {
l.setText ("Key Pressed");
}
public void keyReleased (KeyEvent e) {
l.setText ("Key Released");
}
public void keyTyped (KeyEvent e) {
l.setText ("Key Typed");
}
public static void main(String[] args) {
new KeyListenerExample();
}
}
(Any program which implement KeyEvent class.)
20. Write an applet that receives three numeric values as input from the user and display the
largest.
importjava.applet.*;
importjava.awt.*;
importjava.awt.event.*;
public class largenumber extends Applet implements ActionListener
{
TextField t1,t2,t3,t4;
Button b1;
public void init()
{
setLayout(null);
t1 = new TextField(15);
t1.setBounds(100,25,50,20);
t2 = new TextField(15);
t2.setBounds(100,50,50,20);
t3 = new TextField(15);
t3.setBounds(100,75,50,20);
t4 = new TextField("Ans");
t4.setBounds(175,40,50,20);
b1 = new Button("Find");
b1.setBounds(175,65,50,30);
add(t1);
add(t2);
add(t3);
add(t4);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
inti,j,k;
i = Integer.parseInt(t1.getText());
j=Integer.parseInt(t2.getText());
k=Integer.parseInt(t3.getText());
if(i<j)
{
if(j<k)
t4.setText(""+k);
else
t4.setText(""+j);
}
else
t4.setText(""+i);
}
}
21. What are JDBC statements?
Statement : Used to implement simple SQL statements with no parameters.
PreparedStatement : (Extends Statement .) Used for precompiling SQL statements that might contain
input parameters. ...
CallableStatement: (Extends PreparedStatement .)
Explain with a suitable example.
Part C
Answer any three questions.
Each question carries 15 marks. Maximum marks 30 only.

22. Illustrate the use of different operators in Java.


Unary
Operator,ArithmeticOperator,ShiftOperator,RelationalOperator,BitwiseOperator,LogicalOperator,Ter
nary Operator andAssignment Operator.Explain each and give an example program to illustrate all the
operators.
23. Diffrentiate final methods and final classes with examples.
If a class its final, it can't be subclassed. If a method its final it can't be overriden by any subclass.
Explain each with suitable examples.

24. a) Differentiate between one-dimensional , two-dimensional arrays with appropriate syntax


& examples b) Write a Java program to sort numbers & sort names in 2 different arrays.
a) 1D array is a simple data structure that stores a collection of similar type data in a contiguous block
of memory while the 2D array is a type of array that stores multiple data elements of the same type in
matrix or table like format with a number of rows and columns. Thus, this is the main difference
between 1D and 2D array. The syntax for 1D array is, data-type[] name = new data-type[size]; while
the syntax for 2D array is, data-type[][] name = new data-type[rows][columns]; Give suitable
examples.(8)
b) Java program to sort numbers & sort names in 2 different arrays.(7)

25. What is Layout manager? Explain any three layout managers in which method is used toset the layout
manager.
The LayoutManagers are used to arrange components in a particular manner. The Java LayoutManagers
facilitates us to control the positioning and size of the components in GUI forms.
BorderLayout, FlowLayout ,GridLayout, CardLayout, GridBagLayout, BoxLayout, GroupLayout,
ScrollPaneLayout , SpringLayout etc.
Explain any of the three with example.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy