Search This Blog

Thursday, January 13, 2011

Read Me First: I Am Not Dumb Question


Q: why does everything have to be in a class?
A: java is an object-oriented (OO) language. It’s not like the old days when you had steam driven compilers and wrote one monolithic source file with a pile of procedures.
Q:Do I have to put a main in every class I write?
A: nope. A Java program might use dozen of classes ( even hundreds), but you might only have one with a main method the one that starts the program running. You might write test classes, through, that have main methods for testing your other classes.
Q: In many other language I can do a Boolean test on an integer. In Java, can I say something like:  int  x  =  1;   while  ( x) {}
A: No, A Boolean and an integer are not compatible type in java. Since the result of a conditional test must be a Boolean, the only variable you can directly test ( without using a comparison operator ) is a Boolean.  For example, you can say:  Boolean isHot   = true;   while  ( isHot )    {      }
Q: Please specify system.out.println vs. system.out.print.
A: system.out.println inserts a newline ( think of println  as printnewline ) while system.out.print b keeps printing to the same line. If you want each thing you print out to be on its own line, use println. If you want everything to stick together on one line, use print.

No comments:

Post a Comment