java.lang.UnsupportedClassVersionError: Bad version number in .class file

java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1853)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:875)

Why is this exception coming?

Fiddler: Http debugging proxy

Fiddler is an HTTP debugging proxy that logs all HTTP traffic between your computer and the Internet. Fiddler is simpler in use and provides lots of information regarding the data flow.
1. It allows you setup break points on incoming and outgoing request/response.
2. Modify incoming and outgoing response/ request to test some edge cases.
3. Gives complete information about request, response headers.
4. Provides cookies information.
5. Round trip time taken by request.
6. Can simulates slow internet connect speed. It helps in testing web applications in slow internet connections.
Click here to download fiddler


String Number conversion in JavaScript

Number to String conversion

To convert a number to string you can append an empty string or you can use toString() method. toString() method is not supported by older browsers.

var num = 30;
num = 30 * 5; // 150
str = num + ""; // or
str = num.toString();

String to number conversion

To convert a String to number, you can perform arithmetic operations like (*, / or -) such that it doesn’t alter the given string value. You might have noticed that I have not included ‘+’ in the above list this is because that JavaScript uses ‘+’ sign for string concatenation so adding ‘123′ + 0 will result into ‘1230′ and not 123. We can also user Number() function to perform the conversion. This is bit slower than any of the above options because this make explicit call to a function to perform conversion. But if you are using this option then it makes very clear that what your code is intended to do. So in my opinion if you are not worried about the performance then you can use Number() function as it will make code very clear.

var str = '123'
num = str * 1;
num = str - 0;
num = str/ 0;
num = Number(str);

If you try any of the above method on a text field which doesn’t contain valid numeric fields then you will get an ‘NaN’ as the result. So be careful :)

String.intern in Java

String.intern returns a canonical representation for the string
object. A pool of strings, initially empty, is maintained privately by
the class String. All literal strings and string-valued constant
expressions are stored in this pool.

When the intern method is invoked, if the pool already contains a
string equal to this String object as determined by the equals(Object)
method, then the string from the pool is returned. Otherwise, this
String object is added to the pool and a reference to this String
object is returned.

It follows that for any two strings s and t, s.intern() ==
t.intern() is true if and only if s.equals(t) is true. By using intern
one can get better performance as compared to equals method in String
class. equals does the character by character that you probably want.

There are some disadvantages of intern. If we start using intern
with every string then pool size will increase and could lead to memory
problem. Secondly in case of bigger pool, finding a string could be
more costly that having character by character comparison.

‘ant’ is not recognized as an internal or external command, operable program or batch file.

This error comes when program is not able to find ant.bat i.e. Ant is not installed properly. Please visit How to install Ant.

Starting tomcat 6.X in Debug Mode

To start tomcat 6.x in debug mode, follow the instructions

1. Set System environment variables
  a. JPDA_TRANSPORT=dt_socket
  b. JPDA_ADDRESS=8000 (Any other port you like)

2. Start tomcat using catalina.bat jpda start . Make sure that you have restarted the command prompt window after setting environment variables.
C:\tomcat\bin>catalina.bat jpda start

3. Debug program from the IDE and bind to 8000 (on JPDA_ADDRESS) port.

Installing Apache Ant in Windows

Apache Ant is a Java-based build tool. To install ant, please follow the instructions.

1. Download Ant.

2. Unzip downloaded file.

3. Rename the unzipped directory to “ant”. You can choose another directory name, remember that name is not too long. A long name will create a problem in Win95, Win98 and WinMe.

On these systems, the script used to launch Ant will have problems if ANT_HOME is a long filename (i.e. a filename which is not of the format known as “8.3″). This is due to limitations in the OS’s handling of the "for" batch-file statement. It is recommended, therefore, that Ant be installed in a short, 8.3 path, such as C:\Ant.

4. Set ANT_HOME environment variable.

My Computer -> Advanced System Properties -> Environment Variable.
Now on the system variable click on New to add a new Environment Variable.

5. Update Path environment variable. e.g.(oldpath;%ANT_HOME%/bin;)

You don’t require to setup CLASSPATH because of the following reasons

  1. Do not ever set CLASSPATH. Ant does not need it, it only causes confusion and breaks things.
  2. If you ignore the previous rule, do not ever, ever, put quotes in the CLASSPATH, even if there is a space in a directory. This will break Ant, and it is not needed.
  3. If you ignore the first rule, do not ever, ever, have a trailing backslash in a CLASSPATH, as it breaks Ant’s ability to quote the string. Again, this is not needed for the correct operation of the CLASSPATH environment variable, even if a DOS directory is to be added to the path.
  4. You can stop Ant using the CLASSPATH environment variable by setting the -noclasspath option on the command line. This is an easy way to test for classpath-related problems.

To test if Ant is installed successfully, go to command prompt and type ant-h. It will show you help regarding ant usages.

← Previous Page