• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Confuse point in Chapter 1 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Ranch Hand
Posts: 75
Eclipse IDE AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the end of page 6, chapter 1 the points are mentioned as :

Each file can contain only one class


I was a bit confused as I was pretty sure I had seen a file before having more than one class. It should have been "Each file can contain only one public class".

Same applies for

The filename must match the class name, including case, and have a .java extension


It should have been "The filename must match the public class name, including case, and have a .java extension".

Moreover, out of curiosity I was thinking whether it is possible to escape multiline line comment inside a multiline comment. I know it wont make any sense but was just thinking how compiler checks or can skip a "*/".
 
author & internet detective
Posts: 41415
854
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Saumyaraj Zala wrote:In the end of page 6, chapter 1 the points are mentioned as :

Each file can contain only one class


I was a bit confused as I was pretty sure I had seen a file before having more than one class. It should have been "Each file can contain only one public class".

Same applies for

The filename must match the class name, including case, and have a .java extension


It should have been "The filename must match the public class name, including case, and have a .java extension".


You are correct on both of these. At this point, the reader could easily not know there is such a thing as a non-public class. So we don't confuse the issue. You are going to see some simplifications both in the OCA book and on the OCA exam since it is covering a subset of concepts in the language.

Saumyaraj Zala wrote:Moreover, out of curiosity I was thinking whether it is possible to escape multiline line comment inside a multiline comment. I know it wont make any sense but was just thinking how compiler checks or can skip a "*/".


No. Once you see the */, the comment is done.
 
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

Saumyaraj Zala wrote:Moreover, out of curiosity I was thinking whether it is possible to escape multiline line comment inside a multiline comment. I know it wont make any sense but was just thinking how compiler checks or can skip a "*/".


No, you can't have nested multi-line comments. I also can't think of a use case where having nested multi-line comments would be useful. So this will compileBut this will procude a compiler error

This is (far) beyond the scope of the OCAJP8 certification exam! Even if you would replace the first occurence of */ with the appropriate Unicode values (\u002A\u002F), the code will not compileAnd here is the reason why it doesn't compile. Unicode escape sequences (like \u002A) are replaced by the actual characters they represent before the Java compiler does anything else with the source code. So \u002A\u002F has 2 Unicode escape sequences and thus are replaced internally with */ (and that's exactly as the second code snippet which didn't compile). And you can have some fun with Unicode escape sequences and create real Java puzzlers (as in this topic). But once again this is outside the scope of the OCAJP certification exams.

Hope it helps!
Kind regards,
Roel
 
Jeanne Boyarsky
author & internet detective
Posts: 41415
854
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote: I also can't think of a use case where having nested multi-line comments would be useful.


I can. Suppose you have code like this:



Now imagine I want to comment out all the methods. I'd want to put a /* */ around the whole thing. But I can't because it "ends" before method 1. The same use case comes up in HTML/XML comments.
 
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

Jeanne Boyarsky wrote:Now imagine I want to comment out all the methods. I'd want to put a /* */ around the whole thing. But I can't because it "ends" before method 1.


If you have to do it manually, I definitely agree. As you could comment out all these methods with typing only /* at the beginning and */ at the end. But if you are using an IDE, you simply use a single-line commentUsing the single-line comment makes it also pretty easy, to uncomment for example only method3. Or you could even decide to add a block comment (which looks a bit messy)Although this works, it might be a little bit harder to uncomment just one method. If I select all methods again and click "Remove block comment", all added block comments are removed again. Yay! Both code snippets were created using Eclipse.
 
Jeanne Boyarsky
author & internet detective
Posts: 41415
854
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. So my use case at the command line .
 
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic