Why do I still get errors using a switch statement with strings in Java SE7 on Lion? - netbeans

I am running Mac OSX lion and have a Java project in netbeans where I would like to use string switch statements. I downloaded and installed the OpenJDK7 and I think I have configured the project to use the Java 1.7 properly.
In the Project Properties I have set JDK 7 to the platform:
It is showing up as JDK 1.7 in the Libraries section in the Projects Window.
However, I still get a compilation error saying that switch with strings is not supported in 1.6
Am I missing a step here?

To fix this, I followed the very comprehensive tutorial from the netbeans website found here:
http://netbeans.org/kb/docs/java/javase-jdk7.html
Specifically I had forgotten to set the Sources/Binary Format to JDK 7. You can do this in the bottom right of the Sources section of the Project Properties window.

If it's anything like Eclipse, the string case is a language feature, not a library feature.
Eclipse uses its own internal compiler by default and I suspect NetBeans is similar.
So you have to ensure you're using a JDK7 compiler. From a cursory search, the project settings should allow you to set an external compiler.

Are you using 7.0.1 or greater?
NetBeans 7.0.1 provide a hint if you have a chained if-else statement to take advantage of the JDK7 features. Have you downloaded it yet ? Check out screencast #35 highlighting Project Coin features in NetBeans. NetBeans 7.0.1 provide complete tooling around JDK7 and GlassFish 3.1.1 allow you to leverage JDK7 features in your Java EE 6 applications.
http://blogs.oracle.com/arungupta/entry/totd_168_string_switch_statement

Here are some steps:
Select the project you want to change source settings for.
Got to File > Project Properties...
Select the Sources Category.
Change the Source/Binary Format dropdown to whatever format you want to use.
Viola!

Related

ANTLR and Eclipse (or any decent IDE)

I have been using ANTLR with Eclipse for some time using the ANTLRv3IDE plugin. While it is not perfect, and a bit outdated, it does its job reasonably well.
Now I am looking to switch to ANTLRv4 for another DSL that I am creating. However, Eclipse support seems to be extremely thin. I decided to try out ANTLRWorks, which is a NetBeans plugin, but I could not get it to install (it seems to be locked to specific dated versions (201302132200 while I have something newer, still 7.3 as docs say) of dependencies).
So, the question: Has anyone set up any Java IDE (preferably Eclipse, but I could be persuaded to switch if support is good for something else) to integrate with ANTLR? With integrate, I mean: code generate on save/keyboard shortcut and syntax coloring (at the very least). Code completion and other features are of course nice to have, but I could live without them for now.
I am well aware of Xtext and I have had great success using it for some projects, but unfortunately it does not fit the needs here (need no IDE support, need my own DSL model not based on ECore, etc).
I know ANTLRWorks can be run as a standalone application without a Java IDE, but that I consider to be a last-resort solution as it is extremely cumbersome to work this way (switch between application, files out of sync, no VCS support etc). I tried the other way around: to install the Java parts into ANTLRworks (which itself is a NetBeans distro), but it did not end well (it seems basic project support etc was stripped out of ANTLRworks).
Antlr4 plugin for Eclipse is here:
https://github.com/jknack/antlr4ide
ANTLRWorks 2 uses many non-public interfaces from NetBeans, which means it will always be bound to a particular version. The standalone download will always work because it bundles the dependencies itself.
The standalone build of ANTLRWorks 2.1 is available. This build includes support for ANTLR 4.1.
A new plugin build of ANTLRWorks 2.1 will be available once NetBeans 7.4 is released.
Moving forward, the code for ANTLRWorks post-2.1 is open-source under an LGPL license.
I think you have downloaded Netbeans 7.3.1.
Try download 7.3 from https://netbeans.org/downloads/7.3/ and install the ANTLRworks plugin there. (Link to the ANTLRworks Update Center: http://tunnelvisionlabs.com/downloads/nbupdates/nb73/aw2/updates.xml ).
Note that ANTLRworks v2 contains ANTLR v4.0, which is not the current version of ANTLR (4.1). So also download ANTLR v4.0 from the ANTLR download folder (The antlr-4.0-complete.jar file) and use it as library for compilation.
Now you can use nearly all things you wanted.
ANTLRv3IDE was opensourced. It should be compile-able for Juno. For stringtemplate (ST4) look at the Hastee plugin. It supports some of ST4 constructs.

How to add JDK 7 in compiler list in eclipse

