Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
73Activity
0 of .
Results for:
No results containing your search query
P. 1
Java Interview Questions

Java Interview Questions

Ratings:

4.5

(2)
|Views: 2,065 |Likes:
Published by api-3803341
This book is very useful if you are attending an interview on java
This book is very useful if you are attending an interview on java

More info:

Published by: api-3803341 on Oct 17, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

Brought to you by:
World\u2019s Largest Resource for FREE Interview / Viva Questions
http://www.fundoosite.com/interview-questions/
A Vyom Enterprise \u2013www.vyomworld.com
Java Interview Questions
Java Interview Questions \u2013 Subscribe to FREE & Exclusive career resources atwww.jobsassist.com/CareerMag/
\u00a9JobsAssist.com (http://www.jobsassist.com/) andVyomWorld.com (http://www.vyomworld.com/) \u2013 Free Student Resources
Java Interview Questions \u2013 Subscribe to FREE & Exclusive career resources atwww.jobsassist.com/CareerMag/
\u00a9JobsAssist.com (http://www.jobsassist.com/) andVyomWorld.com (http://www.vyomworld.com/) \u2013 Free Student Resources
1. How can you achieve Multiple Inheritance in Java?

Java's interface mechanism can be used to implement multiple inheritance, with one important difference from c++ way of doing MI: the inherited interfaces must be abstract. This obviates the need to choose between different implementations, as with interfaces there are no implementations.

2. Replacing Characters in a String

// Replace all occurrences of 'a' with 'o'
String newString = string.replace('a', 'o');
Replacing Substrings in a String
static String replace(String str,
String pattern, String replace) {
int s = 0;
int e = 0;
StringBuffer result = new StringBuffer();
while ((e = str.indexOf(pattern, s)) >= 0) {
result.append(str.substring(s, e));
result.append(replace);
s = e+pattern.length();
}result.append(str.substring(s));

return result.toString();
}Converting a String to Upper or Lower Case

// Convert to upper case
String upper = string.toUpperCase();
// Convert to lower case
String lower = string.toLowerCase();
Converting a String to a Number
int i = Integer.parseInt("123");
long l = Long.parseLong("123");
float f = Float.parseFloat("123.4");
double d = Double.parseDouble("123.4e10");
Breaking a String into Words
String aString = "word1 word2 word3";
StringTokenizer parser =
new StringTokenizer(aString);
while (parser.hasMoreTokens()) {
processWord(parser.nextToken());

3. Searching a String

String string = "aString";
// First occurrence.
int index = string.indexOf('S'); // 1
// Last occurrence.
index = string.lastIndexOf('i'); // 4
// Not found.
index = string.lastIndexOf('z'); // -1

Java Interview Questions \u2013 Subscribe to FREE & Exclusive career resources atwww.jobsassist.com/CareerMag/
\u00a9JobsAssist.com (http://www.jobsassist.com/) andVyomWorld.com (http://www.vyomworld.com/) \u2013 Free Student Resources
4. Connecting to a Database and Strings Handling
Constructing a String
If you are constructing a string with several appends, it may be more efficient to construct it using a

StringBuffer and then convert it to an immutable String object.
StringBuffer buf = new StringBuffer("Initial Text");
// Modify
int index = 1;
buf.insert(index, "abc");
buf.append("def");
// Convert to string
String s = buf.toString();
Getting a Substring from a String
int start = 1;
int end = 4;
String substr = "aString".substring(start, end); // Str

5. What is a transient variable?
A transient variable is a variable that may not be serialized. If you don't want some field not to be serialized,
you can mark that field transient or static.
6. What is the difference between Serializalble and Externalizable interface?

When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject()two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class's serialization process.

7. How many methods in the Externalizable interface?
There are two methods in the Externalizable interface. You have to implement these two methods in order
to make your class externalizable. These two methods are readExternal() and writeExternal().
8. How many methods in the Serializable interface?
There is no method in the Serializable interface. The Serializable interface acts as a marker, telling the
object serialization tools that your class is serializable.
9. How to make a class or a bean serializable?

By implementing either the java.io.Serializable interface, or the java.io.Externalizable interface. As long as one class in a class's inheritance hierarchy implements Serializable or Externalizable, that class is serializable.

10. What is the serialization?
The serialization is a kind of mechanism that makes a class or a bean persistence by having its properties
or fields and state information saved and restored to and from storage.

Activity (73)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
nasimakhtar liked this
parthimahendra liked this
faisal_csedu liked this
veeteshjain liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->