Java FX

Java FX is Sun Microsystem’s competing version to create Rich Internet Applications (RIA) rivalling Microsoft’s Silverlight and even Adobe’s Flex. I actually checked this out before I studied Adobe Flex and I sort of did not have a clear understanding on how to go about using Java FX since I don’t use an IDE to do coding. Because I did use an IDE when I studied Adobe Flex, I was able to grasp right away how make great use with these technologies. At least with the time I spent with Adobe Flex, I don’t have to start over with Java FX dealing with the basics. I can just go straight to programming.

You are not restricted to creating… Continue reading

Java Get Image Width And Height

The ImageIcon class under javax.swing package tends to be overlooked as it contains nifty methods to get an Image’s dimension. Just pass the path of the image file as parameter when you create a new ImageIcon instance then use either the getIconWidth() or getIconHeight() methods to get the width and height respectively.

ImageIcon ic = new ImageIcon(pathToFile);
System.out.println(”width = ” + ic.getIconWidth());
System.out.println(”height = ” + ic.getIconHeight())… Continue reading

Java Get OS Name

This method returns the name of the operating system that the program is running in.

public static String getOsName() {
String os = “”;
if (System.getProperty(”os.name”).toLowerCase().indexOf(”windows”) > -1) {
os = “windows”;
} else if (System.getProperty(”os.name”).toLowerCase().indexOf(”linux”) > -1) {
os = “linux”;
} else if (System.getProperty(”os.name”).toLowerCase().indexOf(”mac”) > -1) {
os = “mac”;
}

return os;
}… Continue reading

Java: Roman Numeral Tool

I was looking for a tool to check if a given String is a valid roman numeral or not. Remember old Math? Like IV = 4, or V = 5 or X1 = 11 and so on. I got lucky and chanced upon this link. I did a little modification to cater the code to my needs. This class has 2 public methods namely getRomanNumeral and isRomanNumeral. getRomanNumeral takes in an int parameter and converts it to its roman numeral equivalent. If the value is less than 1 or greater than 3,999, it throws a NumberFormatException. isRomanNumeral meanwhile, takes in a String parameter and checks if the given data is a… Continue reading

Java Check If Date Is Within Date Range

I made this method in order for me to determine if a java.util.Date falls in between 2 java.util.Date objects. I used Calendar objects to wrap the Date objects as they are much easier to use and retrieve month, day and year infos. Another helper method called isDateEqual is used within the isWithinDateRange method to determine if both Date objects are equal (excluding the time).

public static boolean isWithinDateRange(Date dateToSearch, Date startdate, Date enddate) {
Calendar calstart = Calendar.getInstance();
calstart.setTime(startdate);
calstart.set(Calendar.HOUR, 0);
calstart.set(Calendar.MINUTE, 0);
calstart.set(Calendar.SECOND, 0);

Calendar calend = Calendar.getInstance();
calend.setTime(enddate);
calend.set(Calendar.HOUR, 0);
calend.set(Calendar.MINUTE, 0);
calend.set(Calendar.SECOND, 0);

Calendar calsearch = Calendar.getInstance();
calsearch.setTime(dateToSearch);
calsearch.set(Calendar.HOUR, 0);
calsearch.set(Calendar.MINUTE, 0);
calsearch.set(Calendar.SECOND, 0);

if (((isDateEqual(calstart.getTime(), calsearch.getTime())) || (calstart.getTime().before(calsearch.getTime()))) &&
((isDateEqual(calend.getTime(), calsearch.getTime())) ||… Continue reading

Install Java On Ubuntu

I searched through every Google search results and wondered why after updating my apt-get source list, installing Java in Ubuntu still did not work out. It turned out that my source list were lacking some sources in it. If doing this command

apt-get install sun-java6-jre sun-java6-jdk sun-java6-plugin

will give you an error that package is not found, go to the source list at

vi /etc/apt/sources.list

and use your text editor to check if these lines are there.

deb http://us.archive.ubuntu.com/ubuntu feisty main restricted
deb http://us.archive.ubuntu.com/ubuntu feisty universe multiverse

If not, add them. Update apt-get again by typing

apt-get update

and then run the same command to install Java 6.

apt-get install sun-java6-jre

Installing Apache Tomcat 6 On Unix-Type Servers

Each Unix-based (I just call them Unix based since these new OS now were non existent at the time that only Unix and later on Linux were around) OS has a package manager command that will do the downloading and installation of the package specified. If you want to do installations the old fashion way … downloading the file, extracting and moving it to the desired location it’s still pretty easy for say, Apache Tomcat 6 Server. Do the following steps.

  • wget http://apache.hoxt.com/tomcat/tomcat-6/v6.0.16/bin/apache-tomcat-6.0.14.tar.gz
  • tar xvzf apache-tomcat-6.0.16.tar.gz
  • Check the Apache Tomcat’s website for any new version and just change the path and filename for it.
  • mv apache-tomcat-6.0.16 /usr/local/tomcat
  • You can place it anywhere you want in the