0% found this document useful (0 votes)
4 views5 pages

Core Java Paper (Solved)

The document covers core concepts of Java programming, including architectural neutrality, variable types in switch statements, the purpose of packages, and the differences between applets and applications. It also discusses exception handling, the Runnable interface, socket programming, and the differences between Swing and AWT components. Additionally, it explains JDBC and the order of method invocation in applets.

Uploaded by

Jhonson
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)
4 views5 pages

Core Java Paper (Solved)

The document covers core concepts of Java programming, including architectural neutrality, variable types in switch statements, the purpose of packages, and the differences between applets and applications. It also discusses exception handling, the Runnable interface, socket programming, and the differences between Swing and AWT components. Additionally, it explains JDBC and the order of method invocation in applets.

Uploaded by

Jhonson
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

Core Java Programming B.C.A.

(Part-III)
Part - I

(1.)

(a.) Why is Java Architectural Neutral?


- Byte code can run on any Architecture that is why it is call Architectural neutral, just you need JVM. Its compiler
generates an architecture-neutral object file format, which makes the compiled code to be executable on many
processors, with the presence of Java runtime system.

(b.) What type of variable can be used in a switch statement?


- The variable used in a switch statement can only be integers, convertible integers (byte, short, char), strings and
enums. The value for a case must be the same data type as the variable in the switch and it must be a constant
or a literal.

(c.) Why Packages are used?


- One of the main features of OOP is its ability to reuse of code already created. It is another way of achieving the
reusability in java therefore is to use packages. Package is collection of various varieties of classes and interface.

(d.) Which are the two subclasses under Exception class?


- Exception class has two main sub classes :

(1) Runtime exception - Runtime Exception is the superclass of those exceptions that can be thrown during the
normal operation of the Java Virtual Machine. Runtime Exception and its subclasses are unchecked exceptions.

(2) IOexception (input –output exception) - Signals that an I/O exception of some sort has occurred. This class is the
general class of exceptions produced by failed or interrupted I/O operations. Static keyword. A Java keyword used
to define a variable as a class variable

(e.) What is the difference between a Window and a Frame?


- A window is undecorated frame. That is does not have title bar, border and any closed [Link] is just a
container .which holds children on it like a button label, text field etc. Simple we can say imaginary rectangle.

A frame is derived from windows but it has a title bar, border, close button, minimize button, resize button
movable [Link] default if also has border layout.

Frame Window
It is a window with title bars and borders. It is an imaginary rectangle area on the monitor.
Frame is within a window. Window will not in a frame.
It has title bar, border, close button, minimize button, It does not have title bar, border and any close button.
resizable and movable options.
Frame is a part of a window. Window is not a part of window.

(f.) What is Swing?


- Swing is a GUI widget toolkit for Java. It is part of Oracle's Java Foundation Classes (JFC) – an API for providing a
graphical user interface (GUI) for Java programs. Unlike AWT components, Swing components are not implemented
by platform-specific code.
(g.) What is the difference between application and applets?

- (answer in 2 number question)

Appplet Application

Applet is small java program Application is large java program


Used to run a program on client Browser Can be run on stand-alone application
Applet is portable and can be executed by any java Need to executed JDK,JRE ,JVM installed on client
supported browser
Applet are created by extending Applet class in [Link] Application are created by writing public static void main
(String args[] ) method.

- (answer in 4 number question)

Applet Application
Small Program Large Program
Used to run a program on client Browser Can be executed on stand-alone computer system
Applet is portable and can be executed by any JAVA supported
Need JDK, JRE, JVM installed on client machine.
browser.
Applet applications are executed in a Restricted Environment Application can access all the resources of the computer
Applications are created by writing public static void main(String[] s)
Applets are created by extending the [Link]
method.
Applet application has 5 methods which will be automatically invoked
Application has a single start point which is main method
on occurrence of specific event
Example:
import [Link].*;

import [Link].*;

public class Myclass extends Applet public class MyClass


