CUSTOMER_CODE SMUDE DIVISION_CODE SMUDE

advertisement
CUSTOMER_CODE
SMUDE
DIVISION_CODE
SMUDE
EVENT_CODE
OCTOBER15
ASSESSMENT_CODE MCA4030_OCTOBER15
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
12945
QUESTION_TEXT
Explain the following methods associated with the String object in
Java. Give the syntax.
i.toCharArray
ii.regionMatches
iii.compareTo
iv.lastIndexOf
v.trim
SCHEME OF
EVALUATION
i.toCharArray
Syntax:
char [ ] toCharArray( ) – returns the String object into array of
characters.
ii.regionMatches
Syntax:
boolean regionMatches(int startIndex, String str2, int str2StartIndex,
int numChars);
or
boolean regionMatches(boolean ignoreCase, int startIndex, String str2,
int
str2StartIndex, int numChars);
Compares a specific region inside a string with another specific region
in another string. There is an overloaded form that allows you to ignore
case in such comparisons.
iii.compareTo
Syntax:
int compareTo(String str);
Here, str is the String being compared with the invoking String. The
result of the comparison is returned and is interpreted as shown:
Value
1.Less than zero
2.Greater than zero
3.Zero
Meaning
1.Invoking string is less than str
2.Invoking string is greater than str
3.Two strings are equal
iv.lastIndexOf()
Syntax:
int lastIndexOf(char ch);
or
int lastIndexOf(String str);
Searches for the last occurrence of a character or substring.
v.Trim
Syntax:
String trim();
Returns a copy of the invoking string from which any leading and
trailing whitespace has been removed.
(Marks: 2 x 5 =10)
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
12948
QUESTION_TEXT
Explain Remote Method Invocation in detail.
SCHEME OF
EVALUATION
Explanation should include the following:
•RMI allows objects in different Java Virtual Machines belonging to
different hosts to send and receive message.
• Local objects are objects that execute on the local machine
• Remote objects are objects that execute on all the other machines.
•Objects on remote hosts are exported so that they can be invoked
remotely.
•An object exports itself by registering itself with a Remote Registry
Server. It is a service that runs on a server and helps the objects on other
hosts to remotely access its registered objects.
•Objects that are exported for remote access must implement the
interface RemoteInterface
•Java’s RMI approach makes use of stubs and skeletons. A stub is a
local object on the client’s machine that acts as a proxy for a remote
object. The skeleton is the proxy of the client machine’s object that is
located on the remote host.
•The stub the skeleton communicates through a remote reference layer.
RMI uses the TCP protocol for transporting information.
(Marks: 10)
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
12949
QUESTION_TEXT
Explain For and While loop with an example
SCHEME OF
EVALUATION
For Loop:
The usage of for loop is as follows:
for(initial statement; termination condition; increment instruction)
statement;
When multiple statements are to be included in the for loop, the
statements are included inside flower braces as below:
for(initial statement; termination condition; increment instruction)
{
Statement 1;
Statement 2;
}
The example below prints numbers from 1 to 10
//print numbers from 1 to 10
class test
{
public static void main(String args[ ])
{
int i;
for(i=1; i<=10;i++)
{
System.out.println(i);
}}}
Like all other programming languages, java allows loops to be nested.
That is, one loop may be inside another.
(5 Marks)
While Loop:
The while loop is java’s most fundamental looping statement. It repeats a
statement or block while its controlling expression is true. Here is its
general form:
While(condition)
{
//body of loop
}
The condition can be any Boolean expression. The body of the loop will
be executed as long as the conditional expression is true. When condition
becomes false, control passes to the next line of code immediately
following the loop. The flower brackets are unnecessary if only a single
statement is being repeated.
Eg:
//Program calculate factorial of a number
public class test
{
public static void main(String args[ ])
{
int n=5;
int fact=1;
int i=1;
while(i<=n)
{
fact*=I;
i++;
}
System.out.println(“Factorial of”+n+”is”+fact);
}} (5 Marks)
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
120577
Explain in detail the access specifiers supported by Java.
QUESTION_TEXT
Explanation
i.
Public with example (3 marks)
ii.
Private with example (3 marks)
iii.
Protected with example (4 marks)
SCHEME OF EVALUATION
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
120582
QUESTION_TEXT
What is Java IDL? Explain.
1.
Java IDL is a technology for distributed objects – i.e. objects
interacting on different platform across a network. IDL stands for
Interface Definition Language.
2.
Java IDL is similar to RMI, which supports distributed objects
written entirely in the Java programming language.
SCHEME OF
EVALUATION
However, Java IDL enable objects interact regardless of whether they’re
written in the Java programming language or another language such as
C, C++, COBOL or others.
3.
Java IDL is based on the Common Object Request Brokerage
Architecture, an industry standard distributed object model.
4.
A key feature of CORBA is IDL, a language –neutral Interface
Definition Language. Each language that supports CORBA has its own
IDL mapping and as its name implies, Java IDL supports the mapping
for Java. CORBA and the IDL mappings are the work of an industry
consortium known as the OMG or Object Management Group.
5.
TO support interaction between objects in separate programs Java
IDL provides an Object Request Broker, or ORB. The Orb is a class
library that enables low level communication between Java IDL
applications and other CORBA compliant applications.
(10 marks)
QUESTION_TYPE
DESCRIPTIVE_QUESTION
QUESTION_ID
120583
Write a note on following, give example for each
QUESTION_TEXT
a.
Break statement
b.
Continue statement
a.
Break statement:
By using break, you can force immediate termination of loop, bypassing 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. (3 marks)
Ex:
//Using break to exit a loop
class BreakLoop{
SCHEME OF
EVALUATION
public static void main(String args[ ]) {
for(int i=0; i<100; i++){
if(I == 10) break; // terminate loop if i is 10
system.out.println(“Loop complete.”);
}
} (2 marks)
b.
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 processing the remainder of the
code in its body for this particular iteration…..(3 marks)
ex:
//Demonstrate continue.
class Continue{
public static void main (String args[ ]) {
for (int i=0; i<10; i++) {
System.out.print (i+ “ “);
if (i%2 == 0) continue;
Sytem.out.println(“”);
}
}
}
(2 marks)
Download