-
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().
-
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.
-
Connecting to a Database and Strings Handling
Constructing a StringIf 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");// Modifyint index = 1;buf.insert(index, "abc");buf.append("def");// Convert to stringString s = buf.toString();Getting a Substring from a Stringint start = 1;int...
-
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
-
Replacing Characters in a String
// Replace all occurrences of 'a' with 'o'String newString = string.replace('a', 'o');Replacing Substrings in a Stringstatic 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...
-
How do I instantiate a bean whose constructor accepts parameters using the useBean tag?
Consider the following bean: package bar;public class FooBean {public FooBean(SomeObj arg) {...}//getters and setters here}The only way you can instantiate this bean within your JSP page is to use a scriptlet. For example, the following snippet creates the bean with session scope:&l;% SomeObj x = new SomeObj(...);bar.FooBean foobar = new FooBean(x);session.putValue("foobar",foobar);%> You can...
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Java Interview Questions
Ans