{ {
public void init() { } public static void main(String args[]) {}
public void start() { } }
public void stop() {}

public void destroy() {}

public void paint(Graphics g) {}

(h.) What is Runnable in Java?


- The Runnable interface should be implemented by any class whose instances are intended to be executed by a
thread. The class must define a method of no arguments called run . This interface is designed to provide a common
protocol for objects that wish to execute code while they are active.

(i.) What is a Socket?


- A socket is an endpoint of a two-way communication link between two programs running on
the network. Socket is bound to a port number so that the TCP layer can identify the application that data is
destined. To be sent. Java provides a set of classes, defined in a package called [Link], to enable the rapid
(j.) Which class is used by a server application to obtain a port and listen for client request?

- Java Socket programming is used for communication between the applications running on different JRE. Java Socket
programming can be connection-oriented or connection-less. Socket and ServerSocket classes are used for connection-
oriented socket programming and DatagramSocket and DatagramPacket classes are used for connection-less socket
programming.

The client in socket programming must know two information:


1. IP Address of Server, and
2. Port number.

Part - II

(2.)

(a.) Is Java a pure object oriented language? If not why?


- Java is not pure OOP because it supports Primitive data type such as int, byte, long... etc, to be used, which are not
objects. Contrast with a pure OOP language like Smalltalk, where there are no primitive types, and boolean, int and
methods are all objects. ... i think Smalltalk can be considered pure object oriented than java.
Everything in Java is not considered as an Object, there are primitive data types available. All features of OOP
language is not fully supported by Java. Ex : Multiple Inheritance, Operator Overloading, etc.

(b.) What is the difference between throw and throws?


-

S.N. throw throws


1) Java throw keyword is used to explicitly Java throws keyword is used to declare an exception.
throw an exception.
2) Checked exception cannot be propagated Checked exception can be propagated with throws.
using throw only.
3) Throw is followed by an instance. Throws is followed by class.
4) Throw is used within the method. Throws is used with the method signature.
5) You cannot throw multiple exceptions. You can declare multiple exceptions e.g.
public void method() throws IOException,
SQLException.
6) Example - 1. Example -
1. void m() 2. void m()throws ArithmeticException
2. { 3. {
3. throw new ArithmeticException("sorry"); 4. //method code
4. } 5. }
(c.) What is the difference between Swing and AWT components?
AWT Swing

AWT stands for Abstract windows toolkit. Swing is also called as JFC’s (Java Foundation classes).

AWT components are called Heavyweight component. Swings are called light weight component because swing
components sits on the top of AWT components and do
the work.

AWT components require [Link] package. Swing components require [Link] package.

AWT components are platform dependent. Swing components are made in purely java and they are
platform independent.

This feature is not supported in AWT. We can have different look and feel in Swing.

This feature is not available in AWT. Swing has many advanced features like JTabel, Jtabbed
pane which is not available in AWT. Also. Swing
components are called "lightweight" because they do not
require a native OS object to implement their
functionality. JDialog and JFrame are heavyweight,
because they do have a peer. So components like
JButton, JTextArea, etc., are lightweight because they do
not have an OS peer.

With AWT, you have 21 "peers" (one for each control and With Swing, you would have only one peer, the operating
one for the dialog itself). A "peer" is a widget provided by system's window object. All of the buttons, entry fields,
the operating system, such as a button object or an entry etc. are drawn by the Swing package on the drawing
field object. surface provided by the window object. This is the reason
that Swing has more code. It has to draw the button or
other control and implement its behavior instead of
relying on the host operating system to perform those
functions.

AWT is a thin layer of code on top of the OS. Swing is much larger. Swing also has very much richer
functionality.

Using AWT, you have to implement a lot of things Swing has them built in.
yourself.

(d.) What is the order of method invocation in an Applet?

- The Applet’s life cycle methods are as follows:

public void init() : Initialization method called only once by the browser.

public void start() : Method called after init() and contains code to start processing. If the user leaves the page
and returns without killing the current browser session, the start () method is called without being preceded by
init ().
public void stop() : Stops all processing started by start (). Done if user moves off page.

public void destroy() : Called if current browser session is being terminated. Frees all resources used by the
applet.

(e.) What does JDBC do?

- The JDBC API is a Java API that can access any kind of tabular data, especially data stored in a Relational Database.

JDBC helps you to write Java applications that manage these three programming activities:

1. Connect to a data source, like a database


2. Send queries and update statements to the database
3. Retrieve and process the results received from the database in answer to your query

The following simple code fragment gives a simple example of these three steps -

public void connectToAndQueryDatabase(String username, String password)


{

Connection con = [Link]("jdbc:myDriver:myDatabase", username, password);

Statement stmt = [Link]();


ResultSet rs = [Link]("SELECT a, b, c FROM Table1");

while ([Link]())
{
int x = [Link]("a");
String s = [Link]("b");
float f = [Link]("c");
}
}

This short code fragment instantiates a DriverManager object to connect to a database driver and log into the database,
instantiates a Statement object that carries your SQL language query to the database; instantiates a ResultSet object
that retrieves the results of your query, and executes a simple while loop, which retrieves and displays those results. It's
that simple.

You might also like