Download CUSTOMER_CODE SMUDE DIVISION_CODE SMUDE

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CUSTOMER_CODE
SMUDE
DIVISION_CODE
SMUDE
EVENT_CODE
Jan2017
ASSESSMENT_CODE MIT108_Jan2017
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
494165_1
Write short notes on:
QUESTION_TEXT
i.
try
ii.
catch
iii.
finally
Exception-handling keywords:
i.
try
ii.
catch
iii. finally
The try Block
You need to guard the statements that may throw an exception in the try
block. The following skeletal code illustrates the use of the try block.
try
SCHEME OF
EVALUATION
{
// statement that may cause an exception
}
The try block governs the statements that are enclosed within it and
defines the scope of the exception handlers associated with it. In other
words, if an exception occurs within try block, the appropriate exceptionhandler that is associated with the try block handles the exception. A try
block must have at least one catch block that follow it immediately.
(1.5 marks)
The catch Block
You associate an exception-handler with the try block by providing one or
more catch handlers immediately after try block. The following skeletal
code illustrates the use of the catch block.
try
{
//statements that may cause an exception
}
catch ()
{
// error handling code
}
The catch statement takes an object of an exception class as a
parameter. If an exception is thrown, the statements in the catch block
are executed. The scope of the catch block is restricted to the statements
in the preceding try block only.
(1.5 marks)
The finally Block
When an exception is raised, the rest of the statements in the try block
are ignored. Sometimes, it is necessary to process certain statements
irrespective of whether an exception is raised or not. The finally block is
used for this purpose.
try
{
openFile();
writeFile(); //may cause an exception
}
catch (…)
{
//process the exception
}
In the above example, the file has to be closed irrespective of whether an
exception is raised or not. You can place the code to close the file in both
the try and catch blocks. To avoid duplication of code, you can place the
code in the finally block. The code in the finally block is executed
regardless of whether an exception is thrown or not. The finally block
follows the catch blocks. You have only one finally block for an exceptionhandler. However, it is not mandatory to have a finally block.
finally
{
closeFile ();
}
(2 marks)
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
494166_2
What is the use of Applet Tag? Give the syntax and example.
QUESTION_TEXT
The Applet
The Applet tag is used to embed an applet in an HTML document. The
Applet tag takes zero or more parameters.
(1 mark)
SCHEME OF
EVALUATION
The Applet Tag
The Applet tag is written in the body tag of an HTML document.
Syntax:
<APPLET
CODE = “name of the class file that extends
java.applet.Applet”
CODEBASE = “path of the class file”
HEIGHT = “maximum height of the applet, in pixels”
WIDTH = “maximum width of the applet, in pixels”
VSPACE = “vertical space between the applet and the rest
of the HTML”
HSPACE = “horizontal space between the applet and the rest of the
HTML”
ALIGN = “alignment of the applet with respect to the rest of the web
page”
ALT = “alternate text to be displayed if the browser does not support
applets”
>
<PARAM NAME=“parameter_name” value=“value_of_parameter”>
……..
</APPLET>
(2 marks)
Example using Applet tag:
<applet
Code = “clock. class”
Height = 200
Width = 200 >
</applet>
(2 marks)
QUESTION_TYPE DESCRIPTIVE_QUESTION
QUESTION_ID
494167_3
Describe about Inner classes and Anonymous Classes.
QUESTION_TEXT
Inner Classes
Inner classes are classes that are declared within other classes. They are
also known as nested classes and provide additional clarity to programs.
The scope of an inner class is limited to the class that encloses it. The
objects of the inner class can access the members of the outer class. The
outer class can access the members of the inner class through an object
of the inner class.
Syntax:
<modifiers> class <classname>
SCHEME OF
EVALUATION
{
<modifiers> class <innerclassname>
{
}
// other attributes and methods
}
(2.5 marks)
Anonymous Classes
Sometimes, the classes that you declare in a method do not need a name
since you do not need them anywhere else in the program. You can
create nameless classes for this purpose. Classes that are not named are
called anonymous classes.
Example:
public void methodOne ()
{
OKButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent action)
{
//process event
}
}
);
In the above code, the class declaration is the argument of the
addActionListener() method. You cannot instantiate an object of the
anonymous class elsewhere in the code.
An anonymous class cannot have a constructor as the class does not have
a name. An anonymous class can be a subclass of another class. It can
implement an interface.
(2.5 marks)
QUESTION_TYPE DESCRIPTIVE_QUESTION
QUESTION_ID
494168_4
Explain about Swing packages and Classes.
QUESTION_TEXT
SCHEME OF
Swing Packages and Classes
EVALUATION
The Swing API is organized into a number of packages to support APIs for
various categories of components, pluggable look-and-feel layouts, events,
component borders, and other assistive technologies. The package
members (classes and interfaces) and their API methods are substantial
and this unit provides the overview of few.
(2 marks)
Here is a short description of each package in the Swing libraries:
1.
javax.accessibility
This package contains classes and interfaces used to allow assistive
technologies to interact with Swing components. Assistive technologies
cover a broad range of items, from audible text readers to screen
magnification. Although the accessibility classes are technically not part of
Swing, they are used extensively throughout the Swing components.
2.
javax.swing
This package contains the core Swing components, including most of the
model interfaces and support classes.
3.
javax.swing.border
This package contains the definitions for the abstract border class as well
as eight predefined borders. Borders are not components but are special
graphical elements that Swing treats as properties and places around
components in place of their insets. If you wish to create your own border,
you can subclass one of the existing borders in this package, or you can
code a new one from scratch.
4.
javax.swing.colorchooser
This package helps in support for the JColorChooser component
5.
javax.swing.event
This Class defines several new listeners and events that Swing components
use to communicate asynchronous information between classes. To create
your own events, you can subclass various events in this package or write
your own event class.
6.
javax.swing.filechooser
This package contains support for the JFileChooser component
7.
javax.swing.plaf
It defines the unique elements that make up the pluggable look and feel
(L&F) for each Swing component. Its various subpackages are devoted to
rendering the individual L&Fs for each component on a platform-byplatform basis.
8.
javax.swing.table
It provides models and views for the table component, which allows you to
arrange various information in a grid format with a appearance similar to a
spreadsheet. Using the lower-level classes, you can manipulate how tables
are viewed and selected, as well as how they display their information in
each cell.
9.
javax.swing.text
This package provides scores of text-based classes and interfaces
supporting a common design known as document/view. The text classes
are among the more advanced Swing classes for the implementation of text
applications.
10.
javax.swing.text.html
This package is used specifically for reading and formatting HTML text
through an ancillary editor kit.
11.
javax.swing.text.html.parser
This package contains support for parsing HTML.
12.
javax.swing.text.rtf
It is used specifically for reading and formatting Rich Text Format (RTF)
text through an ancillary editor kit.
13.
javax.swing.tree
It defines models and views for a hierarchal tree component, which may
represent a file structure or a series of properties.
14.
javax.swing.undo
This package contains the necessary functionality for implementing
undoable functions.
The most widely used package is javax.swing. Almost all the Swing
components, as well as several utility classes, are located inside this
package. The only exceptions are borders and support classes for the trees,
tables, and text-based components. Because the latter components are
much more extensible and often have many more classes to work with,
these classes have been divided into separate packages.
Explain any 6 packages with one statement
(3 marks)
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
494169_5
Write short notes on:
QUESTION_TEXT
i.
RemoteInterface
ii.
RemoteException
iii.
Stub
iv.
Skeleton
v.
Remote reference layer.
RemoteInterface
Objects that are exported for remote access must implement
RemoteInterface
RemoteException
Is used to handle the errors that may occur during the invocation of
remote method.
SCHEME OF
EVALUATION
Stub
Is a local object on client machine
Skeleton
Skeleton is the remote object on server machine
Remote reference layer
Stub and skeleton communicate through remote reference layer.
(Each point carries 1 mark) (5 marks)
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
494170_6
List and explain the ten methods in the RemoteObject class.
QUESTION_TEXT
Methods in the RemoteObject class
Method
Purpose
SCHEME OF
EVALUATION
description()
Returns a description of the object
finalize()
Performs this code when garbage collection
is run
getClass()
Returns the object’s class
getField()
Returns an instance variable
getFields()
Returns the non-static fields of an object
getFieldValue() Returns the value of an object’s instance
variable
getId()
Returns the ID of an object
setField()
Sets an instance variable, specified by slot or
name
toString()
Returns the object as a string
typeName()
Returns the object type
(Each method carries ½ mark) (5 marks)
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
494171_7
QUESTION_TEXT
Explain about features of Object oriented programming and What is
Bytecode?
Features of Java
SCHEME OF
EVALUATION
Java defines data as objects with methods that support the objects. Java is
purely object-oriented and provides abstraction, encapsulation, inheritance
and polymorphism. Even the most basic program has a class. Any code
that you write in Java is inside a class.
Java is tuned for Web. Java programs can access data across the Web as
easily as they access data from a local system. You can build distributed
applications in Java that use resources from any other networked
computer.
Java is both interpreted and compiled. The code is complied to a
bytecode that is binary and platform independent. When the program
has to be executed, the code is fetched into the memory and interpreted
on the user’s machine. As an interpreted language, Java has simple
syntax.
When you compile a piece of code, all errors are listed together. You can
execute only when all the errors are rectified. An interpreter, on the other
hand, verifies the code and executes it line by line. Only when the
execution reaches the statement with error, the error is reported. This
makes it easy for a programmer to debug the code. The drawback is that
this takes more time than compilation.
(5 marks)
Compilation is the process of converting the code that you type, into a
language that the computer understands - machine language. When you
compile a program using a compiler, the compiler checks for syntactic
errors in code and list all the errors on the screen. You have to rectify the
errors and recompile the program to get the machine language code. The
Java compiler compiles the code to a bytecode that is understood by the
Java environment.
Bytecode is the result of compiling a Java program. You can execute this
code on any platform. In other words, due to the bytecode compilation
process and interpretation by a browser, Java programs can be executed
on a variety of hardware and operating systems. The only requirement is
that the system should have a Java-enabled Internet browser. The Java
interpreter can execute Java code directly on any machine on which a
Java interpreter has been installed.
Thanks to bytecode, a Java program can run on any machine that has a
Java interpreter. The bytecode supports connection to multiple databases.
Java code is portable. Therefore, others can use the programs that you
write in Java, even if they have different machines with different
operating systems.
Java forces you to handle unexpected errors. This ensures that Java
programs are robust (reliable), bug free and do not crash.
Due to strong type-checking done by Java on the user’s machine, any
changes to the program are tagged as error and the program will not
execute. Java is, therefore, secure.
Java is faster than other interpreter-based language like BASIC since it is
compiled and interpreted.
Multithreading is the ability of an application to perform multiple tasks at
the same time. You can create multithreading programs using Java. The
core of Java is also multithreaded.
Bytecode
Bytecode is a highly optimized set of instructions designed to be executed
by the Java run-time system, which is called the Java Virtual Machine
(JVM).
(5 marks)
QUESTION_TYPE DESCRIPTIVE_QUESTION
QUESTION_ID
494172_8
List out with examples various string functions available in Java.
QUESTION_TEXT
String functions available in Java
These operations include the automatic creation of new String instances
from string literals, concatenation of multiple
SCHEME OF
EVALUATION
String objects by use of the + operator, and the conversion of other data
types to a string representation.
String Literals
The earlier examples showed how to explicitly create a String instance
from an array of characters by using the new operator. However, there is
an easier way to do this using a string literal. For each string literal in your
program, Java automatically constructs a String object. Thus, you can use
a string literal to initialize a String object. For example, the following
code fragment creates two equivalent strings:
char chars[ ] = { 'a', 'b', 'c' };
String s1 = new String(chars);
String s2 = "abc"; // use string literal
Because a String object is created for every string literal, you can use a
string literal any place you can use a String object. For example, you can
call methods directly on a quoted string as if it were an object reference, as
the following statement shows. It calls the length( ) method on the string
"abc". As expected, it prints "3".
System.out.println("abc".length());
String Concatenation
In general, Java does not allow operators to be applied to String objects.
The one exception to this rule is the + operator, which concatenates two
strings, producing a String object as the result.
(5 marks)
System.out.println(s);
This fragment displays four: 22 rather than the four: 4 that you probably
expected. Here's why. Operator precedence causes the concatenation of
"four" with the string equivalent of 2 to take place first. This result is then
concatenated with the string equivalent of 2 a second time. To complete
the integer addition first, you must use parentheses, like this:
String s = "four: " + (2 + 2);
Now s contains the string "four: 4".
String Conversion and toString( )
When Java converts data into its string representation during
concatenation, it does so by calling one of the overloaded versions of the
string conversion method valueOf( ) defined by String. valueOf( ) is
overloaded for all the simple types and for type Object.
The toString( ) method has this general form:
String toString( )
To implement toString( ), simply return a String object that contains the
human-readable string that appropriately describes an object of your class.
By overriding toString( ) for classes that you create, you allow the
resulting strings to be fully integrated into Java's programming
environment.
Any Example program by using all string functions.
(5 marks)
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
494173_9
QUESTION_TEXT
Write about interface and an abstract class? Explain Inheritance and Types
of Relationships
An interface does not have any overtones of specialization that are present
with inheritance.
An abstract class is an incomplete class that requires further
specialization. An interface is just a specification or prescription for
behavior.
SCHEME OF
EVALUATION
(2 marks)
Inheritance
Inheritance is one of the cornerstones of object-oriented programming,
because it allows the creation of hierarchical classifications. Using
inheritance, you can create a general class that defines traits common to a
set of related items. In the terminology of Java, a class that is inherited is
called a superclass. The class that does the inheriting is called a subclass.
Therefore, a subclass is a specialized version of a superclass. It inherits all
of the instance variables and methods defined by the superclass and add
its own, unique elements.
(2 marks)
Types of Relationships
Relationships are classified as follows:
1.
A Kind-Of relationship.
2.
A Is-A relationship.
3.
A Part-Of-relationship.
4.
A Has-A relationship.
1.
A-Kind-Of Relationship
Taking the example of a human being and an elephant, both are ‘kind-of’
mammals. As human beings and elephants are ‘kind-of’ mammals, they
share the attributes and behaviors of mammals. Human being and
elephants are subset of the mammals class.
2.
Is-A Relationship
Let’s take an instance of the human being class – peter, who ‘is –a’ human
being and, therefore, a mammal.
3.
Has-A Relationship/Part-Of Relationship
A human being has a heart. This represents has-a relationship. Heart is a
part of the human being. This represents part-of relationship.
(6 marks)
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
494174_10
QUESTION_TEXT
What are the different types of control statements? Write a Java
program to compare whether your height is equal to your friend’s
height.
Control Flow Statements
Following statements are used to control the flow of execution in a
program:
1.
2.
SCHEME OF
EVALUATION
3.
Decision Making Statements
a
If-else statement
b
Switch – case statement
Looping Statements
a.
For loop
b.
While loop
c.
Do-while loop
Other statements
a.
Break
b.
Continue
Syntax with examples of each
(With explanation) (6 marks)
Program for using the control flow
(4 marks)