return to OCLUG Web Site
A Django site.
June 5, 2013

Michael P. Soulier
msoulier
But I Digress
» Java, usable but pointlessly difficult

I've been working on a REST client in Java at work lately. I know, it scares me too. I've had to revisit much of my old Java knowledge, and pick up a lot of new chops in Swing, Eclipse, and author a decent JSON-parsing HTTPS client.

Our internal servers use self-signed SSL certs at work, so to talk to them I had to disable any host-certificate checking. Should be a simple boolean in the API right? Wrong. I forgot. Java.

First, you need to install your own trust manager.

import javax.net.ssl.X509TrustManager;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.HttpsURLConnection;

 TrustManager[] trustAllCerts = new TrustManager[] {
         new X509TrustManager() {
     @Override
     public java.security.cert.X509Certificate[] getAcceptedIssuers() {
         return null;
     }
     @Override
     public void checkClientTrusted(X509Certificate[] certs, String authType) {
     }
     @Override
     public void checkServerTrusted(X509Certificate[] certs, String authType) {
     }
 }};
 // Install this trust manager.
 try {
     SSLContext sc = SSLContext.getInstance("SSL");
     sc.init(null, trustAllCerts, new java.security.SecureRandom());
     HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
 }

Then, you need to install a hostname verifier that accepts a bad host, as that's likely wrong too, especially if you access the box by IP address when the IP isn't in the cert.

import javax.net.ssl.HostnameVerifier;

 HttpsURLConnection sconnection = (HttpsURLConnection)request.unwrap();
 sconnection.setHostnameVerifier(new HostnameVerifier() {
     @Override
     public boolean verify(String hostname, SSLSession session) {
         return true;
     }
 });

Usable? Yes. But it's no wonder that Java programmers insist on IDEs when it's so damn wordy. I mean, wouldn't a simple boolean have done here?

May 7, 2012

Michael P. Soulier
msoulier
But I Digress
» Eclipse is still mean to me

So in working on Android programming I’ve been working through O’Reilly’s book on the subject, or one of them at least, and I’m at the stage of including the jtwitter library to talk to twitter. So, I add it as a library in eclipse, and everything builds, and then when the app runs I get a spectacular backtrace with a NoClassDefFoundError exception on the very library that I just included, winterwell.jtwitter.Twitter. Umm, ok. Is it added or not?

Trying a variety of configuration changes, I’m unable to get it working, but I finally came across this post on stack overflow about moving the jar to the top of the classpath order. So under Build Path -> Order and Export, I move the jtwitter.jar to the top of the list.

Voila. It’s working now. Seems rather braindead to me, as should Java not simply search the entire classpath until it finds the the requested import? I don’t understand why this works, and that isn’t good, ’cause it’ll just happen again. If someone has an explanation I’d appreciate it.

Cheers.


May 3, 2012

Michael P. Soulier
msoulier
But I Digress
» Eclipse, you could be nicer to me

So I’m playing in Eclipse going through Android development HOWTOs. Yes, I know. Java. Thankfully there’s a scripting layer for Android, but I want to learn it all before I choose a toolset for a particular problem. Besides, Java ain’t all bad, just mostly.

Anywho, I fired up the HelloWorld tutorial, made my project, and very quickly found that Eclipse’s wonderful generated code that was going to save me all this work of typing Java didn’t compile. I got, “main cannot be resolved or is not a field”. Huh? The main it’s referring to is my main.xml file (can’t have too much XML eh Java?) describing the Android UI layout, under res/layouts/main.xml. Invoked through the ubiguitous Android R object. What do you mean it’s not there, you stupid machine??

So I do what any modern programmer does, after swearing at my screen repeatedly, I look up the error in google, and voila, I’m not alone. This post was particularly helpful. Apparently, it’s an Android SDK issue, which Eclipse invokes to create the project. Yo, Google! Get off your butts and fix it! Seems to me that you have time…


April 8, 2009

Rick Leir
blinkmonitor
» Core Java Volume II

Core Java Volume II Advanced Features / Cay S. Horstmann, Prentice Hall 2008

Here is an excellent book on Java.  Topics include:

  • Streams and Files
  • Networking
  • Database programming
  • XML
  • JNDI and LDAP
  • Internationalization
  • Advanced GUI components
  • Java 2D and advanced AWT
  • JavaBeans
  • Security
  • RMI and Web services
  • Collections
  • Annotations
  • Native methods

There is no discussion of generics; see Volume 1 for that.  1000 pages,

Get it here at OPL

March 30, 2009

Rick Leir
blinkmonitor
» The art of debugging with GDB, DDD, and Eclipse

The art of debugging with GDB, DDD, and Eclipse / by Norman Matloff, No Starch Press, 2008

This book is important reading for anyone programming on Linux in C++, Java, Perl, or Python. It is very readable with 250 pages.

Get it here at OPL

March 28, 2009

Rick Leir
blinkmonitor
» How to think about algorithms

How to think about algorithms / Jeff Edmonds, Cambridge University Press, 2008

Here is a CS textbook for advanced undergraduate courses which is more readable than most. Apply its concepts to make your programs correct and fast.  450 pages.

Get it here at OPL

March 21, 2009

Rick Leir
blinkmonitor
» Struts 2 in action

Struts 2 in action / Donald Brown, Manning, 2008

