aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes scjp help required Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "scjp help required" Watch "scjp help required" New topic
Author

scjp help required

PETER CARTER
Ranch Hand

Joined: Aug 28, 2004
Posts: 70
Given:
1. public class Alpha{
2. public static void main( string[] args ){
3. if ( args.length == 2 ) {
4. if ( args.[0].equalsIgnoreCase(�-b�) )
5. System.out.println( new Boolean( args[1] ));
6. }
7. }
8. }
And the code is invoked by using the command:
java Alpha �b TRUE
What is the result?
A. true
B. null
C. false
D. Compilation fails.
E. The code runs with no output.
F. An exception is thrown at runtime.
Answer: A
Why ??
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
PETER, I have asked you before: please specify the source of these questions.

Why do you think the anwser is not choice A? Have you run the code?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
s choukse
Greenhorn

Joined: Dec 12, 2001
Posts: 27
Hi,
What is that you did not understand in this code. The code is pretty straight forward.
I am concidering that
1. The instead of was a typo.
2. The instead of was a typo.

To compile the code then true is an obvious answer.
If the above assuptions are incorrect and you got the code the way it is in your post then it will result in compilation error.

-Saurabh
[ September 15, 2004: Message edited by: Barry Gaunt ]
PETER CARTER
Ranch Hand

Joined: Aug 28, 2004
Posts: 70
Sorry,but I compile fail:
E:\l>javac Alpha.java
Alpha.java:4: <identifier> expected
if ( args.[0].equalsIgnoreCase("-b") )
^
Alpha.java:6: ')' expected
}
^
2 errors
Why I can't compile successfully?
Thanks .
Adrian Marti
Greenhorn

Joined: Sep 07, 2004
Posts: 11
args[0] not args.[0]

args is an array

hth

Adrian
Doyle Matt
Ranch Hand

Joined: Jul 05, 2004
Posts: 76
Hi Peter,

May I suggest the following books for you to get an indepth knowledge on java.

1. Beginning Java 1.4 Ed by Horton
2. Sun Certified Programmer & Developer for Java 2 Study Guide by Kathy Sierra, Bert Bates

There are a lot of online resources namely:

1. Javaranch (of course)
2. java.sun.com (try to download the tutorial)
3. javaworld.com
4. google.com

Hope this will solve all of your problems

Cheer.


SCJP 1.4
PETER CARTER
Ranch Hand

Joined: Aug 28, 2004
Posts: 70
Marti,

public class Alpha{
public static void main( String[] args ){
if ( args.length == 2 ) {
if ( args[0].equalsIgnoreCase("-b") )
System.out.println( new Boolean( args[1] ));
}
}
}
I compile it.
E:\l>java Alpha -b TURE
false
So C is right ,not A.
Do you follow me ?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
TURE? You typed TURE?
PETER CARTER
Ranch Hand

Joined: Aug 28, 2004
Posts: 70
E:\l>java Alpha -b TURE//wrong

E:\l>java test1 -b true
true

That's right !!

Thank you very much !!

Cheers !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: scjp help required