I have installed the JDK7 on my machine and I want it to add in the list of compiler
I have tried adding JDK 7 in the list of installed JRE but it is still not appearing in the list of compiler compliance level.
Could any one tell me how can I add JDK 7 into new compliance level.
Eclipse uses its own compiler (see What is the difference between javac and the Eclipse compiler?), so you won't find it if you use an old version of Eclipse (as probably your RSA is based on). Java 7 support is available for Eclipse 3.7.1 or higher (at the moment current stable is 4.2).
However, if you want to keep that version of Eclipse, you can create a new Builder using your JDK7 as base. To do this, go to Project and add a new Builder specifying where the javac is and the other options.
Look also at this question: Eclipse 3.5 and Java 7
Looks like you have to use the 3.8 version of eclipse to get Java 7 support. But I noticed that some later versions of 3.7.x might have it too.
See this for features:
http://www.eclipse.org/jdt/ui/r3_8/Java7news/whats-new-java-7.html

Failed to create javafx flatform in netbeans

I got this error when I'm trying to create a Java Swing Application, by using Netbeans.
I really don't know how to fix this error. Internet did't give me a really good answer.
I Unistalled Netbeans & then reInstalled. but It doesn't work.
How can I fix this error. Thank you.
I don't have a NetBeans installation at hand, but have a look at your Java installations configured in NetBeans ("Java Platform Manager" in Tools menu?). Select the Java version you are using. There should be a JavaFX tab. I think you can disable it there, if you don't need it.
Note: If you're using the latest Java version from Oracle, then JavaFX should automatically be configured correctly, since JavaFX is now shipped with the JDK.

What is the purpose of Java JDK to Eclipse?

I've just installed Eclipse, after i installed the java JDK.
The Getting Started guide (in Eclipse) says i should reference my JDK installation in Window>Preferences>Java>Installed JREs, but that a JRE would also work.
Select the Java > Installed JREs preference page to display the installed Java Runtime Environments. Confirm that a JRE has been detected. By default, the JRE used to run the workbench will be used to build and run Java programs. It should appear with a checkmark in the list of installed JREs. We recommend that you use a Java SDK instead of a JRE. An SDK is designed for development and contains the source code for the Java library, easing debugging.
There was already a JRE set up there (not a JDK), so i did nothing and tried to compile a Hello World (just to see what would happen). To my surprise, it compiled!
I searched a little bit and it looks like this works because Eclipse has a built-in Java Compiler. I tried debugging using the same eclipse set up, and it was also successful.
So, what is the difference between setting a JDK and JRE there? Why is it important to download the JDK, since in my default configuration Eclipse doesn't seem to use it?
Probably the main difference is you get the source to all of the Java runtime libraries (with the JDK) which can be a big help. I always use the JDKs for that reason.
Also if you are debugging, this will allow you to meaningfully step into Java runtime libraries.
There are a number of tools that come with the JDK that don't come with the JRE - JConsole (http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html) springs to mind. This for example can help you understand & monitor the memory usage of your application and so on. Either way if you head into unfamiliar territory, I highly recommend you follow the Eclipse suggestion and use the JDK!
JDK is equipped with different helpful tools, as DotMasta mentioned. Eclipse's "version" of JDK is called JDT. Apart from range of shipped tools, there are also differences between javac and Eclipse built-in compiler ecj, so check here to see the comparison. One of the most important differences is that javac is strict, i.e. with ecj you can create a class file even in case of errors in code, which is perfectly suitable for testing phase, but not for launch :)
JDK contains software development tools which are used to compile and run the Java program.
Plenty of classes and methods in standard jdk library
Javac java compiler
Diffrences and why you will need this?
JDK includes the JVM, standard class libraries, and several other tools that a developer needs in order to create a Java program.
JRE includes the JVM, as the JRE provides some standard libraries and the JVM which can be used to execute a Java program.
You can even look there: http://en.wikipedia.org/wiki/Java_Development_Kit

How do i find out the JDK version Eclipse is using?

I see JRE all over the place, but i can not be sure which JDK is compiling my code. How do i find out?
You can still check/set which JDK version you want to compile to. If you go to Window->Preferences, then click "Java" from the menu on the left and then "Compiler". The first setting allows you to see which JDK version is being complied with.
I know this doesn't directly answer your question since JDK isn't actually compiling it, but hopefully it helps!
Actually Eclipse has its own compiler. You can develop java apps using only the JRE and Eclipse
You don't find JDK explicitly mentioned anywhere because way to point to a JDK is under the name of 'Installed JRE'. That is Window > Preferences > Java > Installed JREs. This is useful when using m2e plugin.
secondly apart from having it's own built in compiler, it is recommended to you install one of your own to support development of Java programs. Except below from eclipse wiki page :
If you intend to use Eclipse for Java development, then you should install a JDK