Pieter-Jan Remaut

Greenhorn
+ Follow
since Sep 05, 2015
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Pieter-Jan Remaut

Hi,

I've got a question about what exactly happens when I compile a class with javac. Relevant bits of my test classes are:

TestTypes.java

Horse.java

Halter.java


1. I compile all classes and run TestTypes:
2. I then comment out the tie method in Halter.java:
--> This seems obvious: I didn't recompile Halter.java.
3. I then comment out the myHalter = new Halter(); in Horse.java's constructor:

Note that in step 3, i only compiled TestTypes.java. However, unlike Halter.java, Horse.java was re-evaluated (compiled?) upon doing so.

This leads me to my question:
* What classes are, in general, compiled if I use javac in one class? Are the general rules on what gets compiled / evaluated described somewhere?
* When taking the exam, can I get confronted with a question that requires this knowledge, i.e. 'class Y is modified and class X is compiled, what is the output?'


Thanks!

Hi Henry,

Thanks for the reply. I assume you're talking about the ++x occuring in the second 'part' (correct terminology?) of the for loop, and I'd guess this just means that before executing 'this iteration of the for loop' the x variable is already incremented.

However, that's not my core problem by now (although I thank you for confirming the solution!) - see also my previous reply: the fact that me not knowing precisely this syntactical structure caused me to answer incorrectly makes me worry about how I'll do on the exam.

Cheers,
Pieter-Jan
Hi,

After thinking about this some more (which is hard to avoid once you've invested the effort of making a descriptive post about your problem), I'm guessing the answer is going to lie in the syntax of - I imagine that's what the answer calls pre-incrementing logic - I see that the third 'part' I'd expect to be present in a for statement is missing.

This raises another, more general and hence more important question about the exam - was I supposed to know about this syntax? To clarify what I mean:
* I'm pretty sure this was not explicitly explained in the scope of Chapter 1 and
* Gazing over the topics of future chapters, it seems this might be covered in Chapter 6 - not something I was assumed to have read by now.

Is this question an example of an "accidental" reliance on knowledge that was not (yet) treated in the book? My real question here is: will the exam assume technical knowledge not explicitly covered in this book or present in the Objectives, and if so, how do I best prepare for this?

To further illustrate what I mean (just so you don't think I'm being pedantic about the order of topics in the book): in the same self test series I also answered questions 2 and 5 incorrectly, simply because I'd never seen or used System.out.print(String) before (as opposed to println), including in the first chapter of the study guide. In hindsight, it seems pretty obvious that the writers just assumed everyone would have at least seen print(String) before.
However, when answering the question I simply assumed it was a sneaky way of introducing a compilation error. Is there a list out there of "Java common assumed knowledge" - or should I just have gone through Java's documentation for System.out beforehand?


Apologies for the mini-rant! If the correct answer does not depend on the used for syntax, it would be nice if we could pretend this reply doesn't exist - thanks!
Hi,

I've been going through the OCA/OCP Java SE 7 Study Guide, and have arrived at the first self test section. I'm now struggling to understand the answer to question 3:


Given that the for loop's syntax is correct, and given:


And the command line:
java _ - A .

What is the result?

A. -A
B. A.
C. -A.
D. _A.
E. _-A.
F. Compilation fails
G. An exception is thrown at runtime



My answer: C
Correct answer: B, with explanation

The question is using valid (but inappropriate and weird) identifiers, static imports, main(), and pre-incrementing logic.



Unless I misunderstand something, this does not seem to cover why C is not correct. I assumed that the hyphen (-) is not seen as a java parameter because it gets interpreted by the java executable as a command line parameter.
However, putting this theory to the test disappointed me: I just added a line to my Coffee class (pasted below for reference) and recompiled. Here's my command line output:






This seems to dispel my theory: in each case, the hyphen is clearly seen as a "Java argument". Why, then, is the answer B rather than C (the hyphen does not get printed)? Thanks!



FOR REFERENCE: Coffee class