• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Review Questions Doubt

 
Rachit Kumar Saxena
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,I was just reading the book OCAJP Programmer SE 1 Study Guide by Jeanne and Scott.While solving the following question(Q.23,Review Questions Chapter 1),I had a doubt:

Q)Which of the following are true?

A) javac compiles a .class file into a .java file.

B)javac compiles a .java file into a .bytecode file.

C)javac compiles a .java file into a .class file.

D)Java takes the name of the class as a parameter.

E)Java takes the name of the .bytecode file as a parameter.

F)Java takes the name of the .class file as a parameter.

I thought options C and F would be correct,not C and D as the book shows.Because after javac compiles a program into a .class file,we pass that name to run the program(obviously without a .class extension).
The option D sounds ambiguous in the case there are three classes in the program.So where am I going wrong?

 
Ganesh Patekar
Bartender
Posts: 694
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, It depends on how you interpret the meaning of option D, E and F.

In general when we say
F) Java takes the name of the .class file as a parameter so here name of the .class file is a then in this way F can be understood correct but since an option D says Java takes the name of the class as a parameter then I would opt option D as correct, also by looking at option E which mentions .bytecode It suggest D as correct.

Rachit Kumar Saxena wrote:The option D sounds ambiguous in the case there are three classes in the program.So where am I going wrong? 
Although you have three classes in a program, to run that program one of these three classes must have public static void main(String[] args) method whose name you will use to save that file with .java extension and use that class name as parameter with java command to run that program.

Again here It depends how you interpret option D)Java takes the name of the class as a parameter.  In general It can mean any one name of three class's names but since we know we use class's name with java command which has main method in It and file has same name as that class.
 
Henry Wong
author
Marshal
Pie
Posts: 22086
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it with a class that is defined in a package. You will see that the java program needs the fully qualified class name (including the package name portion), and not the fully qualified file and directory name... since the separators are different.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic