Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

preparing for ocajp 7 but using java jvm 8

 
Mark Justison
Ranch Hand
Posts: 31
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is probably a silly question but I've been using java 8 jvm during my preparations for the ocajp 7 certification. I didn't even realize I had version 8 installed.
I imagine it matters more what preparation material I use but I wanted to check and make sure I wasn't somehow shooting myself in the foot.
On the bright side I just realized that exercism has finally added java exercises and they require java 8 for it.

Am I in the clear or do I have to start running my code with the '-target 1.7' line?

Thanks!
-Mark
 
nemo zou
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Justison wrote:Hi,

This is probably a silly question but I've been using java 8 jvm during my preparations for the ocajp 7 certification. I didn't even realize I had version 8 installed.
I imagine it matters more what preparation material I use but I wanted to check and make sure I wasn't somehow shooting myself in the foot.
On the bright side I just realized that exercism has finally added java exercises and they require java 8 for it.

Am I in the clear or do I have to start running my code with the '-target 1.7' line?

Thanks!
-Mark


I think it is fine to use java JDK 8 to prepare the OCAJP 7 exam. JAVA8 inherits almost all properties in JAVA7. If you want to know more technique details, please see http://www.oracle.com/technetwork/java/javase/8-compatibility-guide-2156366.html
I don't see any incompatible conflict if your goal is the OCAJP 7 exam.
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interface with a method body would be an error in 7 but not in 8, for one thing. You've got nothing to lose by using -target 1.7 or equivalent.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Justison wrote:Am I in the clear or do I have to start running my code with the '-target 1.7' line?

You can install different versions of Java on your machine. And if you are using an IDE for your code snippets, you can easily use a different JDK for one specific project. And if you are using your favourite text editor and javac/java, you can easily use JDK 7 to compile and run your code snippets.

I would not use JDK 8, but JDK 7! Just to be on the safe side. I don't know of any difference for the OCA exam (besides the major new language features like lambdas, predicates, default methods in interfaces and so on), but for the OCP exam I know a small difference between Java 7 and Java 8 with regard to local variables and method-local inner classes. And secondly, you are not required to add the -target option with each compilation. So more convenient and less typing

Just my 2 cents!
Kind regards,
Roel

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At one point, I needed both the Java 7 and Java 8 command lines to work. I wound up creating operating system level aliases called javac7, javac8, java7, java8. (I realize some of that is redundant, but it helped me keep track since it was more consistent.)
 
Mark Justison
Ranch Hand
Posts: 31
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed my java home directory and I can now compile using 7.
My question now is how do I use version 8? Can I have multiple versions of java as home paths?
Apparently it's not as easy as '-target 1.8' as I get:

javac: invalid target release: 1.8


 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Justison wrote:My question now is how do I use version 8? Can I have multiple versions of java as home paths?

On a Windows machine, I know a few workarounds you could use
1/ You could create environment variables JDK7_HOME and JDK8_HOME both refering to the bin directory of the JDK7 respectively JDK8 installation. On the command prompt you can then do something likeAnd the version of the JDK will be printed.
You could (of course) also create environment variables java7c with value path_to_jdk7_bin_directory\javac.exe and then on the command prompt do something likeYou'll create similar environment variables for java7, javac8 and java8 as well and then you can easily switch between compiling/running using Java 7 and/or 8.

2/ You could create something similar without the environment variables:You'll create similar variables for java7, javac8 and java8 as well and then you can easily switch between compiling/running using Java 7 and/or 8.

3/ And finally you could use doskey to create a macro:You'll create similar macros for java7, javac8 and java8 as well and then you can easily switch between compiling/running using Java 7 and/or 8.

Option 1 you have to do just once and you can use these them in as many command prompts as you want. Options 2 and 3 you'll have to do each time when you open a new command prompt (but you could of course add these commands to a batch file which you execute right after opening the command prompt).


Mark Justison wrote:Apparently it's not as easy as '-target 1.8' as I get:

javac: invalid target release: 1.8

Should work if you are using JDK8. Here you'll find an overview of all possible javac options for Java 8. Using JDK7, trying to use -target 8 will not work (obviously). And here you'll find an overview of all possible javac options for Java 7.

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic