File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes main(), PrintWriter and Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main(), PrintWriter and Collection" Watch "main(), PrintWriter and Collection" New topic

main(), PrintWriter and Collection

Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 170
The Java 2 Cert guide has question...
Which of the ff. signatures are valid for
the main() method entry point of application.
the answers are...
public static void main(String args[])
public static void main(String[] args)
public static int main(String args[])
how come the third one?

Another is.. in java API docs...
The class PrintWriter states...
Methods in this class never throw I/O exceptions. The client may inquire as to whether any errors have occurred by invoking checkError().
..but methods such flush(),close(),write(),print()
throws IOException... is this contradicting?
3.) About Collection...
Is there any
real world application or practical application
that uses collection classes?
All i know is for table of information than can
use for database application.
Lance Finney
Ranch Hand

Joined: Apr 26, 2001
Posts: 133
I'm not sure about the first two, but Collections are used all the time. If you write a video store application, you'll need to keep a List of videos the customer is renting. Maybe you'll have an employee screen, so you'll want to display a Set of all the employees on the screen. If you want to keep track of the days overdue for each video, you could have a Map with the video as key and days late as value.
I hope these few examples help.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Methods in the PrintWriter class don't throw exceptions. Inherited methods might.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Greg Ostravich
Ranch Hand

Joined: Jul 11, 2002
Posts: 112
RE: First question of the three - main signatures.
Which Java Certification guide are you using
for this?
The reason I ask is when I was studying for my Cert (it's been almost 2 years now) I had used the Boone and Stanek book which was horrible!
It was riddled with so many errors that the only value the book had was that I had to check every single thing to verify it was correct so I learned stuff that way.
The Java 2 Exam Notes and Java 2 Exam Cram books were great and when I sent some errata to Sybex for the Java 2 Exam Notes they sent me a nice e-mail from the publisher and another e-mail from the author confirming the errors.
In my opinion, the first two are in fact valid signatures if you want the main() to run because you can have the array declaration on either side.
It could be that they're saying the third is a valid signature in general but it will not work if you're trying to use it as the 'main' called to run as an application. You may want to e-mail them and ask for clarification.

Greg Ostravich - SCPJ2
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Question 1 is an error and was corrected in later printings.
Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 170
thanks for the time you spent to answer...I appreciate it very much...
I agree. Here's the link:
subject: main(), PrintWriter and Collection
It's not a secret anymore!