Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Jesse Silverman

Saloon Keeper
+ Follow
since Oct 25, 2020
Jesse likes ...
Eclipse IDE Postgres Database C++ Java
Been programming "since forever" but Java was always a second (or third) language. It's moving to the front seat. I'm mostly harmless.
New York
Cows and Likes
Cows
Total received
63
In last 30 days
0
Total given
3
Likes
Total received
258
Received in last 30 days
7
Total given
1171
Given in last 30 days
96
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt Green check
expand Greenhorn Scavenger Hunt Green check

Recent posts by Jesse Silverman

Just one comment to the OP.

I know it seems like you are "making the compiler happy" but it is just doing this for your safety, not its own benefit.

This is like seat belts, or looking both ways before crossing the street, etc.

I have most definitely seen code in languages that let you get away with not necessarily returning a value of the right type start crashing after years and years because compiler options or input data changed.  That's no fun.

The compiler is just trying to keep your code, or actually, those relying on it working correctly, healthy and safe.

2 days ago
There are absolutely no pre-requisites to taking the 819 exam.

You might find it pretty difficult, and want to ensure you are prepared, but there are no other certifications you need to have nor any other exams you have to have taken blocking you from registering for the 819.

Yes, this is a break from prior practice, where for a long while there were two different exams that needed to both be taken, the 819 and now the 829 break that tradition.

Welcome to the Ranch, by the way!

As I read the bit you put up, I feel myself saying "Yeah, that makes sense" and simultaneously realizing how much stuff within scope of both the exams and outside of it is more practical and important for daily effective use of Java that I could spend the same time on.

I zoom out and think how I remember it is 100 times as hard to draft a specification that handles everything correctly, including those insanely weird corner cases we all forget about all the time, then to have something 98% or 99% solid.

The specific rules about this may just be because it is very hard to unambiguously specify or code the compilations otherwise.

People who don't have experience with other standards documents often think it is hard to read, or gets really abstract in places....I think that it (using metonymy, I mean its authors) takes its responsibility as a living, breathing specification for a language that needs to be used by millions of people pretty seriously.  I find 80% of it readable, and when I see the other 20% I can only imagine that if I spent enough time thinking about the potential complications that are unlikely to happen but quite possible, and therefore, must be addressed correctly, I wouldn't be able to make it any simpler.

I referred to the primary preparatory materials, because I remembered both Hanumant Deshmukh and our Sybex authors both covered these issues thoroughly, yet tersely, in a way that would be more readable than the JLS.  I've also seen videos that covered it pretty well, tho I remember one taking a full hour to get thru it.
People seem to be somewhat split about what point is knowing too much about static and instance variable initialization, and what is knowing just enough.

Searching Google for:
"Read indirectly write only" state java

Yields 152 results, including:
https://srikarbandla.wordpress.com/2015/07/31/static-control-flow/

Chapter 12 of the JLS goes into rather a lot about these things...

At the moment, I am leaning towards "Make sure you know everything about initialization of instance members and static members that your chosen preparatory materials details."

If you fall short there, the choice of preparatory materials may be inadequate.

It might be easier to know "too much" about this, from the point of view of exam preparation in the face of "lots of different stuff to know".
That confused me the first time that I read it, too.

No, it can't just be any class.

In Java, there is an actual class called Class, like a dog named "Dog":

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Class.html

It is only this type, and not any other Class or class in the world, that is an acceptable, legal type.

This class named Class gets used very heavily in a relatively advanced Java technique called Reflection.

Reflection is 95%+ off-topic for even the 819, it is important in the industry for advanced Java programming but you don't need to know about it for the exams.

So just know that java.lang.Class is the only class they mean in this section on annotations.

For general Java use, please know it would be a terrible idea to ever try to create your OWN class named Class, because Java's is right there in the java.lang package which would make life VERY confusing for everyone if you did so.
Some find Enthuware's mock sets to be their best predictor of success or failure, enough to decide to either take or postpone the exam based on their numbers.

However, if you are doing this poorly on the Sybex questions, don't despair, don't give up, but certainly don't schedule the exam yet either!!

Their questions are not much harder, in general, than the real exam questions, tho in general the real exam questions tell you how many answers are correct to choose for each question and the Sybex questions do not.

Both their questions and the real exams expect you to know the material very, very well.

If you kind of sort, pretty much, more or less know it, there is almost no hope of passing at that time.

Don't get discouraged, keep studying, and because of the phenomenon that if you see the same questions too many times you memorize the answers and think you are okay for the test when you are not -- you are going to want some source of more mock exam questions when you do start getting much closer -- Enthuware and the Sybex book of mock exams are two popular sources, there are a number of others as well.

Other people would say "Have you figured out why you are getting so many wrong?  Did you not realize the level of detail they expect you to commit to memory?  Are you not practicing writing programs using the new features you haven't used before?  Are you having trouble reading the questions and determining exactly what they want from you?"

Those were the very long answers, the short answer is "The Sybex Book mock questions are NOT very much harder than the real questions, except that they don't tell you how many answers to choose as correct for each question."  Additionally, because questions on the test (and to be fair sometimes in their mocks) appear to be asking about one topic but the answer really hinges on another, there can be even more of that seen on the real exams.

This is already in the errata, and you can read more about it (and why it doesn't matter) here:

https://coderanch.com/t/732754/certification/Sybex-OCP-Programmer-Answers-review#3408325

Note, in general, when either the supplied answers for a mock question are incorrect, or the explanation of these answers are incorrect, the page number cited will be the one near the back of the book with the answers, rather than the page number on which the question originally appears.

And Welcome to the Ranch!
Someone's been spoiled by Default Parameters in Other Languages!
6 days ago
These kind of suck, and some (many) people will tell you that you should really never, or almost never, use labelled break or continue in your code, for the same reason we hate to see it on a test with the time tick-tick-ticking away, it takes a long time to read such code correctly.

So, even tho what I am going to say seems obvious, and even tho I still find these to take at least twice as long as almost any other question on the exam (and I have been writing nested loops for about 40 years now!)...



What I would remind you to know here is that continue inner and continue would be the same, so on a fair number of questions where they ask you "which ones will output <Some Output>?" either both those answers must be true or both of them must be false, right?

I don't encourage anyone to cheat, but it is possible that there are much better uses of your time in learning Java than in getting super-fast at these slowest of all questions on an exam that punishes spending too much time on any question very harshly.

So, you might see some where "I know if A is true C must be" -- this can either shave time off your correct answer fully worked out at amazing speed, or allow you to save time by guessing something logically sound saving those extra seconds (minutes?) for other questions.

I just realized I might be projecting a bit, as for me I could get 100 of them right in a row, they just take too long and I am pressed for time, but, the standard advice for most people is:

use your scratch area "pad of paper" or whatever for your exam to keep track of the variables which inevitably are changing thru each part of the loop.

i        j        prints
 0        0            nothing!
 0        1                        1
 0        2                        2

If you are doing this write big enough to write very fast and still be readable to you as you go along and small enough to not run out of room...

There may be other things you can do to get at least a probable answer very quickly, by looking quickly at the answer choices and back to the loops.  I find I can sometimes eliminate an answer or two that way, and on the real exam if they tell you PICK 3 CHOICES that might get you over the finish line sometimes.

In Real Life, where lots of people write interesting code you might find yourself looking at that doesn't follow best practices all around, this skill is actually sometimes pretty useful -- I have definitely seen code that was doing interesting enough stuff I wanted to understand it, modify it or debug it, that DID use these features, and it really isn't hard to take pen or pencil and paper and figure it out.

It is *not* so easy to look at it for 5 seconds and see everything, I think.

The programs Campbell recommended writing can be a lot of fun and sort of interesting, but there is also a lot to cover in the stuff you are studying...I can usually write those pretty well, not quite the same skill as matching nested loops with labelled break and continues to statements about their output.

It probably wouldn't hurt, but consider the possibility that after you study the heck out of everything, you may look back on these and say "If I skip ANY question to come back to it will definitely be one of these time sucks!" -- there are many harder things covered on the exam, for sure, but very few that take more time to answer with confidence.

I just noticed that BOTH of us were so fixated on the content of the reply that we failed to tell you:

WELCOME TO THE RANCH!!

We are generally friendly folk around here, and strive to be helpful and approachable.
2 weeks ago
You're quite welcome.

So you know, if things are fairly specific to studying for the certification, like "Is this in scope for the test?"
those questions might be best answered over here:
https://coderanch.com/f/24/java-programmer-OCPJP

But things that are about how Java works in general that just happen to also be on the exam are just great right in here, of course.

2 weeks ago
What Carey said.

In more formal terms, you can pass sub-types of the types specified in the method definition as arguments.

For primitive arrays, the only super-type or sub-type relationships are these:

JLS 4.10.3 wrote:• If P is a primitive type, then:
– Object >1 P[]
– Cloneable >1 P[]
– java.io.Serializable >1 P[]



So, you can pass an array of some primitive type somewhere that is expecting exactly an array of that exact type, a perfect match.

You can also pass an array of (any) primitive type to a parameter that wants an Object, a Cloneable, or a java.io.Serializable.

That's it, there is nothing else that fits the bill.

If you could pass an int[] somewhere you could pass a long[], which of course you can not, it would have to copy all of the values somewhere else, extend them, let you work on them, and then try to copy them back...this would never work.

The reason you can pass an individual int somewhere that a long is needed, is solely because these are pass by value.  The only work it needs to do is to extend each of those separate int parameters to long values before it enters the function.

Similarly, you can not do this:
int[] ia;
long[] la;

la = ia;



2 weeks ago
I believe that the explanatory material misuses the term "conditional expression".

I don't have time to go into it further, but from section 15.25 of the JLS, we see:

JLS 17 wrote:There are three kinds of conditional expressions, classified according to the
second and third operand expressions: boolean conditional expressions, numeric
conditional expressions, and reference conditional expressions.



The conditional expression is evaluated each time.
The code that is tied to that expression by if ( condExpr ) is conditionally executed, but that code is not part of the conditional expression itself.

Someone with a bit more time right now can confirm if this could be better worded to be consistent with established terms as used in the JLS -- I suspect it could be.


The conditional expression is always evaluated, regardless.

There is code that will be executed if the conditional expression evaluates to true.

Because that code is either break or continue,  it is not true that the code with the post-increment will be executed regardless of the value of the conditional expression -- if the code that went with the if was almost anything else, it would be as you describe, but clearly that code is control-flow code in the form of break or continue, so -- no.