Archive for the Java Category

I’m not going to go into what a java archive (JAR) file is. You already know what it is and why you’d want to make one, or else you would never have found your way to this page. You just want to know how to make one executable, so that when people double-click on it, it executes just like a regular non-Java program. Okay: Here’s how:
(more…)

Popularity: 19% [?]

I’m writing a small program and I’m packaging it in an executable JAR file so that all the end user has to do is double-click on it to run it. None of that command-line madness that… okay, that’s another rant. ANYWAY, my particular program uses an external package that’s ALSO stored in a jar file. To put everything in one JAR means putting a jar inside another jar.

That part is easy.

Ah, but I still want my main jar file to be executable. Still easy.

AH, but I want it to run anywhere on the destination file system, without the end user having to dick mess around with CLASSPATH statements and other crap, trying to point my application to a jar file that’s contained in its own archive. Nor do I want to spend time setting CLASSPATH statements INSIDE the jar file, because a) I have more important things to do and b) they don’t work as advertised.

Fortunately, there’s a solution.
(more…)

Popularity: 19% [?]

I was building a GUI in Java and discovered, to my annoyance, that the getText() method for the JPasswordField component has been deprecated. (It’s probably been deprecated for a WHILE and I just never cared before). So I use the getPassword() method instead.

Only getPassword() returns an array of characters (a char[]) instead of a String, which the rest of my code expects. I had a brain-fart and couldn’t remember how to turn one into the other. It happens. Rather than hunt through the API for which method turns a char[] into a String, I just Googled it. I found a nice discussion where experienced programmers jumped all over some guy for asking them how to turn a char[] into a String. He asked them instead of just reading the API docs for himself. Their response, predictably, was along the lines of “Read the API and stop asking stupid questions.”

I ALSO found that you could just do a String s = new String(char[]) , but that’s not what this post is about. Why am I bothering to post this, then?

Two reasons:

  1. Berating someone for wasting your time with a simple question on the internet is…wasting your time. This guy asked a question in a public forum. If you think it’s a stupid question, all you have to do is NOT FRIGGING ANSWER IT. Making the effort to berate someone does indeed waste time and bandwidth… but YOU are the one doing it. Not them. These people were wasting their own time and blaming this guy for it.
  2. If it’s easier for people to find answers to simple API questions on Google than it is for them to simply look in the documentation, maybe… just maybe… the problem is the documentation, not the people.

End of rant.

Popularity: 7% [?]

You’re building a Java application that needs to connect to a Microsoft SQL 2005 database, and installing the JDBC driver on the database server isn’t an option for whatever reason. After some quick research, you stumble across the best, fastest, and easiest way to connect (barring the JDBC): the open-source JTDS package. You download it, install it, and start slinging code…

…only when you run the app, you get a mysterious message like: “unable to get information from sql server.” WTF!? Your first few minutes (hours?) of troubleshooting leads you people who insist that the database server isn’t configured to accept connections. Only it IS configured, and your connection URL is pristine. You’ve checked everything against the documentation and it still won’t run. Now what?

The Problem:

Your Jtds/Java/MSSQL2005 app won’t run. Java can’t “get information” from the server even though you’ve properly configured the server to accept the connection. Now what?

(more…)

Popularity: 26% [?]