Friday 1 January 2016

ASSIGNMENT OF OBJECT ORIENTED PROGRAMMING


 ASSIGNMENT OF OBJECT ORIENTED PROGRAMMING



Question No.1- Describe about JDK. List and explain any five tools available in JDK.

Java Development Kit (JDK)

The Java Development Kit (JDK) is a software development environment used for developing Java applications and applets. It includes the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator (javadoc) and other tools needed in Java development.
 is an implementation of either one of the Java SE, Java EE or Java ME platforms[1] released by Oracle Corporation in the form of a binary product aimed at Java developers on Solaris, Linux, Mac OS X or Windows. The JDK includes a private JVM and a few other resources to finish the development of a Java Application. Since the introduction of the Java platform, it has been by far the most widely used Software Development Kit (SDK) On 17 November 2006, Sun announced that it would be released under the GNU General Public License (GPL), thus making it free software. This happened in large part on 8 May 2007, when Sun contributed the source code to the Open JDK.
Java developers are initially presented with two JDK tools, java and javac. Both are run from the command prompt. Java source files are simple text files saved with an extension of .java. After writing and saving Java source code, the javac compiler is invoked to create .class files. Once the .class files are created, the 'java' command can be used to run the java program.

Five tools available in JDK
1.   Basic Tools
These tools are the foundation of the Java Development Kit. They are the tools you use to create and build applications.
Javac
The compiler for the Java programming language.
Java
The launcher for Java applications. In this release, a single launcher is used both for development and deployment.
The old deployment launcher, jre, is no longer provided.
Javadoc
API documentation generator. Also see Javadoc Enhancements for 1.2
Appletviewer
Run and debug applets without a web browser.
Jar
Manage Java Archive (JAR) files.
Jdb
The Java Debugger.
Javah
C header and stub generator. Used to write native methods.
Javap
Class file disassemble
Extcheck
Utility to detect Jar conflicts.

2.   Remote Method Invocation (RMI) Tools

These tools help to create apps that interact over the Web or other network.

Rmic
Generate stubs and skeletons for remote objects.
Rmiregistry
Remote object registry service.
Rmid
RMI activation system daemon.
Serialver
Return class serialVersionUID.

3.   Internationalization Tools
This tool helps to create localizable apps.
native2ascii
Convert text to Unicode Latin-1.
4.   Security Tools
These tools help you set security policies on your system and create apps that can work within the scope of security policies set at remote sites.
Keytool
Manage keystores and certificates.
Jarsigner
Generate and verify JAR signatures.
Policytool
GUI tool for managing policy files.

5.   Java IDL Tools
These tools are used when creating apps that use CORBA to access databases
tnameserv   Provides access to the naming service.

idltojava.   Generates .java files that map an OMG IDL interface and enable an application written in the Java programming language to use CORBA functionality. This tool is available for download from the Java IDL web site. Documentation for the idltojava compiler is included in the download.

Question No.2-  Differentiate  Break and Continue statements in Java with example Program.

 Break Statement-
By using break you can force immediate termintaion of a loop typassing the conditional expression and any remaining code in the body of the loop. When a break statement is encountered inside a loop, the loop is terminated and program control resumes at the next statement following the loop.
 Here is a simple example:
// Using break to exit a loop
Class BreakLoop{
Public static void main(String args[]) {
For(int i=0;i<=100; i++)
{
If(i==10) break;
System.out.println(“i:”+i);
}
System.out.println(“Loop complete”);
}
}
Output is
I:0
I:1
I:2
I:3
I:4
I:5
I:6
I:7
I:8
I:9
Continue Statement:-
Sometimes it is useful to force an early iteration of a loop. That is you might want to continue running the loop, but stop rpocessing the remainder of the code in its body for this particulor iteration. The continue statement performs such an action. Int while and do-while loops, a continue statement causes control to be transferred directly to the conditional expression that controls the loop.in a for loop, control goes first to the iteration portion of the for statement an then to the conditional expression. For all three loops any intermediate code is bypassed.
Here is an example program that uses continue two rumbers to be printed on each line:
// Demostrate continue
Class Continue{
public static void main(String args[]) {
for(int i=0;i<10;i++)
{
System.out.println(i=””);
If(i%2==0) continue;
System.out.println(“”);
}
}
}
Output is
0 1
2 3
4 5
6 7
8 9

Question No 3. Differentiate packages and Interfaces.
There is a huge difference between packages and interfaces.  A package is a scoping mechanism for classes within a group.  So that the names used for classes in one package do not conflict with the names (even if they are the same) of classes and public methods in another package.
Packages
Definition:  A package is a grouping of related types providing access protection and name space management. Note that types refers to classes, interfaces, enumerations, and annotation types. Enumerations and annotation types are special kinds of classes and interfaces, respectively, so types are often referred to in this lesson simply as classes and interfaces.
A package is just a mechanism for grouping objects, it is very similar to grouping items within a folder or directory on a file system. A class is found within a package, but this does not have an impact on the class' behavior (review the "package" access level for a slight exception). 

Creating a Package:
To create a package, you choose a name for the package and put a package statement with that name at the top of every source file that contains the types (classes, interfaces, enumerations, and annotation types) that you want to include in the package.
You can include non-public types in the same file as a public type (this is strongly discouraged, unless the non-public types are small and closely related to the public type), but only the public type will be accessible from outside of the package. All the top-level, non-public types will be package private.
Interface

An interface, however, is a .java file that is used (implemented) by another class to tell the outside world that it conforms to a certain specification. For example, you might have a "Runnable" interface that has a "run()" method in it, by having a class that is "Runnable" (implements Runnable) anyone using that class knows that it must have a "run()" method defined. This is used when you have several different classes that have the same interface. 
Interfaces have more in common with abstract classes than they do with packages. An interface, by definition, cannot have any implemented methods; an abstract class, in contrast, can define some methods and leave some methods to be implemented by a subclass. Also, a class can implement many interfaces, but can only extend one (abstract) class.
Interfaces have nothing to do with scoping... they have to do with having behaviors cross a set of classes outside of an inheritance chain.  Of course, behaviors are shared via inheritance from parent class to child class - but what do you do if you want to share behaviors across a group of classes that are not related via inheritance?  The answer is interfaces.  A good common example of this is logging or capturing metrics or creating plugins - whenever behavior (and not attributes) are common across a set of classes.  Hope that helps.

Question No 4. What are Applets? What are the restrictions of Applets? Describe
about applet class.
Applets
An applet is a little application. Prior to the World Wide Web, the built-in writing and drawing programs that came with Windows were sometimes called "applets." On the Web, using Java, the object-oriented programming language, an applet is a small program that can be sent along with a Web page to a user. Java applets can perform interactive animations, immediate calculations, or other simple tasks without having to send a user request back to the server
An applet is a small Internet-based program written in Java, a programming language for the Web, which can be downloaded by any computer. The applet is also able to run in HTML. The applet is usually embedded in an HTML page on a Web site and can be executed from within a browser
Applets Restrictions
Applets have many resitrictions over the areas of secrurity because they are obtained from remote machines

1. If we are running an applet from a provider who is not trustworthy than security is important.
2. Applet itself cannot run or modify any application on the local system.
3. Applet has no access to client-side resources such as files, OS etc.
4. Applets can have special privileges. They have to be tagged as trusted applets and they must be registered to APS applet security manager.
5. Applet has little restriction when it comes to communication. It can communicate only with the machine from which it was loaded.
6. Applet cannot work with native methods
7. Applet can only extract information about client machine is its name, version OS, version etc.

Class Applet

