aspose file tools*
The moose likes Associate Certification (SCJA,OCAJ 5/6) and the fly likes String Question - Im in Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Associate Certification (SCJA,OCAJ 5/6)
Bookmark "String Question - Im in Doubt" Watch "String Question - Im in Doubt" New topic
Author

String Question - Im in Doubt

Frederico Werly
Greenhorn

Joined: Sep 14, 2004
Posts: 18
I was studing about String and i cant understand why some characters have changed to Uppercase and other to LowCase.


Here the code :
----------------------------------------------------------------------------
public class StringsDemo {
public static void main(String[] args) {
String palindrome = "Dot saw I was Tod";
int len = palindrome.length();
StringBuilder dest = new StringBuilder(len);
for (int i = (len - 1); i >= 0; i--) {
dest.append(palindrome.charAt(i));
}
System.out.println(dest.toString());
}
}
----------------------------------------------------------------------------
The output from this program is:

doT saw I was toD
----------------------------------------------------------------------------

WHY NOT "Dot saw I was Tod" ?

Thanks,
Fred.
[ June 15, 2005: Message edited by: Frederico Werly ]

SCJP 1.4<br />--------<br />Sorry for my english, im half in english, i speak portuguease ;-)
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Look at what you are doing. Your program does not change the case of any of the characters, it simply reverses the order.
Frederico Werly
Greenhorn

Joined: Sep 14, 2004
Posts: 18
OH my god !!! is true !!!

Thanks .. eheheheh .. LOL !!
karthik Madhesan
Greenhorn

Joined: Dec 28, 2004
Posts: 23
Originally posted by Steven Bell:
Look at what you are doing. Your program does not change the case of any of the characters, it simply reverses the order.


good catch up steven...
keep it up..

Thanks
Karthik_Techie
SCJP1.4,ICAD 285,Prep SCJA.
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
Are these type of questions being asked in Sun exams?


Anbudan & Mahalo,<br />Arul<br /> <br />-Not a sun certified Java professional :-)
Mahesh Kumaraguru
Ranch Hand

Joined: Jun 01, 2005
Posts: 95
Originally posted by Arulkumar Gopalan:
Are these type of questions being asked in Sun exams?


Yes, to get a feel for what are the questions that may be asked in exam take a look at some mock exams in each topic. As an example, lets look at http://www.examulator.com/phezam/question.php Question No=36 ( The question changes daily, so you may not get the same question when u visit. I am mentioning the original URL as part of JavaRanch question posting policy ).

Question : What will happen when you attempt to compile and run the following code?



  • 1 Compile time error, StringBuilder cannot be cast to a String.
  • 2 Compilation but runtime exception where the code attempts to cast StringBuilder to String.
  • 3 Compilation and output of "JohnSmith" at runtime.
  • 4 Compilation but blank output at runtime.


  • The Correct Answer is
    1) Compile time error, StringBuilder cannot be cast to a String.

    When I read thru the program, the first thing that stuck me was that main( String[] ) method calls constructor, but constructor does not call output( StringBuffer ) method. There is a possibility that I might not focus on the compilation error.

    In code related questions, there may be code which distracts the candidate from the real answer. There would be no questions that deliberately confuse you, like for example declaring a variable called "l1" ( the lowercase L char follwed by number 1 = one ) and some other place use a variable "ll" ( two lowercase L chars in sequence ) and ask if the code will compile.

    But you might expect a question which tests a concept like a main method signature like main( String args ) - Note that though the variable is called args, but its not a String array. A class with this main method will compile fine, but not run because jvm will try to find the main( String[] ).

    <Bottomline>Look thru some mock exams</Bottomline>

    Visit The JavaRanch mock exam @ http://www.javaranch.com/roundup.jsp[/URL]


    Regards,<br />K. Mahesh<br /> <br />SCJP 1.2 Aug-2001 : 79%
    Mahesh Kumaraguru
    Ranch Hand

    Joined: Jun 01, 2005
    Posts: 95
    The confusing variable names depends on font - for example lowercase L and number 1 look clearly distinct above, but "rn" lowercase RN and "m" lowercase M may look more similar.
    Arulkumar Gopalan
    Ranch Hand

    Joined: Oct 13, 2003
    Posts: 104
    From what I understand, these kinds of questions are like reviewing the written code. So, it is more like testing ´┐ŻReview Effectiveness´┐Ż of a person in the exam. A person might have good technical knowledge, might not be a good reviewer. Whatz your thought? :roll:
    Mahesh Kumaraguru
    Ranch Hand

    Joined: Jun 01, 2005
    Posts: 95
    Arulkumar,

    Review effectiveness questions like clear naming of variables are not part of exam, but a question asking will a class with method "public static void main( String args )" compile ? run ? is testing the java programming language basics. There will be no attempt to confuse the candidate, but the candidate is expected to be clear of language fundamentals.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: String Question - Im in Doubt
     
    Similar Threads
    Garbage Collection question from K&B
    Array vs java.util.ArrayList
    using byte array to copy contents of one file to another
    [Easy] Shift String
    how to check whether a word is a palindrome