Sie sind auf Seite 1von 10

Ques.no.1: Explain any five features of Java.

Ans.1: Features of java:


Sun Microsystems defined the features of Java as Java is a
simple, object-oriented, distributed, interpreted, robust, secure,
architecture neutral, portable, high-performance, multithreaded and dynamic language.
Explanation:
Simple: According to Sun Microsystems, Java language
was designed to be easy for the programmer to learn
and use easily. It is simple as its syntax is based on C+
+. Java requires a little effort for C++ programmer
because java inherits the C++ syntax and many of the
object-oriented features of C++.
Secure: Due to strong type-checking done by Java on
the users machine, any changes to the program are
tagged as error and the program will not execute. Java
is, therefore, secure.
Multithreaded: Java was designed to meet the realworld requirement of creating interactive, networked
programs. Java supports multithreaded programming,
which allows user to write programs that do many
things simultaneously. The Java run-time system comes
with an elegant yet sophisticated solution for
multiprocess synchronization that enables the users to
construct smoothly running interactive systems. Java is
easy-to-use approach to multithreading allows one
about the specific behaviour of a program, not the
multitasking subsystem.
Distributed: Java is designed for the distributed
environment of the Internet, because it handles TCP/IP
protocols. The original version of Java (Oak) included
features for intra-address space messaging. This
allowed objects on two different computers to execute
procedures remotely. Java has recently revived these
interfaces in a package called Remote Method
Invocation (RMI) that brings an unparallel level of
abstraction to client/server programming.
Dynamic: Java programs carry with them substantial
amounts of run-time type information that is used to
verify and resolve accesses to objects at run time. This
makes it possible to dynamically link code in a safe and

expedient manner. This is crucial to the robustness of


the applet environment, in which small fragments of
bytecode can be dynamically updated on a running
system.

Ques.no.2: Describe main () methods in Java. What are


the rules for writing a main method?
Ans.2: Main () methods:
In a java application, there are many classes. Within those
classes, there are many methods. The method that are to be
execute first should be the main () method.
Syntax for the main () method:
Public static void main (String args [])
{
}
It is the major factor that the main method must exist in a class
that is declared as public.
Rules for writing a main method:
The primary name of the file in which the code is written,
and the name of the class that has the main () method
should be exactly the same.
If a user try to execute a java application that does not
have a main () method, following error message will be
printed:
Exception
in
java.lang.NoSuchMethodError: main

threadmain

Ques.no.3: Differentiate packages and interfaces


Ans.3: Differences between packages and interfaces:
The difference between packages and interfaces are described
below:
Packages:
Creating a package is quite easy: simply include a package
command as the first statement in a Java source file. Any
classes declared within that file will belong to the specified
package. The package statement defines a name space in
which classes are stored. If the package statement will be
omitted then the class names are put into the default
package, which has no name. While the default package is
fine for short, sample programs, it is inadequate for real
applications. Most of the time, user define a package for
their own code.
The general form of the package statement: package pkg;
Here, pkg is the name of the package.
Interfaces:
An interface can be defined much like a class. One class can
implement any number of interfaces but to implement an
interface, a class must create the complete set of methods
defined by the interface. However, each class is free to
determine the details of its own implementation.
Interfaces are designed to support dynamic method
resolution at run time and also since interfaces are in a
different hierarchy from classes, it is possible for classes that
are unrelated in terms of the class hierarchy to implement
the same interface. This is where the real power of interfaces
is realized.
Interfaces add most of the functionality that is required for
many applications which would normally resort to using
multiple inheritances in a language such as C++.
The interfaces specify the exact signatures of the methods
that must be provided. One should use the interface type as
a parameter for a method. Also, interfaces can be used to
mix in generally useful constants.
An interface is used to specify the form that something must
have, it does not actually provide the implementation for it.
It does not have any overtones of specialization that are

present with inheritance. It can also be used for supporting


callbacks.

Ques.no.4: How we can


occurrence of a substring?

search

the first and last

Ans.4: Searching of the first and last occurrence of a


substring:
The String class provides two process or method that allows a
user to search a string for a specified character or substring
mainly:
indexOf( ): It, searches for the first occurrence of a
character or substring.
lastIndexOf( ): It searches for the last occurrence of a
character or substring.
These two methods are overloaded in several different ways. In
all cases, the methods return the index at which the character
or substring was found, or -1 on failure.
For example,
To search for the first occurrence of a character, user
should use
int IndexOf(int ch);
To search for the last occurrence of a character, user
should use
int lastIndexOf(int ch);
Here, ch specifies character.
To search for the first occurrence of a substring, user
should use
int indexOf(String str);
To search for the last occurrence of a substring, user
should use
Int lastIndexOf(String str);
Here, str specifies the substring.
A starting point for the search can also be specified as:
For characters
For the first and last occurrence, user should use
int indexOf(int ch, int startIndex);
int lastIndexOf(int ch, int startIndex);
For String
For the first and last occurrence, user should use
int indexOf(String str, int startIndex);

