Tuesday Oct 09, 2012

Seven Random Thoughts on JavaOne

As most people reading this blog may know, last week was JavaOne. There are a lot of summary/recap articles popping up now, and while I didn't want to just "add to the pile", I did want to share a few observations. Disclaimer: I am an Oracle employee, but most of these observations are either externally verifiable or based upon a collection of opinions from Oracle and non-Oracle attendees alike. Anyway, here are a few take-aways:

  1. The Java ecosystem is alive and well, with a breadth and depth that is impossible to adequately describe in a short post...or a long post, for that matter. If there is any one area within the Java language or JVM that you would like to - or need to - know more about, it's well-represented at J1.
  2. While there are several IDEs that are used to great effect by the developer community, NetBeans is on a roll. I lost count how many sessions mentioned or used NetBeans, but it was by far the dominant IDE in use at J1. As a recent re-convert to NetBeans, I wasn't surprised others liked it so well, only how many.
  3. OpenJDK, OpenJFX, etc. Many developers were understandably concerned with the change of sponsorship/leadership when Java creator and longtime steward Sun Microsystems was acquired by Oracle. The read I got from attendees regarding Oracle's stewardship was almost universally positive, and the push for "openness" is deep and wide within the current Java environs. Few would probably have imagined it to be this good, this soon. Someone observed that "Larry (Ellison) is competitive, and he wants to be the best...so if he wants to have a community, it will be the best community on the planet." Like any company, Oracle is bound to make missteps, but leadership seems to be striking an excellent balance between embracing open efforts and innovating in competitive paid offerings.
  4. JavaFX (2.x) isn't perfect or comprehensive, but a great many people (myself included) see great potential, are developing for it, and are really excited about where it is and where it may be headed. This is another part of the Java ecosystem that has impressive depth for being so new (JavaFX 1.x aside). If you haven't kicked the tires yet, give it a try! You'll be surprised at how capable and versatile it is, and you'll probably catch yourself smiling while coding again.  :-)
  5. JavaEE is everywhere. Not exactly a newsflash, but there is a lot of buzz around EE still/again/anew. Sessions ranged from updated component specs/technologies to Websockets/HTML5, from frameworks to profiles and application servers. Programming "server-side" Java isn't confined to the server (as you no doubt realize), and if you still consider JavaEE a cumbersome beast, you clearly haven't been using the last couple of versions. Download GlassFish or the WebLogic Zip distro (or another JavaEE 6 implementation) and treat yourself.
  6. JavaOne is not inexpensive, but to paraphrase an old saying, "If you think that's expensive, you should try ignorance." :-) I suppose it's possible to attend J1 and learn nothing, but you'd have to really work at it! Attending even a single session is bound to expand your horizons and make you approach your code, your problem domain, differently...even if it's a session about something you already know quite well. The various presenters offer vastly different perspectives and challenge you to re-think your own approach(es).
  7. And finally, if you think the scheduled sessions are great - and make no mistake, most are clearly outstanding - wait until you see what you pick up from what I like to call the "hallway sessions". Between the presentations, people freely mingle in the hallways, go to lunch and dinner together, and talk. And talk. And talk. Ideas flow freely, sparking other ideas and the "crowdsourcing" of knowledge in a way that is hard to imagine outside of a conference of this magnitude. Consider this the "GO" part of a "BOGO" (Buy One, Get One) offer: you buy the ticket to the "structured" part of JavaOne and get the hallway sessions at no additional charge. They're really that good.

If you weren't able to make it to JavaOne this year, you can still watch/listen to the sessions online by visiting the JavaOne course catalog and clicking the media link(s) in the right column - another demonstration of Oracle's commitment to the Java community. But make plans to be there next year to get the full benefit! You'll be glad you did.

 

All the best,
Mark

P.S. - I didn't mention several other exciting developments in areas like the embedded space and the "internet of things" (M2M), robotics, optimization, and the cloud (among others), but I think you get the idea. JavaOne == brainExpansion;  Hope to see you there next year!

Wednesday Jul 25, 2012

How to Get Started (FAST!) With JavaFX 2 and Scene Builder

A question I hear all too often is "How do I get started with JavaFX and/or Scene Builder?" Like most tools/toolsets, there are as many ways to use these implements as there are developers...but shouldn't there be an easy way to "hit the ground running"? While casting about for an end-to-end example, demo, or video, I found a wealth of useful information, but I couldn't find anything that took someone from start to finish, quickly and easily. JavaFX is easy and fun. But don't take my word for it; let's give it a try!

Before we begin, you'll need to visit this page to download and install all the necessary goodies. Click the download link to go to the current downloads page, then download and install JavaFX (NOTE: if you already have a JDK installed that includes JavaFX, you can omit this step), then download and install the JavaFX Scene Builder. Specific instructions for those steps are located on that page. Go ahead, I'll wait right here.  :-)

Back now? Great! Let's get started!

First, let's fire up Scene Builder just to make sure it works. If not, you'll want to revisit the installation instructions on the downloads page. Once that's working, we're ready to roll...assuming you're running NetBeans 7.2 or higher, of course. You are running NetBeans, right? If not, you owe it to yourself to download it - it's free, and as you're about to see, it's pretty amazing. NetBeans and Scene Builder are loosely-but-effectively integrated, and using both greatly simplifies things and makes your life easier.

Okay, here's the fun part: we're going to actually create a simple JavaFX application, create/modify a window using Scene Builder, and successfully test it in under 15 minutes. Don't believe me? Buckle up friend, here we go!

NetBeans

We start this fun frenzy with NetBeans. Choose File, New Project, JavaFX, then JavaFX FXML Application. This creates a very simple JavaFX app that includes a main application class, a controller class to provide the actual backing logic for the window defined in Scene Builder, and the FXML file containing our window definition (XML) code. I used the name "EasyJavaFX" for our project.


Here's a quick summary of these three files:

EasyJavaFX.java contains the main application class. We won't really do anything with this class for this example, as its primary purpose in life is to load the window definition code contained in the FXML file and then show the main stage/scene. You'll keep the JavaFX terms straight with ease if you relate them to the theater: a platform holds a stage, which contains scenes. Simple. :-)

SampleController.java is our controller class that provides the "brains" behind the graphical interface. If you open the SampleController, you'll see that it includes a property and a method tagged with @FXML. This tag enables the integration of the visual controls and elements you define using Scene Builder. Let's take a look at that next.

Sample.fxml is the definition file for your sample window. You can right-click and Edit the filename in the tree to view the underlying XML - and you may need to do that if you change filenames or properties by hand - or you can double-click on it to open it in Scene Builder. Let's do that next, but first a quick look at our little project:


Scene Builder

Opening Sample.fxml in Scene Builder results in the display of a very spartan window.

Let's rework it a little. For a complete tour of Scene Builder, please visit this page, but here's the nickel tour: stuff and navigation to the left, picture in the middle, and properties on the right. :-) We'll make some small modifications like so:

First, we click on the Button in the Hierarchy panel (bottom left), which selects it in the middle Content panel. We'll move it down and over a bit to make room for another button.


Next, let's drag another button from the Library panel and drop it onto the canvas, lining it up with the other button using the red positioning lines that appear while dragging it.

Once the button is positioned, we turn our attention to the Properties panel. We'll assign our new button an fx:id of exitButton, change the text to Exit, and tab out of the field to see our changes dynamically applied. Next, we click on the other button to change its fx:id and text to clickmeButton and "Click Me for an Important Announcement", respectively. Finally, we click the Exit button and resize it to be a bit wider. Who likes to hunt for tiny Exit buttons?

We're nearly done with our first round with Scene Builder. To finish, we select the Label in the Hierarchy panel at the bottom left - that's often the quickest way to locate "hidden" visual controls - and then resize it using the sizing handles on the canvas, again using the red lines to line up with edges and buttons. Once we're done, things should look something like this:



Click File, Save to save our changes, and Scene Builder confirms with a brief message at the top of the Content panel. Leaving Scene Builder open for convenience, return to NetBeans for the next step.

Back to NetBeans

Let's make a few changes to the controller class. Opening SampleController.java, let's start with the only method we (currently) have. Since we now have two buttons, we will need to keep two methods straight. Renaming handleButtonAction to something like handleClickmeButtonAction is a good start. And to add something of significance to read when the button is clicked, we'll replace the wonderfully traditional "Hello World!" with "Space... the Final Frontier. These are the voyages of the starship Enterprise. Its continuing mission: to explore strange new worlds, to seek out new life and new civilizations, to boldly go where no one has gone before." For those reading this who aren't Star Trek fans, please feel free to substitute your own, slightly less-interesting text.  :-)

Next, we'll create a method for our Exit button by either copying the other method and renaming it or hand-jamming it. Either way, be sure you have the @FXML tag to allow for integration with our window definition/Scene Builder. Putting the following line in our new handleExitButtonAction method will give us a quick escape hatch for our demo app:

Platform.exit();

To fix the error shown by NetBeans, click on the light bulb to the left of the code line and allow it to import javafx.application.Platform. After a quick click on the Save All button, we're good to go from the NetBeans side. Now to go back to Scene Builder to wrap things up.

And Back to Scene Builder

In order for our buttons to tie to our new methods, we need to connect them to the names we gave those methods in our SampleController class. First, we'll select the top Button (clickmeButton) in the Hierarchy panel. Next we turn our attention to the Properties panel on the right. At the bottom of the right side is a collapsed section labeled "Code: Button". Clicking that line opens the Code properties window so we can update the OnAction property. Notice it still points to the method formerly known as handleButtonAction. Click the dropdown, select handleClickmeButtonAction, tab out of the field, and we're done with that button.

We repeat some of the same steps with the other (Exit) button, although since we already have the Code properties panel open, selecting the button takes us directly there. Choosing handleExitButtonAction from its OnAction dropdown and tabbing out of the field concludes our work with Exit. But there is one more thing, purely cosmetic though it may be...

Since we added quite a lot of text to our label (see the handleClickmeButton method in the SampleController class), we may want to change the default behavior of our display label. Labels default to using an ellipsis when the length of text to display exceeds the space available, but we want to see the text in its entirety! Clicking the "Wrap" checkbox in the label's Properties panel fixes that up nicely and concludes our work in Scene Builder. Click File, Save, and then back to NetBeans for our maiden voyage!


And Now Back to NetBeans for the Big Finale!

Right-clicking the project in the Projects window to the left and clicking Run provides these satisfying results:



Clicking the "Click Me" button displays the following:



And clicking the Exit button closes the application.

Start to finish, you just developed a JavaFX application using Scene Builder in less time than it takes to drink a cup of coffee...while learning your way around in the process. Fast, fun, and productive: THAT is JavaFX.

All the best,
Mark

P.S. - There isn't much to the code, but I'll post it to GitHub if anyone wants it. Just let me know.
P.P.S. - If there is any interest in a video, please let me know that as well by commenting below. No promises, but if enough people ask and I can find some free time...

Tuesday Jun 05, 2012

Quick Fix for GlassFish/MySQL NoPasswordCredential Found

Just the other day, I stood up a GlassFish 3.1.2 server in preparation for a new web app we've developed. Since we're using MySQL as the back-end database, I configured it for MySQL (driver) and created the requisite JDBC resource and supporting connection pool. Pinging the finished pool returned a success, and all was well.

Until we fired up the app, that is -- in this case, after a weekend. Funny how things seem to break when you leave them alone for a couple of days. :-) Strangely, the error indicated "No PasswordCredential found". Time to re-check that pool.

All the usual properties and values were there (URL, driverClass, serverName, databaseName, portNumber, user, password) and were populated correctly. Yes, the password field, too. And it had pinged successfully. So why the problem?

