Java Technologies Essay Sample

10 October 2017

Q. 1: a ) What is Object Oriented Paradigm? Explain advantages of Object Oriented Programming. 5 Markss
Ans Object Oriented paradigm: The Object Oriented paradigm is centered on the construct of the object. Everything is focused on objects. In this linguistic communication. plan consists of two things: foremost. a set of objects and back the manner they interact with each other. Calculation in this paradigm is viewed as the simulation of existent universe entities. The popular scheduling linguistic communications in this paradigm are C++ . Simula. Smalltalk and Java

Object Oriented scheduling: The universe is Object Oriented. and Object Oriented scheduling expresses plans in the ways that model how people perceive the universe. Figure 2 shows different existent universe objects around us which we frequently use for executing different maps. This shows that job work outing utilizing the objects oriented attack is really near to our existent life job work outing techniques. The basic difference in Object Oriented scheduling ( OOP ) is that the plan is organized around the informations being operated upon instead than the operations performed. The basic thought behind OOP is to unite both. informations and its maps that operate on the information into a individual unit called object. Object Oriented methods are favored because many experts agree that Object Oriented techniques are more disciplined than conventional structured techniques. ( Martin and Odell 1992 )

B ) What is polymorphism? Explain the advantages of polymorphismwith an illustration. Solution: Polymorphism is the capableness of a method to make different things based on the object through which it is invoked or object it is moving upon. For illustration method find _area will work decidedly for Circle object and Triangle object In Java. the type of existent object ever determines method calls ; object mention type doesn’t play any function in it. You have already used two types of polymorphism ( overloading and overruling ) in the old unit and in the current unit of this block. Now we will look at the 3rd: dynamic method binding. Java uses Dynamic Method Dispatch mechanism to make up one’s mind at tally clip which overridden map will be invoked. Dynamic Method Dispatch mechanism is of import because it is used to implement runtime polymorphism in Java. Java uses the rule: “a ace category object can mention to a subclass object” to decide calls to overrule methods at tally clip. If a superclass has method that is overridden by its subclasses. so the different versions of the overridden methods are invoked or executed with the aid of a superclass mention variable. Assume that three subclasses ( Cricket_Player Hockey_Player and Football_Player ) that derive from Player abstract category are defined with each subclass holding its ain Play ( ) method. abstract category Player // category is abstract

{
private String name ;
public Player ( String nm )
{
name=nm ;
}
public String getName ( ) // regular method
{
return ( name ) ;
}
public abstract nothingness Play ( ) ;
// abstract method: no execution
}
category Cricket_Player extends Player
{
Cricket_Player ( String volt-ampere )
{
}
public nothingness Play ( )
{
System. out. println ( “Play Cricket: ”+getName ( ) ) ;
}
}
category Hockey_Player extends Player
{
Hockey_Player ( String volt-ampere )
{
}
public nothingness Play ( )
{
System. out. println ( “Play Field hockey: ”+getName ( ) ) ;
}
}
category Football_Player extends Player
{
Football_Player ( String volt-ampere )
{
}
public nothingness Play ( )
{
System. out. println ( “Play Football: ”+getName ( ) ) ;
}
}
public category PolyDemo
{
public inactive nothingness chief ( Stringing [ ] args )
{
Player ref ; // put up volt-ampere for an Playerl
Cricket_Player aCplayer = new Cricket_Player ( “Sachin” ) ; // makes specific objects Hockey_Player aHplayer = new Hockey_Player ( “Dhanaraj” ) ;
Football_Player aFplayer = new Football_Player ( “Bhutia” ) ;
// now cite each as an Animal
ref = aCplayer ;
ref. Play ( ) ;
ref = aHplayer ;
ref. Play ( ) ;
ref = aFplayer ;
ref. Play ( ) ;
}
}
End product: Play Cricket: Sachin
Play Hockey: Dhanaraj
Play Football: Bhutia
Question 2: a ) What is platform independency? Explain why Java is unafraid and
platform independent. ( 3 Marks )
B ) Write a plan in Java to bring forth Fibonnaci Series. ( 3 Marks ) c ) Explain the advantage of of Unicode. ( 2 Marks )
vitamin D ) Explain the significance of PATH and CLASS PATH. ( 2 Marks ) Solution ( a ) : PlatformIndependent
































































Java is Platform independent. The significance of platform here may be confounding for you but really this word is ill defined. In the computing machine industry it typically means some combination of hardware and system package but here you can understand it as your operating system. Java is compiled to an intermediate signifier called Java byte-code or merely byte codification. A Java plan ne’er truly executes instantly after digest on the host machine. Rather. this particular plan called the Java translator or Java VirtualMachine reads the byte codification. translates it into the corresponding host machine instructions and so executes the machine direction.

A Java programcan tally on any computing machine systemfor which a JVM ( Java Virtual Machine ) and some library modus operandis have been installed. The 2nd of import portion which makes Java portable is the riddance of hardware architecture dependent concepts. For illustration. Integers are ever four bytes long and floating-point variables followthe IEEE 754. You don’t necessitate to worry that the reading of your whole number is traveling to alter if you move from one hardware to another hardware like Pentiumto a PowerPC. We can develop the Java plan on any computing machine system and the executing of that plan is possible on any other computing machine system loaded with JVM. For illustration. we can compose and roll up the Java plan on Windows 98 and put to death the compiled plan on JVM of the Macintosh operating system.

Solution ( B ) : Solution
Input – 8
Output – 1 1 2 3 5 8 13 21 */
category Fibonacci {
public inactive nothingness chief ( Stringing a rgs [ ] ) {
int num = Integer. parseInt ( args [ 0 ] ) ; //taking no. as bid line statement.
System. out. println ( “*****Fibonacci Series*****” ) ;
int f1. f2=0. f3=1 ;
for ( int i=1 ; i & lt ; =num ; i++ ) {
System. out. print ( ” “+f3+” “ ) ;
f1 = f2 ;
f2 = f3 ;
f3 = f1 + f2 ;
}
}
Solution ( degree Celsius ) : Unicode is a 16-bit codification holding a big scope in comparing to old ASCII codification. which is merely 7 spots or 8 spots in size. Unicode can stand for all the characters of all human linguistic communications. Since Java is developed for planing Internet applications. and world-wide people can compose plans in Java. transmutation of one linguistic communication to another is simple and efficient. Use of Unicode besides supports platformindependence in Java.














Solution ( vitamin D ) : Way variable
In JDK the PATH variable contains directories where binary files ( e. g. EXE files in Windows ) will be looked for. We set the PATH variables like this i. e path C: Javajdk1. 6. 0_03in ( I ) on bid prompt

Degree centigrades: & gt ; set path= % way ; C: Javajdk1. 6. 0_03in %
When you open a bid prompt and type “javac” . you’re supposed to hold the “bin” directory of your sdk into the PATH. otherwise you’ll acquire an ill-famed “Command non found” mistake message CLASSPATH

In JDK the CLASSPATH contains directories ( or JAR files ) . from where your Java compiler/runtime will look for. category files ( and some others ) . For illustration. “java Hello. class” will non work unless you set the directory ( or JAR file ) Hello. category is in. into your CLASSPATH. i. e. classpath C: Javajdk1. 6. 0_03lib

For puting CLASSPATH utilizing bid prompt
Java category way can be set utilizing either the -classpath option when naming an SDK tool ( the preferred method ) or by puting the CLASSPATH environment variable. The -classpath option is preferred because you can put it separately for each application without impacting other applications and without other applications modifying its value. ( two ) on bid prompt

Degree centigrades: & gt ; set classpath= % classpath ; C: Javajdk1. 6. 0_03lib %
Question 3: a ) What is an exclusion? Create an exclusion subclass named MyException to manage user generate exclusions in Java. ( 5 Marks ) B ) What is abstract category? What are advantages of utilizing

abstract category? Write a plan in Java to explicate abstract category and multilevel heritage. ( 5 Marks )
Solution ( a ) : Java utilizations exclusions as a manner of signaling serious jobs when you execute a plan. The criterion categories use them extensively. Since they arise in your Java plans when things go incorrect. and if something can travel incorrect in your codification. Oklahoman or later it will. they are a really basic consideration when you are planing and composing your plans.

An exclusion normally signals an mistake and is so called because mistakes in your Java plans are bound to be the exclusion instead than the rule—by definition! An exclusion doesn’t ever indicate an mistake though—it can besides signal some peculiarly unusual event in your plan that deserves particular attending.

An exclusion in Java is an object that’s created when an unnatural state of affairs arises in your plan. This exclusion object has Fieldss that shop information about the nature of the job. The exclusion is said to be thrown—that is. the object placing the exceeding circumstance is tossed as an statement to a specific piece of plan codification that has been written specifically to cover with that sort of job. The codification having the exclusion object as a parametric quantity is said to catch it. An illustration of how to specify an exclusion category:

public category DreadfulProblemException extends Exception
{
// Builders
public DreadfulProblemException ( ) { } // Default builder
public DreadfulProblemException ( String s )
{
super ( s ) ; // Name the base category builder
}
}
Solution ( B ) : An abstract category is a category in which one or more methods are declared. but non defined. The organic structures of these methods are omitted. because. as in the instance of the method sound ( ) in the Animal category. implementing the methods does non do sense. Since they have no definition and can non be executed. they are called abstract methods. The declaration for an abstract method ends with a semicolon and you specify the method with the keyword abstract to place it as such. To declare that a category is abstract you merely utilize the keyword abstract in forepart of the category keyword in the first line of the category definition.








A plan in Java to explicate abstract category and multilevel heritage abstract category Player // category is abstract
{
private String name ;
public Player ( String nm )
{
name=nm ;
}
public String getName ( ) // regular method
{
return ( name ) ;
}
public abstract nothingness Play ( ) ;
// abstract method: no execution
}
category Cricket_Player extends Player
{
Cricket_Player ( String volt-ampere )
{ }
public nothingness Play ( )
{
System. out. println ( “Play Cricket: ”+getName ( ) ) ;
}
}
category Hockey_Player extends Player
{
Hockey_Player ( String volt-ampere )
{
}
public nothingness Play ( )
{
System. out. println ( “Play Field hockey: ”+getName ( ) ) ;
}
}
category Football_Player extends Player
{
Football_Player ( String volt-ampere )
{
}
public nothingness Play ( )
{
System. out. println ( “Play Football: ”+getName ( ) ) ;
}
}
public category PolyDemo
{
public inactive nothingness chief ( Stringing [ ] args )
{
Player ref ; // put up volt-ampere for an Playerl
Cricket_Player aCplayer = new Cricket_Player ( “Sachin” ) ; // makes specific objects Hockey_Player aHplayer = new Hockey_Player ( “Dhanaraj” ) ;
Football_Player aFplayer = new Football_Player ( “Bhutia” ) ;
// now cite each as an Animal
ref = aCplayer ;
ref. Play ( ) ;
ref = aHplayer ;
ref. Play ( ) ;
ref = aFplayer ;
ref. Play ( ) ;
}
}
End product:
Play Cricket: Sachin
Play Hockey: Dhanaraj
Play Football: Bhutia
Question 4: Distinguish the followers and support with illustration: ( 10 Marks ) Final and inactive member
Inheritance and Collection
Abstract category and Interface
Stringing and String Buffer
Solution: ( I ) Final and staticmember
Solution
1. Inactive variables ( besides called category variables ) merely exist in the category they are defined in. They are non instantiated when an case of the category is created. In other words. the values of these variables are non a portion of the province of any object. When the category is loaded. inactive variables are initialized to their default values if no expressed low-level formatting look is specified Final variable: values of concluding variables can non be changed.




































































2. Inactive methods are besides known as category methods. A inactive method in a category can straight entree other inactive members in the category. It can non entree case ( i. e. . non-static ) members of the category. as there is no impression of an object associated with a inactive method. However. note that a inactive method in a category can ever utilize a mention of the class’s type to entree its members. regardless of whether these members are inactive or non.

3. Concluding methods: can non be overriden.
FinalMember
inactive concluding variables are non the same with concluding ( non-static ) variables! Final ( non-static ) variables can differ from object to object! ! ! But that’s merely if the low-level formatting is made within the builder! ( If it is non initialized from the builder so it is merely a waste of memory as it creates concluding variables for every object that is created that can non be altered. ) ( two ) Inheritance and Collection

