• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

OCP Java SE 11 Programmer II Study Guide (Sybex 815) - Import in Single-File souce-code programs

 
Greenhorn
Posts: 4
1
Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'd be greatful to get some clarification around imports in single-file source-code programs.

On Page 15 - Table 1.1 it is stated that it is only possible to import code that came with the JDK.

But when having two files ImportedClass.java and AnotherImportedClass.java






Assuming they are compiled, the import works absolutely fine in the ImportTest.java



when running it from the main folder with


Did I miss anything or understand it wrong?






 
author & internet detective
Posts: 40677
827
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
Anke,
You compiled ImportedClass and AnotherImportedClass already right? That's fine, you are allowed to use things that are already compiled whether you wrote them yourself or they are third party jar files.

What you can't do is have two java files and reference them without compiling either.

Also, I want to make sure you are curious about this for learning (vs edge cases for the exam.) Because chapter 1 is no longer in scope for the 819. See this postfor other topics you no longer need to know (and one important one you need to add)
 
Anke Bremer
Greenhorn
Posts: 4
1
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jeanne,

Thanks for your reply.

Yes, it was mentioned in the book that only the one java file can be compiled in memory and not several when using the launcher.
However, the statement was that no other code than that from the JDK can be imported. No other libraries, etc. But assuming my class files work, then other libraries would as well? I was just curious as I think it is good to understand things properly.

Thanks for the hint about the 819 exam. Do the same changes apply to 815/816 as well?


 
Jeanne Boyarsky
author & internet detective
Posts: 40677
827
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anke Bremer wrote:However, the statement was that no other code than that from the JDK can be imported. No other libraries, etc. But assuming my class files work, then other libraries would as well? I was just curious as I think it is good to understand things properly.


Oh. That wasn't true. (and I think it is in the errata). At the time I wrote that chapter, I thought there were more limits on single-file source-code programs than actually exist. My readers informed me otherwise .

Anke Bremer wrote:Thanks for the hint about the 819 exam. Do the same changes apply to 815/816 as well?


There are no 815/816 exams anymore. They were merged/tweaked and turned into the 819. Luckily 95% of it is the same so the study guide you have + the 816 one is helpful.
 
Anke Bremer
Greenhorn
Posts: 4
1
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, my mistake, sry. I mixed up the 819 with the 817 when reading your post earlier. Thanks!

I am using the complete study guide (815, 816 and 817). So far I find the book really well structured and accessible.
Looking forward to getting stuck into more complex topics

 
Jeanne Boyarsky
author & internet detective
Posts: 40677
827
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
Ah yes. The 817 definitely exists .  It doesn't cover this topic either.
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic