NetBeans Quick Tip #1 - Setting Target JDK



I would like to start by this post a series of tips for NetBeans 4.1. My goal is to provide a quick solution for questions of the following kind: "I want the IDE to do something but how the heck do I tell it?". I apologize upfront to people who will read the tips and will think that they are just obvious. Hey, NetBeans user base has trippled during past year, so there's a lot of newbies for who it may not be so clear. I'd also like to give more information than you can find in docs, help or FAQ - to give you some background how things work together (or don't). Enough of introduction, here's the first tip.

Setting target JDK

You'll use this tip if you want the IDE to produce compiled .class files in a version that is lower than the JDK you're running. That can be useful for instance if the customer you're writing code for is using an older version of Java. You can still use JDK 5 as your development platform, but by setting the source level you specify the Java version for compiler.

How to do it? You can specify the target JDK by right-clicking the Libraries node in Projects View and choosing Properties. Then, go to Sources section and the Source Level combobox is what you are looking for. You can choose source level 1.2, 1.3, 1.4 or 1.5 if your platform is JDK 5. Here is a screenshot:


If you set for instance the source level to 1.4, the compiler won't accept all the new JDK 5 features like varargs, generics, autoboxing, enhanced for loop, etc. These are all marked as errors. When you compile your project, all classes are created with the source level you specify in here.

Side note: You have probably mentioned that JDK 1.5 is now called JDK 5. There won't be any 1.6 but we'll have JDK 6. If you want to understand why, take a look at this page. The world would be boring, if things would be simple and predictable all the time, wouldn't it? That's one of the advantages of IT industry, there's always something new ;-)
Comments:

Can the source level be set for freeform projects?

Posted by Alexis MP on květen 23, 2005 at 03:47 dop. CEST #

Good question - yes, it is possible, although it's a bit more complicated. For details see page 17 in chapter 12 of the NetBeans IDE Field Guide.

Posted by Roman Strobl on květen 23, 2005 at 04:40 dop. CEST #

Post a Comment:
Comments are closed for this entry.
About

Roman Strobl

Search

Archives
« duben 2014
PoÚtStČtSoNe
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today