int lastIndexOf(String str, int startIndex);


Here, startIndex specifies the index at which point the search
begins.
For indexOf( ), the search runs from startIndex to the end of
the string.
For lastIndexOf(), the search runs from startIndex to zero.
Ques.no.5: Compare JDBC and ODBC
Ans.5: Comparison of JDBC and ODBC:
On comparing JDBC and ODBC following information is collected
as described below:
o JDBC stands for Java Data Base Connectivity
o ODBC stands for Open Data Base Connectivity.
The JDBC API i.e. Java Data Base Connectivity Application
Program Interface can access any kind of tabular data,
especially the data stored in a Relational Database. JDBC works
on top of the ODBC that is the driver for database connectivity.
Since ODBC is implemented in C, for that users from the VB
background had to face some difficulties in understanding the
implementation intricacies.
JDBC helps in writing Java applications that manage mainly
three programming activities namely:
a. Connecting to a data source, like a database
b. Sending queries and updating statements to the database
c. Retrieving and processing the results received from the
database in answer to the query.
JDBC provides a database-programming interface for Java
programs. A java program can send queries to a database using
the JDBC driver. Since the ODBC is written in C language, a Java
program cannot directly communicate with an ODBC driver.
The ODBC is a standard database access method developed by
Microsoft Corporation. Its main goal is to make it possible to
access any data from any application, without having details of
which Database Management System or DBMS is handling the
data. ODBC manages all these by inserting a middle layer,
called a driver, between an application and the DBMS.
Mainly the purpose of this layer is to translate the queries of
the application into commands that the DBMS understands. For
this to work, both the application and the DBMS must be ODBCcompliant i.e. the application must be capable of issuing ODBC

commands and the DBMS must be capable of responding to


them.
Since JDBC works on top of ODBC we have something called as
a JDBC-ODBC bridge to access the database. JavaSoft created
the JDBC-ODBC bridge driver that translates the JDBC API to the
ODBC API. It is used with ODBC drivers. The JDBC-ODBC Bridge
allows you to use the ODBC driver as JDBC drivers.

Ques.no.6: Write a short note on the following:


a. Swing
b. JFC
Ans.6: Short note on the followings:
a. Swing: The Swing API is organized into a number
of packages to support APIs for various categories
of components. The various packages in the swing
libraries are described below:
javax.accessibility: This package contains
classes and interfaces used to allow assistive
technologies
to
interact
with
Swing
components.
javax.swing: This package contains the core
Swing components, including most of the
model interfaces and support classes.
javax.swing.border:
It
contains
the
definitions for the abstract border class as well
as eight predefined borders that are special
graphical elements.
javax.swing.colorchooser: This package
helps in support for the JColorChooser
component.
javax.swing.event:
This
Class
defines
several new listeners and events that Swing
components
use
to
communicate
asynchronous information between classes.
javax.swing.filechooser:
This
package
contains
support
for
the
JFileChooser
component.
javax.swing.plaf: It defines the unique
elements that make up the pluggable look and
feel (L&F) for each Swing component.
javax.swing.text: This package provides
scores of text-based classes and interfaces
supporting a common design known as
document.
javax.swing.text.html: This package is used
specifically for reading and formatting HTML
text through an ancillary editor kit.

b. JFC: JFC known as Java Foundation Class. Java


provides such ease for the programmer through
the use of Java Foundation Class (JFC). The Java
Foundation Class (JFC) is a suite of libraries
designed to assist programmers in creating
enterprise applications with Java. The JFC are a
graphical framework for building portable Javabased graphical user interfaces (GUIs) programs.
The JFC also have some constituents as described
below:
Abstract Window Toolkit (AWT): AWT
provides a rich set of user interface
components including graphics and imaging
tools, layout managers for flexible window
layouts and data transfer classes for cut-andpaste through the native platform clipboard.
Accessibility API: The assistive systems
include screen readers, screen magnifiers, and
speech recognition systems. The Accessibility
API provides an interface that allows assistive
technologies to interact and communicate with
JFC and AWT components.
2D API: The 2D API contains classes for
implementing various painting styles, complex
shapes, fonts, and colours. The 2D Graphics
API supports advanced 2D graphics and
imaging.
Drag and Drop: The DnD API allows users to
implement droppable elements that transfer
information between Java applications and
native applications.

Das könnte Ihnen auch gefallen