This is about the framework for Java web applications. It has lots of code examples, and good explanations in 400 pages.

Get it here at OPL

» Building Spring 2 Enterprise applications

Building Spring 2 Enterprise applications / Interface 21 ; with Bram Smeets, Apress, 2007

This is about the framework for Java web applications, and is intended for the intermediate programmer. There are lots of code examples, and good explanations in 300 pages.

Get it here at OPL

March 11, 2009

Rick Leir
blinkmonitor
» Professional multicore programming

Professional multicore programming : design and implementation for C++ developers / Cameron Hughes, Tracey Hughes, Wiley, 2008

Concurrent programming has become important for a greater proportion of all programmers since commodity PC’s went multicore. Good books on this have been in OPL for years (click on the 5-star tag to see some of them).  This book is useful because it gathers all the important topics into one place.  It starts with a good introduction, then outlines machine architecture for Intel, AMD, Sparc and Cell. Then it gets into programming structure for thread synchronization, with code examples in C++.  It has good reference information on Posix threads (pthreads).  It is intended for C++ programmers, but Java programmers will gain from reading it too.

Get it here at OPL

March 10, 2009

Rick Leir
blinkmonitor
» Test driven : practical TDD for Java developers

Test driven : practical TDD and acceptance TDD for Java developers / Lasse Koskela, Manning, 2008

TDD (Test Driven Development) takes a surprising amount of thought to do it right. Here are the techniques that lead to better software faster. 500 pages.

Get it here at OPL

February 22, 2009

Rick Leir
blinkmonitor
» Java SCJP certification

A programmer’s guide to Java SCJP certification : a comprehensive primer / Khalid A. Mughal, Rolf W. Rasmussen, Addison-Wesley, 2009

Here is a primer on Java that will be useful if you are getting certified. It includes material on recent improvements to Java such as generics. At 1000 pages, it is a bit long.

Get it here at OPL

December 21, 2008

Rick Leir
blinkmonitor
» xUnit test patterns

xUnit test patterns : refactoring test code / Gerard Meszaros, Addison-Wesley, 2007

If you are serious about unit testing then this book is for you. It is Hardcover, 850 pages. I like the list of ’smells’ which are clues if the test suite has problems. The examples are in Java, but no matter which language you use, you can profit from using this book.

Get it here at OPL

December 3, 2008

Rick Leir
blinkmonitor
» Implementation patterns

Implementation patterns / Kent Beck, Addison-Wesley, 2008

This book is about design patterns, and the examples are in Java but the concepts apply to many languages. The book is based on the premise that good code matters. In 150 pages, it packs in topics that are vital to a programmer.

Get it from OPL

November 22, 2008

Rick Leir
blinkmonitor
» Effective Java

Effective Java / Joshua Bloch, Addison-Wesley, 2008

“I sure wish I had this book ten years ago. Some might think that I don’t need any Java books, but I need this one.” — James Gosling, inventor of Java.

“This is a truly excellent book done by the guy who designed several of the better recent Java platform API’s (including the Collections API).” — James Clark, of XML fame.

Get it from OPL

November 18, 2008

Rick Leir
blinkmonitor
» Java : the complete reference

Java : the complete reference / Herbert Schildt. McGraw-Hill, 2007.

1024 pages, Updated and expanded for Java SE 6.  I wish I had time to read this.

Get it from OPL

October 31, 2008

Rick Leir
blinkmonitor
» Holub on patterns

Holub on patterns : learning design patterns by looking at code / Allen Holub. Apress, 2004

An opinionated look at design patterns. If you are using a language not known for rapid development then you want to choose the right patterns in advance so you won’t be refactoring too much. This book discusses which patterns are most useful, with examples in Java. Not recently written, but worth reading.

Get it from OPL

October 19, 2008

Rick Leir
blinkmonitor
» Programming interviews exposed

Programming interviews exposed : secrets to landing your next job / John Mongan, Noah Suojanen, Eric Giguère. Wiley Pub., 2007

If you work in technology, whether programming or similar, you probably need to look for new work now and then. This book is the best I have seen for advice on how to interview, negotiate pay, and prepare your resume. Useful to hiring managers too.

There is another way to approach this book.  More than half of the book is programming algorithms that you would learn in undergrad CS, and you can read it to refresh your knowledge.

Get it from OPL

September 14, 2008

Rick Leir
blinkmonitor
» JSP, JSF and Tomcat

book coverBeginning JSP, JSF and Tomcat web development : from novice to professional / Giulio Zambon, Apress 2007

For the Java programmer developing a web application, a framework such as JSF is recommended so you can reuse the work of many others. Here is a current intro.

Get it from OPL

August 25, 2008

Rick Leir
blinkmonitor
» SCEA Sun certified enterprise architect

book coverSCEA Sun certified enterprise architect for Java EE study guide (exam 310-051) / Paul R. Allen, McGraw Hill, c2007

For the Java pro who needs to be certified.

Get it from OPL

» Beginning JBoss Seam

book coverBeginning JBoss Seam : from novice to professional / Joseph Faisal Nusairat, Apress 2007

Here’s a good book for Java programmers. Agile and Enterprise in the same sentence! Seam is a framework that attempts to streamline the development of a web app.  I will read this book before I do my next web app.

Get it from OPL