JBuilder2005 upgrades to JDK5.0 to implement refactoring

Source: Internet
Author: User

JDK 5.0 has made significant grammatical improvements, although the source code developed in the lower version of the JDK can run directly into JDK 5.0 without any modification. However, there is a need for a version upgrade refactoring, so you can apply JDK 5.0 for and while loops, automatic loading/unpacking, generics, and other improvements to make the code more compact while the code performance is optimized. So JBuilder's program, specifically for a lower version of JDK 5.0, offers 3 refactoring features to make it easy for you to upgrade seamlessly.

1, the project based on JDK 5.0

Although JBuilder 2005 supports JDK 5.0, its default JDK version is 1.4.2, and to make the JDK version of the Project 5.0, you must install JDK 5.0 and set the corresponding settings under JBuilder. The detailed setup of JDK 5.0 is not overly descriptive, in short, it mainly includes the following steps:

1 Install JDK 5.0 (download from http://java.sun.com/j2se/1.5.0/download.jsp).

2) Tools->configure->jdks ... The common specified JDK5.0 installation path sets the JDK.

3 Project->project properties...-> Set the page in paths and set JDK to JDK 5.0.

4) Project->project properties...->build-> in the Java Settings page, will language features: set to Java 2 sdk,v 5.0 (generics enabled), Set the target VM to Java 2 sdk,v 5.0 and later.

You can do code refactoring on JDK 5.0 only if you set the JDK version of the project to JDK 5.0.

2, optimize the cycle

JDK 5.0 introduces a more efficient loop, called the JDK 5.0-style loop, which includes:

• Array traversal

· List traversal

· Iterator for Loop

· Iterator while Loop

JBuilder provides a way to convert a lower version of the JDK's looping code to this JDK5.0 loop-style refactoring, which we illustrate with an array-traversal refactoring, see the lower version of the JDK loop code below:

Code Listing 11 Low version loop style

1. public static void arrayLoopRefactoring()
2. {
3.  int[] myArray = {1 , 2 , 3 , 4} ;
4.  for(int x = 0 ; x < myArray.length ; x++) {
5.   System.out.println(myArray[x]) ;
6.  }
7. }

Move the cursor to the middle of line 4th for (int x = 0; x < Myarray.length + +): Ctrl+shift+r->introduce foreach invokes the Loop refactoring dialog box:

Figure 22 Looping Refactoring dialog box

In loop variable name, specify a variable name for the array loop temp variable, where we set the item, press OK to complete the refactoring, JBuilder generate the JDK 5.0 style loop code as follows:

Code Listing JDK 5.0 style loops

1. public static void arrayLoopRefactoring()
2. {
3.  int[] myArray = {1 , 2 , 3 , 4} ;
4.  for(int item : myArray) {
5.   System.out.println(item) ;
6.  }
7. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.