An applet is a small program that is intended not to be run on its own, but rather to be embedded inside another application.
The Applet class must be the superclass of any applet that is to be embedded in a Web page or viewed by the Java Applet Viewer. The Applet class provides a standard interface between applets and their environment.
The Applet class doesn't provide any genuine applicability on its own. Its purpose is to provide a super class from which custom applet classes are extended.
Question No 5. Compare JDBC and ODBC.
Compare JDBC and ODBC
ODBC is an open interface which can be used by any application to communicate with any database system, while JDBC is an interface that can be used by Java applications to access databases. Therefore, unlike JDBC, ODBC is language independent. But by using JDBC-to-ODBC bridge Java applications can also talk to any ODBC compliant database
Typically, software applications are written in a specific programming language (such as Java, C#, etc.), while databases accept queries in some other database specific language (such as SQL). Therefore, when a software application needs to access data in a database, an interface that can translate languages to each other (application and database) is required. Otherwise, application programmers need to learn and incorporate database specific languages within their applications. ODBC (Open Database Connectivity) and JDBC (Java DatabBase Connectivity) are two interfaces that solve this specific problem.
ODBC
ODBC is an interface to access database management systems (DBMS). ODBC was developed by SQL Access Group in 1992 at a time there were no standard medium to communicate between a database and an application. It does not depend on a specific programming language or a database system or an operating system. Programmers can use ODBC interface to write applications that can query data from any database, regardless of the environment it is running on or the type of DBMS it uses
ODBC is a multidatabase API for programs that use SQL statements to access data. An ODBC-based program can access heterogeneous databases without needing source code changes-one program can retrieve and store content in different vendors' databases via the ODBC interface. ODBC thus provides database-neutral delivery of both SQL and database content. Be aware, however, that you must load ODBC driver software for each vendor's database you want to access.
JDBC
JDBC is a Data API developed for Java programming language. It was released with JDK 1.1 by Sun Microsystems (Java’s initial owners). And its current version is JDBC 4.0 (currently distributed with JAVA SE6). Java.sql and javax.sql packages contain the JDBC classes. It is an interface that helps a client to access a database system, by providing methods to query and update data in the databases. JDBC is more suitable for object oriented databases. You can access any ODBC-compliant database by using the JDBC-to-ODBC bridge.
JDBC is a collection of database access middleware drivers that provide Java programs with a call-level SQL API. Java applets and applications can use the drivers' API to connect to databases, store and retrieve database content and execute stored procedures, thus making JDBC a Java-enabled delivery mechanism for SQL. JDBC is to Java programs what ODBC is to programs written in languages other than Java. In fact, JDBC's design is based on ODBC's

Question No 6. Describe about Java Beans and BeanBox.
BeanBox
BeanBox is a test container in BDK. We can use Bean Box to create Application, Applet, and New Beans. We can lay out, edit and interconnect beans visually. That is one of the benefits of Java beans is the capability for the beans to be used in visual application builder tools.
Before installing BDK, we have to install JDK version 1.1 or later first and then install BDK. There is a "beanbox" directory insidne of BDK (assume "BDK" is a directory for JavaBeans"). BeanBox comes with the batch file, called run.bat in the "beanbox" directory. If we type in "run", it would displays 3 windows:
The first window is Toolbox, it lists all the beans registered for use with BeaBox. We also can write our own beans and add them to this window.
The second window is BeanBox, it is the main container window.
Last window is Propertysheet, it lists the properties associated with the current selected bean. It is responsible for providing the visual editing capabilities of the BeanBox.
The following is the picture of the windows from Starting and Using the BeanBox
What can BeanBox do?
The BeanBox allows you to:
Drop beans onto a composition window
Resize and move beans around
Edit the exported properties of a bean
Run a customizer to configure a bean
Connect a bean event source to an event handler method
Connect together bound properties on different beans
Save and restore sets of beans
Making applets from beans
Get an introspection report on a bean
Add new beans from JAR files
For more information The BeanBox
Using the BeanBox
Let's create a simple application using BeanBox. We are going to select "OurButton" from the ToolBox window and place it somewhere in the BeanBox window. We are going to edit this bean in the Propertysheet window, change the label to "Start". We are going to select another button, and call it "Stop". Now let's get something exciting, select the "Juggler" bean. A useful function of BeanBox is that we can wire beans together using events, we can do that visully, this makes it very easy. Click the "Start" button, go to Edit and Event, select Action Event Menu item, and then select Action performed. Now we can see a line originating from the "Start" button that moves as the mouse moved around. We are going to move the mouse over the "Juggle" bean. Click to connect the button bean's action event to the "Juggle" bean. Select "start Juggle" method from Dialog box. We are going to do the same thing for "Stop" button. Now, we can click "stop" and "start" to control the animation.

No comments:

Post a Comment