There are two schools of idea on how to outdo extend. enhance. and recycle codification in an objectoriented system:
1. Inheritance: widen the functionality of a category by making a subclass. Override superclass members in the subclasses to supply new functionality. Make methods abstract/virtual to coerce subclasses to “fill-in-the-blanks” when the superclass wants a peculiar interface but is agnostic about its execution.

2. Collection: make new functionality by taking other categories and uniting them into a new category. Attach an common interface to this new category for interoperability with other codification.
It’s non a affair of which is the best. but of when to utilize what. ( three ) Abstract category and Interface
An interface is an empty shell. there are merely the signatures ( name / params / return type ) of the methods. The methods do non incorporate anything. The interface can’t do anything. It’s merely a form Implementing an interface consume really small CPU. because it’s non a category. merely a clump of names. and therefor there is no expensive search to make. It’s great when it matters such as in embedded devices.

Abstract categories
Abstract categories. unlike interfaces. are categories. There are more expensive to utilize because there is a search to make when you inherit fromthem.
Abstract categories look a batch like interfaces. but they have something more: you can specify a behaviour for them. It’s more about a cat stating “these categories should look like that. and they got that in common. so fill in the spaces! ” .

( four ) String and String Buffer
A String is changeless. i. e. when it’s created. it can ne’er alter. A StringBuffer ( or its non-synchronized cousin StringBuilder ) is used when you need to build a twine piece by piece without the public presentation operating expense of building tonss of small Strings along the manner.

Question 5: a ) What are the categories in Java available for file handling? Write a plan in Java to add on content at the terminal of an
already bing file. ( 5 Marks )
B ) Explain the difference between checked and unbridled
exclusions with illustration.
Solution a ) Solution:
Java input and end product is based on the usage of watercourses. or sequences of bytes that travel from a beginning to a finish over a communicating way. If a plan is composing to a watercourse. you can see it as stream’ s beginning. If it is reading froma watercourse. it is the stream’ s finish. The communicating way is dependent on the type of I/O being performed. It can dwell of memory-to-memory transportations. a file system. a web. and other signifiers of I/O. File managing in Java is available through watercourses and watercourse categories




The Java theoretical account for I/O is wholly based on watercourses. There are two types of watercourses: byte watercourses and character watercourses.
• Byt vitamin E str eams carry whole numbers with values that range from 0 to 255. A diversified information can be expressed in byte format. including numerical informations. feasible plans. and byte codifications – the category file that runs a Java plan. • Char acter Str eams are specialised type of byte watercourses that can manage merely textual informations. Most of the functionality available for byte watercourse is besides provided for character watercourses. The methods for character watercourses by and large accept parametric quantities of informations type char. while byte watercourses work with byte informations types. The names of the methods in both sets of categories are about indistinguishable except for the postfix. that is. character-stream categories end with the suffix Reader or Writer and byte-stream categories end with the postfix InputStream and OutputStream. For illustration. to read files utilizing character watercourses use the Java. Io. FileReader category. and for reading it utilizing byte watercourses use Java. Io. FileInputStream

A Programto Copy an already bing File to new File
import Java. Io. * ;
public category jCOPY {
public inactive nothingness chief ( Stringing args [ ] ) {
seek {
jCOPY J = new jCOPY ( ) ;
j. CopyFile ( new File ( args [ 0 ] ) . new File ( args [ 1 ] ) ) ;
}
gimmick ( Exception e ) {
e. printStackTrace ( ) ;
}
}
public nothingness CopyFile ( File in. File out ) throws
Exception { FileInputStream fis = new
FileInputStream ( in ) ; FileOutputStream fos = new
FileOutputStream ( out ) ;
byte [ ] buf = new byte [ 1024 ] ;
int I = 0 ;
while ( ( i=fis. read ( buf ) ) ! =-
1 ) { field-grade officer. write ( buf. 0. I ) ;
}
fis. near ( ) ;
field-grade officer. near ( ) ;
}
}
two ) Solution:
As stated by their name. unbridled exclusions are non checked at compile-time which means that the compiler doesn’t require methods to catch or to stipulate ( with a throws ) them. Classs belonging to this class are detailed in the subdivision 11. 2 Compile-Time Checking of Exceptions of the JLS:

























The unbridled exclusions categories are the category RuntimeException and its subclasses. and the category Error and its subclasses. All other exclusion categories are checked exclusion categories. The Java API defines a figure of exclusion categories. both checkered and unbridled. Extra exclusion categories. both checkered and unbridled. may be declared by coders. See §11. 5 for a description of the exclusion category hierarchy and some of the exceptionclasses defined by the Java API and Java practical machine

Question 6: a ) What is multithreading? Explain the two ways of making togss in Java plans. Besides explain difference between
notify ( ) and notify All ( ) methods. ( 5 Marks )
B ) What is demand of Layout Manager? Explain different layouts available in Java. ( 5 Marks )
Solution a ) :
Multithreaded plans support more than one coincident yarn of executing. This means they are able to at the same time put to death multiple sequences of instructions. Each direction sequence has its ain alone flow of control that is independent of all others. These independently executed direction sequences are known as togss.



Your Personal computer has merely a individual CPU ; you mi ght inquire how it can put to death more than one yarn at the same clip? In individual processor systems. merely a individual yarn of executing occurs at a given blink of an eye. But multiple togss in a programincrease the use of CPU.

The CPU rapidly switches back and Forth between several togss to make an semblance that the togss are put to deathing at the same clip. You know that single-processor systems support logical concurrence merely. Physical concurrence is non supported by it. Logical concurrence is the characteristic exhibited when multiple togss execute with separate. independent flow of control. On the other manus on a multiprocessor system. several togss can put to death at the same clip. and physical concurrence is achieved.

Making Threads in Java
The multithreading system in Java is built upon the Thr ead Class. its methods and its comrade interface. Runnable. To make a new yarn. your plan will either widen Thread Class or implement the Runnable interface. The Thread Class defines several methods that help in pull offing togss. For illustration. if you have to make your ain yarn so you have to make one of the following 1 )

classMyThread extends Thread
{
MyThread ( statements ) // builder
{
} //initialization
public nothingness tally ( )
{
// performoperations
}
}
Write the undermentioned codification to make a yarn and get down it running: MyThread P = newMyThread ( statements ) ;
p. start ( ) ;
2 )
classMyThread implements Runnable
{
MyThread ( statements )
{
//initialization
}
public nothingness tally ( )
{
// performoperation
}
}






















notify ( ) : this method should be called merely when the current yarn has already acquired the lock on the object. If the delay set of the object is non-empty so a yarn from the set is randomly chosen. removed and is re-enabled for thread programming. Of class. the yarn will non be able to continue unless the current yarn releases the object’s lock.

notifyAll ( ) : it’s same as the notify ( ) method. The lone difference is that in this instance all the togss from the non-empty delay set of the object are
removed and are re-enabled for thread programming in position of merely one yarn from the delay set being picked randomly. removed. and re-enabled for thread programming as is the instance in notify ( ) method.

B ) A LayoutManager rearranges the constituents in the container based on their size relation to the size of the container.
See the window that merely popped up. It has got five buttons of changing sizes. Resize the window and watch how the buttons move. In peculiar attempt doing it merely broad plenty so that all the buttons fit on one line. Then seek doing it narrow and tall so that there is merely one button on line. See if you can pull off to cover up some of the buttons. Then uncover them. Note that whatever you try to make. the order of the buttons is maintained in a logical manner. When you add a constituent to an applet or a container. the container uses its layout director to make up one’s mind where to set the constituent. Different LayoutManager classes use different regulations to put constituents. Java. awt. LayoutManager is an interface. Five categories in the Java packages implement it:

• FlowLayout • BorderLayout • CardLayout •
GridLayout
• GridBagLayout
•plus javax. swing. BoxL ayout
Question 7: a ) What is an Applet? Write an applet that prints “Lear Java it is useful” at the current pointer place whenever the mouse left button is clicked. ( 5 Marks )
B ) See a category that shops a Bank history holder’s name. history figure. ATM card figure. history balance and
ATM PIN. Write a plan to hive away the informations onto a disc file. except for the history balance and ATM PIN. Use serialisation and transient variables. ( 5 Marks ) Solution a ) :
Applet is a Java plan that runs in the Appletviewer ( a trial public-service corporation for Applets that is included with the J2SDK ) or a World Wide Web browser such as Microsoft Internet Explorer or Netscape Communicator.






