Friday, October 30, 2009

Printing Javascript object properties

If you would like to print out all the properties of an Javascript object and their associated values, do this:

Note: Replace < objName > below with the name of your instantiated object.

var str;

for(prop in < objName >)
{
str += prop + ' value :' + < objName >[prop]+ '\n ';
}

alert(str); //Show all properties and its value

Friday, October 16, 2009

Resolving the Exception in thread "main" java.lang.UnsupportedClassVersionError: com/google/gwt/dev/GWTCompiler(Unsupported major.minor version 48.0)

When I tried compiling my GWT project using TestProject-compile.cmd, I got the following exception:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/google/gwt/dev/GWTCompiler (Unsupported major.minor version 48.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)



How To Resolve This?

Ensure that your JRE version in your environment variable in anything from Version 1.4 and above.
To check your Java version, pull up comman prompt and type in the following on the command line to check your JRE version:
java -version

Since I had Oracle installed, my "Path" environment variable was referencing 2 Oracle JVM's that were versions 1.1.3 and 1.1.8. I deleted these two paths and ensured that JVM path in the environment variable was pointing to the folder where I had installed Java 1.6.

This worked and did not cause the UnsupportedClassVersionError exception to be thrown anymore.

Tuesday, October 13, 2009

How to print output on the same line on the console in Java?

Trying to continuously print output onto the same line in a console using Java?

Try this:
System.out.print("TEST TEXT\r");

The "\r" (carriage return) character returns the cursor to the beginning of the output line.

Just remember that if you do System.out.print("TESTTEXT\r"); and then System.out.print("BLAH\r");, your final output will be
BLAHTEXT

This is because the remaining characters from the longest string are not deleted after the shorter string overwrites it. Hence try to do something like this to delete of all characters from the longest string:
System.out.print("TESTTEXT\r"); //write text and go back to beginning of line
System.out.print(" \r"); //have many empty spaces to overwrite the chars from the longest string and then go back to the beginning of the line
System.out.print("BLAH\r"); //write text and go back to the beginning of the line

This will output:
BLAH

Monday, October 12, 2009

Internet Information Services - Setting Up Access Permissions for Specific Windows Users to Access Specific FTP Virtual Directories

To set up the Windows IIS FTP Server to allow certains Windows users to access certain virtual directories, ensure that you have done the following:
1. Install an IIS FTP Server
2. Ensure that you have a Windows User account set up for the user you want to log on as, onto your FTP Server.
3. In the 'Default FTP Site Properties', uncheck the 'Allow Anonymous Connections' checkbox which can be found under the 'Security Accounts' tab. This will allow specific users that have the right username and password of one of the Windows user accounts on the FTP Server machine to access the FTP Virtual Directories.

Once Step 1 and 2 above is set up, permissions to specific FTP Virtual Directories can be set up as follows:
3. Right click on the virtual directory you have created (eg. CHITRATEST). Below this Local Path textbox, there are three checkboxes (Read, Write and Log Visits). You can uncheck/check these boxes. Think of these boxes as three different pipes. Clogging a pipe (i.e. unchecking a say, 'Write' checkbox) will cause all Windows users who log on to the FTP Server to not have Write permissions to CHITRATEST, regardless of whether the folder on the local path of the virtual directory (e.g. c:\TEST) has 'Write' permission enabled for the currently logged in Windows Users.
4. Once the FTP Server evaluates the super access priviledges it can give to a currently logged Windows user (by evaluating the checkboxes in Step 3 above), it will then evaluate the next level folder properties of the virtual directory. If say, C:\TEST is mapped to a virtual directory called CHITRATEST, the Security permissions set on C:\TEST and C:\Inetpub\ftproot\CHITRATEST will both be evaluated to give the currently logged Windows user specific permissions. Both C:\TEST and C:\Inetpub\ftproot\CHITRATEST must have the exact permissions set/unset for folder level permissions to be evaluated by the FTP Server.

Summary
-------

To allow users with the username and password of a specific Window User account to access the FTP server, follow Steps 1 and 2.

To allow specific logged on Windows users (with a corresponding Windows User account) to gain access permissions to specific virtual directories, follow Step 3.

To allow a lower level folder access permission for logged on Windows users, follow Step 4.

Why does a file on a Windows machine have different timestamps on different Windows machines?

I have a program (which runs on a Windows machine) that gets a list of files and their corresponding timestamps from a remote Windows machine.

On the 4th of Oct (the day when Daylight savings triggered of a 1.59am to 3am time change in Melbourne, Australia), my program returned a null value when retrieving the last modified timestamp of a file that was created at 1.21am that day.

What puzzled me was that although the file was created at 1.21am (which was recorded within the contents of the file), the last modified timestamp was 2.21am. When I uploaded this file across to a machine that had the Windows option "Automatically Adjust for Daylight Saving Time" turned off, it had a last modified time of 1.21am.

After reading up on http://www.peterdonis.net/computers/computersarticle3.html and http://support.microsoft.com/kb/129574 , I finally realised why the last modified timestamp of the file on a Windows machine was different to the timestamp when it was actually created:

On Windows, if you are in a location that observes DST (Daylight Savings Time) and the DST time change kicks in, the timestamps on all files on the Windows NT file system (NTFS) are shifted by an hour. Even the files that were created BEFORE the daylight saving time change are shifted. So basically, the timestamps of ALL files created ANYTIME before 4/10/2009 1.59am will have one hour added to it.

As stated on the Windows Help and Support page, "All times displayed in Windows NT for event log events and files on NTFS partitions are computed as offsets to Greenwich Mean Time (GMT). When you set the time on your system, you are setting the value for GMT. When you select your local time zone for the system, the appropriate number of hours are added or subtracted to the stored GMT value. This adjusted time is displayed. When "Automatically Adjust for Daylight Saving Time" is selected, an additional hour is added to GMT during daylight savings time (the first Sunday in April through the last Sunday in October)." In other words, manually changing the system time does not affect file timestamps but when the local time zone is changed, all file timestamps will be adjusted to display the new zone time.