A bit of searching online produced enough relevant material to offer promise. I didn't take notes as I was investigating the cause (note to self), but here were the general steps I took to resolve the issue:

First, per some guidance I had found, I tried resetting the password value to nothing (using () for a value). Of course, this didn't fix anything; the database account requires a password. And when I tried to put the value back, GlassFish politely refused. Hmm.

I'd seen that some folks created a new pool to replace the "broken" one, and while that did work for them, it seemed to simply side-step the issue. So I deleted the password property - which GlassFish allowed me to do - and restarted the domain. Once I was back in, I re-added the password property and its value, saved it, and pinged...success! But now to the app for the litmus test.

The web app worked, and everything and everyone was now happy. Not bad for a Monday.  :-D

Hope this helps,
Mark

Wednesday Apr 04, 2012

Extreme Portability: OpenJDK 7 and GlassFish 3.1.1 on Power Mac G5!

Occasionally you hear someone grumble about platform support for some portion or combination of the Java product "stack". As you're about to see, this really is not as much of a problem as you might think.

Our friend John Yeary was able to pull off a pretty slick feat with his vintage Power Mac G5. In his words:

Using a build script sent to me by Kurt Miller, build recommendations from Kelly O'Hair, and the great work of the BSD Port team... I created a new build of OpenJDK 7 for my PPC based system using the Zero VM.

The results are fantastic. I can run GlassFish 3.1.1 along with all my enterprise applications.

I recently had the opportunity to pick up an old G5 for little money and passed on it. What would I do with it? At the time, I didn't think it would be more than a space-consuming novelty. Turns out...I could have had some fun and a useful piece of hardware at the same time. Maybe it's time to go bargain-hunting again.

For more information about repurposing classic Apple hardware and learning a few JDK-related tricks in the process, visit John's site for the full article, available here.

All the best,
Mark

Monday Mar 19, 2012

Spotlight on mkyong

Occasionally, I'd like to share a blog I've discovered or that someone has passed along to me. Criteria are few, but in a nutshell, it must be:

  1. Java-related. (Doh!)
  2. Interesting. A good blog is exciting to read at some level, whether due to perspective, eye-catching writing, or technical insight. It doesn't have to read like a Stephen King novel, but it should grab you somehow.
  3. Technically deep or technically broad. A site that dives deeply, quickly is a great reference for particular topics/tasks. On the other hand, one that covers a lot of ground at a high-but-still-technical level can be a handy site to visit occasionally as well. Both are what I consider "bookmarkable", but for different reasons.

Drumroll, please...

With that in mind, this Blog Spotlight is cast upon mkyong.com, a site I stumbled across that offers a little bit of everything for various Java dev audiences. The title indicates the site is for "Java web development tutorials", and indeed it does have these: JSF, Spring, Struts, Hibernate, JAX-WS, JAX-RS, and numerous other topics are addressed to varying degrees.

The site isn't devoted exclusively to server-side tutorials, though. Recent posts include mobile development topics, and the links at the bottom of the page connect you to reference pages and other useful sites.

I've poked around through a couple of the tutorials and, while they won't take you from "zero to hero", they do seem to provide a nice overview of the subject at hand. They also offer an occasional explanatory comment that is missing from far too many texts, sites, and doc pages. It's not a perfect site, but I like it.

The Bottom Line

mkyong.com offers a nice "summary site" of server-side tutorials, mobile dev posts, and reference links. Check it out!

All the best,
Mark 

About

The Java Jungle addresses topics from mobile to enterprise Java, tech news to techniques, and anything even remotely related. The goal is to help us all do our work better with Java, however we use it.

Your Java Jungle guide is Mark Heckler, an Oracle Java/Middleware/Core Engineer with development experience in numerous environments. Mark's current work pursuits and passions all revolve around Java and leave little time to blog or tweet - but somehow, he finds time to do both anyway.

Mark lives with his very understanding wife, three kids, and dog in the St. Louis, MO area.



Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
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