The Applet category is packed in the Java. Applet bundle which has several interfaces. These interfaces enable the creative activity of Applets. interaction of Applets with the browser. and playing audio cartridge holders in Applets. In Java 2. category Javax. swing. JApplet is used to specify an Applet that uses the Swing GUI constituents.

// An Applet plan holding two text boxes and one button. Read your name in one text box // and when button is pressed so your name is transferred into text box two import Java. awt. * ;
import Java. applet. * ;
import Java. awt. event. * ;
public category Q6a extends Applet implements ActionListener {
TextField text1. end product ;
Label label1. label2 ;
Button button ;
public nothingness init ( ) {
setLayout ( void ) ;
label1 = new Label ( “Enter Name: “ ) ;
label1. setBounds ( 20. 20. 100. 20 ) ;
attention deficit disorder ( label1 ) ;
text1 = newTextField ( 5 ) ;
text1. setBounds ( 150. 20. 100. 20 ) ;
attention deficit disorder ( text1 ) ;
label2
label2 = new Label ( “You Entered: “ ) ;
label2. setBounds ( 20. 80. 130. 20 ) ;
attention deficit disorder ( label2 ) ;
end product = new TextField ( 5 ) ;
end product. setBounds ( 150. 80. 100. 20 ) ;
attention deficit disorder ( end product ) ;
button = new Button ( “Submit” ) ;
button. setBounds ( 150. 110. 100. 20 ) ;
attention deficit disorder ( button ) ;
button. addActionListener ( this ) ;
}
public nothingness actionPerformed ( ActionEvent ae ) {
Stringing src=text1. getText ( ) ;
end product. setText ( src ) ;
}
& lt ; HTML & gt ;
& lt ; BODY & gt ;
& lt ; APPLET ALIGN=”CENTER” CODE=”Q6a. class” width = “700” height = “400” & gt ; & lt ; /APPLET & gt ; & lt ; /BODY & gt ;
& lt ; /HTML & gt ;
Question 8: a ) Write a Java plan to put up JDBC and put to death the undermentioned SQL statement on a database table employee-t with the Fieldss emp-id. emp name. emp-department. empbasic
“SELECT * FROM employee-t where emp-basic & lt ; 10000. ( 7 Marks ) B ) What is Java Bean? What are its advantages? ( 3 Marks )
Solution:
Java Database Connectivity ( JDBC ) is a category library which provides a standard manner for set uping and keeping a Java program’ s connexion to a database.
Java provides JDBC to link to databases and work with it. Using standard library modus operandis. you can open a connexion to the database. Basically JDBC allows the integrating of SQL calls into a general scheduling environment by supplying library modus operandis. which interface with the database. In peculiar. Java’ s JDBC has a rich aggregation of modus operandis which makes such an interface highly simple and intuitive.






































Class. forName ( “sun. jdbc. odbc. JdbcOdbcDriver” )
Connection con = DriverManager. getConnection ( url. username. watchword ) ; Statement stmt = con. createStatement ( ) ;
ResultSet R = stmt. executeQuery ( “SELECT * FROM employee-t where emp-basic & lt ; 10000” ) ; while ( R. following ( ) )
{
ename = R. getString ( “emp_name” ) ;
eaddress = R. getString ( “emp_address” ) ;
esal = R. getFloat ( “emp_salary” ) ;
System. out. println ( ename + ” reference is” + eaddress + ” draws salary ” + esal + “in dollars” ) ; }






B ) A JavaBean on its ain is non awfully interesting. it’s merely a Java category that conforms to some criterions that you listed above. However. conformity with this criterion is one of the pillars on which the Java EE model is built and it comes up in rather a few topographic points. I suspect that when you hear about all of the great things that JavaBeans can make. what’s being referred to in Enterprise JavaBeans ( EJBs ) .

A limited
time offer!
Get authentic custom
ESSAY SAMPLEwritten strictly according
to your requirements