• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unusual Syntax

 
Greenhorn
Posts: 6
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

I'm currently studying for the OCAJP 7 exam at the moment. I'm using the OCA/OCP Java SE7 Programmer I and II Study guide by Kathy Sierra and Bert Bates. So far I've gone through the OCA part of the book once, taking all the self tests as I went along. However there were a couple of things that threw me a bit and made me worried about the exam. And that was the appearance of unusual looking code in the test questions. One in particular that I'm looking back at today is in the 1st Self Test:



The for loop is what threw me. This self test is from chapter one, before we've gone into any detail on loops. So I went forward to that section. This explains that the basic for loop has three parts 1. Initialization 2. Condition 3. Iteration. Towards the end of that section it says that you can leave all three empty essentially creating an endless loop. It also says that you can leave out the initialization and increment parts essentially creating a while loop.

But other than this the syntax of the for loop in the self test is alien to me. And this is the thing that is slightly worrying. When I first see it in the test I have to make an educated guess at what it will do, rather than knowing right away what its doing. This isn't the first time I've come across 'interesting' syntax in a test that is not mentioned, or is only covered by a single line in the book.

So my question is how to deal with things like this? Are there other sources I should be using in preparation for the test that might cover things like this? Possibly the Mala Gupta book? Or different online resources? I haven't downloaded the Enthuware tests yet because I don't want to tackle them until I'm more confident i.e. I don't want to waste them. I'm guessing a lot more coding would be a good idea. But its the fact that I don't know that these types of syntaxes exist in the first place, so how to know to use them in my own code is the question.

Anyway, any advice would be appreciated.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just wondering what is the context of this code?

As part of a question about style? loops? compilation?
It looks pretty much like deliberately obfuscated code, using underscores and $ to make it more difficult to read. Maybe so you can focus on the 'important' bits for the purposes of the book.

What this code example covers
- what comprises a 'valid' name for a class/variable
- use of the pre-increment vs post-increment operator. i.e. ++x vs x++


That is definitely not a standard for loop. The standard "iteration" step has been incorporated into the condition.
But then from my limited understanding on these sorts of test, it is just this sort of nitpicky detail that you need to know to pass it.
Nobody I know would accept code like this in a real software product.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Janet Smith,

First of all, a warm welcome to CodeRanch!

Janet Smith wrote:I'm using the OCA/OCP Java SE7 Programmer I and II Study guide by Kathy Sierra and Bert Bates.


Excellent choice! It's probably the best study guide currently available on the market for the OCAJP7 (and OCPJP7) certification exam.

Janet Smith wrote:One in particular that I'm looking back at today is in the 1st Self Test:


In this topic you'll find an excellent explanation about the exact same question (code snippet). I'm pretty sure after carefully reading this topic all your doubts (concerning this topic) will be cleared. If you still have doubts/questions after reading this topic, simply click on the "Post reply" button and let us know

Janet Smith wrote:This isn't the first time I've come across 'interesting' syntax in a test that is not mentioned, or is only covered by a single line in the book.


This question is more about the very weird identifiers (class name, variable name and parameter name) than about the for loop itself.

Janet Smith wrote:So my question is how to deal with things like this? Are there other sources I should be using in preparation for the test that might cover things like this? Possibly the Mala Gupta book? Or different online resources? I haven't downloaded the Enthuware tests yet because I don't want to tackle them until I'm more confident i.e. I don't want to waste them. I'm guessing a lot more coding would be a good idea. But its the fact that I don't know that these types of syntaxes exist in the first place, so how to know to use them in my own code is the question.


You don't provide any background information about your own Java experience. To prepare for the OCAJP7 certification exam, you don't need any other study guide than K&B7. This study guide is especially written to prepare yourself for this certification exam. But if you have no (or very little) experience in Java, it might be useful to first read a Java text book before reading (and studying) a certification study guide. And you could of course buy the Mala Gupta study guide as well and use it as a complementary resource. But it is not required, if you prepare thoroughly using the K&B7 study guide, you'll know everything to pass the exam.
You should definitely write lots and lots of code, preferrably using your favourite text editor, javac and java (and thus not using an IDE). And each code snippet in the study guide is a very good starting point for these coding exercises. You can experiment a bit with these code snippets (e.g. rename a method, use another access modifier, change the name, change the data type, and so on). Then you can tell yourself what will happen with the code (will it compile, will you get a runtime exception, what will be the output) and finally you compile and run the code to see if you were correct or not. The more you proceed through the study guide, the more syntax you will learn and need to master to pass the exam. That's one of the benefits about using a certification study guide: it's written especially for this certification exam, so you'll need to know everything explaind in the study guide to pass the exam.

Hope it helps!
Kind regards,
Roel
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stefan Evans wrote:Just wondering what is the context of this code?


It is one of the self test questions of chapter 1 of the K&B7 study guide. So it's nothing more but a question to test your knowledge about what you have read/studied. And this question has a few weird looking identifiers, so it focuses mainly on the rules for valid identifiers. For the certification exam you'll need to be able to identify valid and invalid identifiers.
 
Janet Smith
Greenhorn
Posts: 6
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:
This question is more about the very weird identifiers (class name, variable name and parameter name) than about the for loop itself.


Hi Roel,
Thanks for your reply. The rest of the question made sense and I was able to work it out. It was just when I saw the unusual loop I wasn't sure if it was valid. So I wasn't 100% sure whether my answer was correct or if it was going to have a problem during compilation or at runtime.

I'll definitely take your advice on board about tinkering around with the code and trying out different things.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Janet Smith wrote:The rest of the question made sense and I was able to work it out. It was just when I saw the unusual loop I wasn't sure if it was valid. So I wasn't 100% sure whether my answer was correct or if it was going to have a problem during compilation or at runtime.


That might have indeed be a bit of an overwhelming exercise, certainly if you are not yet familiar with the for loop. Expect on the actual exam to encounter some very weird looking variable/class/method/parameter names as well and it's up to you to decide if these names are valid or not. But in a real software product you are of course not supposed to name your class _
 
He baked a muffin that stole my car! And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic