Tuesday, August 25, 2009

Simple Twisters on Java Strings

Java Stings is a relatively easy topic in Java to understand.But until you master any topic you cannot answer even the simplest questions on that topic.These twisters are interesting and will test your Strings knowledge.In the previous tutorials on Java Strings you have learned following topics:-

1.How JVM Handles Strings
2.Important Java Strings methods
3.Method Chaining in Strings

if you wish to answer the following questions i recommend you to look back the previous tutorials to make your Java String Concepts more strong.

Get Java Books Free!!!!! Hurry answer these questions correctly and you can win a chance to download Java books for free.Just answer these questions and mail me javatute@gmail.com within 2 days of its publish.First five winner will get exclusive Java ebooks for free.Hurry !!!

1.In Java Strings are immutable and Cannot be changed
a)True
b)False

2.What would be the output of following code:-

String a="abcdefgh";
a.concat(" i don't know buddy!!");
System.out.println(a);

a)abcdefgh i don't know buddy!!
b)abcdefgh
c)Compilation fails
d)Runtime Exception

3.How many Strings are created in the String constant pool upon compilation of following code segment:-

String a="abcdefgh";
a=a.concat(" i don't know buddy!!");
System.out.println(a);

a) 1
b) 2
c) 3
d) 4

4.What would be the output of following code:-

String a="abcdefgh";
a=a.concat(" i don't know buddy!!");
System.out.println(a);

a)abcdefgh i don't know buddy!!
b)abcdefgh
c)Compilation fails
d)Runtime Exception

5.What would be the output of following code segment:-

String a ="abcdefgh";
a.toString();
a.concat("Its not a joke dude!!!");
System.out.println(a.concat("Its amazing"));
System.out.println(b.toUpperCase());

a)abcdefgh Its amazing
ABCDEFGH

b)abcdefgh
ABCDEFGH

c)ABCDEFGH
d)Compilation fails

6.What would be the output of following code segment:-

String s="abcdefgh";
System.out.println(s.length);
System.out.print(s+="ijk");

a) 8abcdefgh
b) 8abcdefghijk
c) Compilation fails
d) Rintime Exception

7.What would be the output of following code segment:-

String s="abcd";
String r=s.toUpperCase().concat("efgh").replace('A','Z');
System.out.println(r);

a)abcdefgh
b)ABCDEFGH
c)Zabcdefgh
d)ZBCDEFGH


8.What happens when Strings having no reference reside in String constant pool?
(select all that apply)

a)JVM repeatedly search for Strings with no reference and sweeps them to recollect the memory in String Constant pool.
b)String continues to reside in the memory and JVM doesnot do anything.
c)JVM keeps them in constant pool for some time then eliminates them.
d)The String Constant pool memory Overflows.

Useful Links:-

Java Interview questions on Utilities and Strings
Java Interview Questions
Best Java Interview Questions
Sponsored Links:-

Get your SCJP kit free!!!!!
Check your Intelligence here

0 comments:

About This Blog

This Blog is all about Java and programming.This blog is written by Vaibhav Pandey .He is a Computer Science Graduate .You can contact the author at javatute@gmail.com for any suggestion or Query.You can also contact the author for advertising on this blog.All the material presented here is the property of author and its reproduction in any form is strictly prohibited.

Disclaimer:-Download links provided here are not of author in any means.These are found over the Internet.
Page copy protected against web site content infringement by Copyscape

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP