Java Tutorial Updated!

An update of the Java Tutorial has gone live. This March 2013 edition of the tutorial contains early access information on some upcoming Java SE 8 features:

Note that this new material is currently available online only.

NetBeans IDE Development Builds Now Require JDK 7

As of March 25, the NetBeans IDE development builds require JDK 7. Please note that this does not apply to NetBeans 7.3 or any other previous release.

The reasons for this are: JDK 6 has already stopped public updates, so if NetBeans users encounter a bug that originates in the JDK, we have no way to fix it in JDK 6. Also, we are forging ahead with tooling for JDK 8, which requires the JDK 7 compiler and tools. And most important of all, we are excited about using JDK 7 language constructs in NetBeans itself. We think that there are some real improvements we can give our users, especially in the area of performance, by using JDK 7.

As always, you can register JDK 6 or earlier versions of the JDK and build programs that runs against those platforms.

Some Of The Best Java Tools

  • Apache Abdera – work easily with Atom feeds. See also Rome.
  • Antlr – this parser generator can look daunting, but it’s pretty easy once you get your head around it. Can be used to parse things like complex URLs where regexps are not up to the job.
  • ApacheDS – Java LDAP and Kerberos server, very easy to embed and great for testing your directory code. Now under the Apache Directory project which has heaps of other good stuff.
  • ASM – small, efficient bytecode manipulation
  • CGLIB – built on ASM, it works at a higher level and makes the former look like Assembler by comparison. Only downside is that it’s not well documented
  • JEXL – easily embeddable expression language, compares with OGNL
  • DisplayTag – JSP taglib for table formatting and exporting
  • EHCache – easy in-memory caching for everyone. Used this, it’s awesome.
  • Janino – someone took the time to write an embeddable Java compiler! It lets you use Java like a scripting language, eg. allow your users to type Java expressions directly into your GUIs.
  • Jar Jar Links – allows you to overcome namespace/package clashes between different versions of libraries used by your product by repackaging them. Similar to the Minijar Maven plugin that approaches the problem slightly differently by removing unused classes. Can be used to resolve dependency issues (classpath hell).
  • jDBI – substitute for JDBC that doesn’t suck when used directly
  • Jetty – web server/servlet container. Lightweight, yet lightning fast. Great for embedding, drives Grails.
  • Joda Time – date time library that kicks butt over java.util.Calendar. Intuitive (January is month 1!), easy to use and complete – everything that the java.util classes aren’t. Can be used alongside Date and Calendar. Chances are that the JSR based on this will become a part of Java 7, but why wait when you can use it now!
  • JSON-lib – best Java JSON library out there. Has good documentation. See also Jaxen.
  • Commons Math – everything from linear algebra to statistics
  • Mock Javamail – mock test infrastructure for Javamail code. See also Dumpster, Smartster.
  • Not-Yet-Commons-SSL – Nice, easy to use Java wrapper over OpenSSL. Encryption for the masses!
  • Selenium – test your web app interaction! HTML/JS, browser-based test environment – JUnit starts playing with windows :) .
  • Selenium IDE – the “IDE” part may be overstating things, but this Firefox plugin generates the basis of your test code for you. See also Canoo Webtest.
  • Selenium Maven plugin – self explanatory
  • Sitemesh – like Tiles, but non-intrusive and heaps better. It hasn’t been updated for ages because it Just Works.
  • Smack – Java Jabber client
  • XStream – objects -> XML -> objects translation. I can’t recommend this one enough, awesome one to have in the toolbox.
  • StringTemplate – like Velocity, but better.
  • Ivy – this Ant plugin means that dependency management is not just for Maven any more. I worked on a big project that used this and it worked a treat.
  • Subetha – a mailing list manager and embeddable mail server. See also James.
  • Scriptella – extract, transform and load (ETL) tool for Java.

Eclipse plugin for testing/editing regular expressions flavor of the Sun Java standard API (java.util.regex).

Screenshot:

Screenshot of eclipse plugin

Features

  • Full highlighting of regular expression syntax for an easy visual clue
    (including bracket matching , ; error detecting , , , )
  • Tooltips will be shown when the mouse is over a part of the regex. , , ,
  • Evaluates your regular expression while you are typing;
  • 4 distinct match modes:
    • Find a sequence of characters ;
    • Match a complete text , ;
    • Split text (see java.lang.String.split(String regex)) ;
    • Replace ;
  • Support for pattern flags (e.g. Pattern.CASE_INSENSITIVE, Pattern.DOTALL, …);
  • Generation of java source string literals based on the regexp, (escape slash, e.g. “\(x\)” becomes “\\(x\\)”)
  • Synchronized selection of regular expression and text: Just select part of the regexp to see which part of the text is matched by this part. .
Functionality of this plugin is available as java-applet

Demo of Regular Expression Hilighting

Move mouse to regex to see example of tooltips and brackets matching

(19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])

Opening in eclipse

In Eclipse choose Window -> Show View -> Other -> Regex Util

License

This programm is free and is distributed under the GPL. All funds for developement come from advertisement on this page.

Download the plugin

Last version: Download

Java Magazine – March/April 2013

The March/April issue of  java Magazine  is now out, with several great Java stories, including
Read the latest issue Now

Java Is Community
Get our hands-on guide to Java citizenship, from reinvigorating your JUG to hosting a hackathon and more.

Java In Robotics
Meet Java pioneer Paul Perrone—and some of his robots.

Using Java 8 Lambda Expressions
We continue our series on exploring lambda expressions.

Meet Our Guest Editor
Find out what drives JUG leader Agnès Crepet’s passion for community.

JCP Executive Q&A: CloudBees
Steve Harris talks about the JCP and the cloud.

Responsive Interportlet Communication with Ajax
Build portlets that communicate with each other and update dynamically on the client.

JavaFX in Spring
Stephen Chin uses Spring to build out data screens in a JavaFX application.

And more!

Java Magazine is a bi-monthly online publication. It includes technical articles on the Java language and platform; Java innovations and innovators; JUG and JCP news; Java events; links to online Java communities; and videos and multimedia demos. Subscriptions are free.

Eclipse HOWTO

  • Turn off hard tabs
    By and large, the Eclipse defaults mimic the Code Conventions for the Java(tm) Programming Language from Sun. For some reason, Eclipse uses hard tabs by default. Since most people set their tabs differently, the rule is not to use hard tabs in code.Go to Windows > Preferences > Java > Editor > Typing:

    • Check Insert space for tabs

    In a Java file, type a tab character and then use the arrow keys to ensure that you’re inserting spaces, not tabs.

  • Customize code formatting
    Go to Windows > Preferences > Java > Code Style > Code Formatter and click on the Edit button.

    • Uncheck Comments > Indent description after @param
    • Uncheck Comments > New line after @param tags
    • Check New Lines > Insert new line at end of file
    • Set Blank Lines > Before field declarations to.

     

  • Update compiler warnings
    Change the following items in Window > Preferences > Java > Compiler > Errors/Warnings to keep the code clean:

    • Set Unnecessary Code > Local variable is never read to Warning
    • Set Unnecessary Code > Unused or unread private members to Warning
    • Set Unnecessary Code > Unnecessary else statement to Warning
    • Set Unnecessary Code > Unnecessary cast or instanceof operation to Warning
    • Set Unnecessary Code > Unnecessary declaration of thrown checked exception to Warning
    • Set Potential programming problems > Serializable class without serialVersionUID to IgnoreThis can be a legitimate error, so be careful!

    Change the following items in Window > Preferences > Java > Compiler > Javadoc:

    • Check Process Javadoc comments
    • Set Malformed Javadoc comments from Ignore to Warning

    These will help you catch errors before JCSC does.

  • Update task tags
    I like to go to Window > Preferences > Java > Task Tags and make XXX as a high priority alias of FIXME. These high priority tags are used for items that should be looked at before the next release while the normal TODO tags are used to mark items that aren’t critical.
  • Update Code Version The assert keyword will generate errors until you set the code version to 1.4. To do this, go to Window > Preferences > Java > Compiler, and:
    • Deselect Use default compliance settings
    • Set Generated .class files compatibility to 1.4
    • Set Source compatibility to 1.4

    Now you can use the assert keyword.

  • Load your project
    I typically check out a project with CVS or Subversion and then use File > New > Project to load it into Eclipse. In the dialog that ensues, ensure that Java Project is selected and click Next. Name the project, deselect the Use default item and enter the path to your checked-out project, unless you’ve checked it out into the default directory.I check in the .project and .classpath files (being careful that the paths are relative so others can use it) so that Eclipse will load the project and be nearly ready to go. I also set the build path to build.eclipse to avoid conflicts with my ant environment which sends output into build.
  • Compile with ant
    You might need to run ant to build jars or RMI stubs. One way to do this is to use the Run > External Tools menu to call your ant target.To set this up, run Run > External Tools > External Tools and click on New. Enter a Name. To fill in the Buildfile field, click on Browse Workspace and select the appropriate build.xml file. You should have something like ${workspace_loc:/your-project/build.xml}. Then set the Arguments to -Dbuild.classes=build.eclipse (since we set the output entry in .classpath to build.eclipse above). Select the Targets tab and ensure that the desired target is selected. Then click Run. This also creates a menu item that you can select in the Run > External Tools menu.
  • Create an item in the Run button menu
    Use the pull-down menu on the Run button and choose Run. Select Java Application and use the New button to create a new configuration. Enter the name of your project as the Project and the name of the class that contains main.Optionally, go to the Argument tab and enter the name of the working directory if it is different from your project directory.You should now be able to click on the Run button and launch your project.
  • Install Subclipse
    This is the Eclipse plugin for Subversion. With this plugin you can check in your changes within Eclipse. One of the best features is that you can use Eclipse’s refactoring tools for renaming and moving files and packages and the changes are propagated automatically to Subversion.To install the plugin, use the Help > Software Updates > Find and Install Command. Select the Search for new features to install choice, click Next, click New Remote Site and enter http://subclipse.tigris.org/update as the URL and Subclipse for the Name. The rest of the wizard should be self-explanatory.Restart Eclipse as directed, and then go into Window > Preferences > Team > SVN. Edit the preferences as desired. Non-windows users will want to either select the SVN command line choice in SVN interface, or install Javahl per instructions in the Subclipse FAQ.Then, bring up the context menu for your project and run the Team > Share Project item and select SVN in the dialog. The rest should be self-explanatory.

    After doing that, you might get an authorization failed message. If so, use the Window > Show View > Other > SVN > SVN Repository command. This brings up an SVN Repository tab down by the Console. Using the context menu on your repository in this view, run the Properties command. Enter your login and password.

    You should now be able to use the Team and Compare With menu items.

    Non-windows users should install the JavaSVN plugin using the same procedure as was used to install the Subclipse plugin.

Other Tips

Here are some tips that may or may not apply to you.

  • Remove Trailing Whitespace
    Your Subversion repository may require that there cannot be any trailing whitespace. Some versions of Eclipse do not remove this space in the Source > Format command. In this case, you can bind a key to execute the Remove Trailing Whitespace command.

    1. Go to Window > Preferences > General > Keys > Modify
    2. Select the following
      • Scheme: Default
      • Command Category: File
      • Command Name: Remove Trailing Whitespace
    3. Under Key Sequence, click in the Name field, and press the key and then +T (hold down Ctrl key and type t)
    4. Click on the Add button near the bottom
    5. Click Apply

    Now when you are in an editor, you can just type <Esc>, <Ctrl>+T, and trailing white space will be removed from the text.