Archive for the ‘Java’ Category

04.4
07

Test your Java Skills

by Terry Pearson ·

I am currently in a Java class at my university. This is a language that I think is just wonderful. Java (and  .NET languages) truly utilizes Object Orientated Concepts to the fullest.

When you are learning a language, it is sometimes difficult to test your skills. You certainly think you know a lot about the language, but how do you know that you are an expert? Possibly the best way, besides certification, is to take online tests on the language of your choice.

A great place to look for these online tests is on text book publisher websites. For example, my textbook entitled “Introduction to Java Programming” by Daniel Liang, has a website with source code and tests available to all. This tool makes it very easy to assess your current skill set, and helps identify areas in which you need to improve.

02.3
07

Learning about Applets

by Terry Pearson ·

Web programming can be as simple or as complex as you want it to be. The easiest web publication is a simple text file. You could upload it to the web and it would show up as just text.

From the text file, you could progress to a simple HTML file. This is basically a specially formatted text file.

As complexity increases, so do your options and features. Languages like Coldfusion add another layer to the complexity. But, they open the door to many more uses. PHP would probably come slightly after Coldfusion.

Eventually you come to a category called “Applets.” I am sure you have heard of them, but they can be seen as mysterious in nature. They are Java Programs that are compiled and all, and told to run within the confines of a web browser.

Applets are just past the edge of the “scripting universe.” In a way, they are the bridge between compiled code and scripts. They themselves are compiled, but closely relate to their scripted environment.

Learning how to program applets can be rewarding and can extend the usefulness of your website. My advice is to start by going to WebChalkboard’s lessons on applets. They are concise and to the point and will get you started in no time.

After you go through the initial tutorials on WebChalkboard, go over to Sun’s own applet tutorials. Sun’s tutorials will show you how to use pictures, sounds and more. It will take your applet building to the professional realm.

Once you know the basics, applets can be a fun way to create an interactive and informative website!

01.28
07

Display a Double with two decimal places in Java

by Terry Pearson ·

I just spent the longest time trying to find the easiest way to make a double display two decimal places in Java.

Basically, I wanted to output money information, and it would look better if the money data says “$5.00″ instead of “$5.0″ as is sometimes the case. There are so many “solutions” to this, that it is difficult to wade through them all.
The best solution I encountered was relatively easy. You can find it in Sun’s Java forums.

import java.text.DecimalFormat;

double d = 8.9909879;

DecimalFormat dFormat = new DecimalFormat(0.00″);

String formattedString = dFormat.format(d));

The above code will format a string that has two decimal point precision. It will give the number 8.99 instead of 8.9909879.

01.26
07

The most important reference document for Java

by Terry Pearson ·

If you are new to Java, or are more experienced than anyone, you still need to look up stuff. Every developer has moments in their language of choice where they just can’t solve a problem. Or, they may just be looking for an easier way. Don’t be ashamed to look up a result. Doctors do it all the time. Engineers do it. Why shouldn’t programmers do it as well. It helps us all develop cheaper, faster, and smarter code without reinventing a wheel that someone else already created.
To make life easier for us all, Sun publishes some of the best documentation that I have seen for a programming language. In a very clear layout, all functions in the Java API are laid out in one place. Each class has easy to understand instructions on the class in general, it’s interfaces, classes, exceptions, and errors. This is all published on Sun’s website as the Java API Specifications.

I knew about this for a while, but just today realized it’s complete usefulness. This has quickly become my favorite “book” on Java programming. To top that off, it is freely available online.  This is a useful set of documents for any Java coder.
Sun even caters to the more graphically inclined persons, the documentation can be formatted in the form of a tree (extending from the package).

Also, you can use the “index” link to show an entire “glossary” for a package. This can be a speedy way to get results when using the find function on your web browser.

So, whether you are a Java Newbie, or a super Java coder, using the API specs will help improve your programming ability.