Java – How to find out version of a .class file

Who doesn’t know java’s exception java.lang.UnsupportedClassVersionError?

Java throws the exception when class is compiled to a newest version of Virtual Machine that is trying to run. For instance, run a class compiled to J2SE 5 in a JRE 1.4

There’s many ways to find the version from a .class file. One of then need a hexadecimal editor to verify the Magic Numbers. An another way, the easier way, you’ll just need run the command javap.

javap are located in $JAVA_HOME/bin (same path of javac and java).


javap -v <class_file_path>/Test.class

You will able to check the version in “major version” line.

Classfile /C:/Users/USER/Test.class
 Last modified 26/08/2014; size 532 bytes
 MD5 checksum cb9054fefbbaa410d3asd38fb82c7c54afb
 Compiled from ""
 public class Test
 SourceFile: ""
 minor version: 0
 major version: 51

With this result we discovered that class was compiled to version 51 (JRE 7).

You can find respective JRE version in table above:

Number version JRE version
52 J2SE 8
51 J2SE 7
50 J2SE 6
49 J2SE 5
48 JDK 1.4
47 JDK 1.3
46 JDK 1.2
45 JDK 1.1

Don’t forget about to comment if it helped!

JSF – Javascript without taglibs, scriptlets and no pain

Who tried to use an if with javascript with logic operators && or ||, knows how painful this can be inside a JSF page.

Many developer opt to create .js files and reference them with tag <script src=”path_to_file.js”></script>, what is highly recommended, but will increase amount files in your directories when you just need a specific script only in a page and in no other place.

To avoid fails in JSF Render Fase, add a comment followed by tag CDATA after line with <script> and end with another comment closing CDATA, like this:


JSF works parsing these files as XML and the expressions “&&” and “||” are confused with scriptlet’s logic operators or ELExpressions, what causes fail in rendering.

JSF 2.2: Pass Through – Using custom attributes without headache

JSF taglib is very helpful to build HTML forms and reports. Not all W3C’s attributes are available in standard tags. The h:inputText does not contains the attribute “placeholder”, available only in HTML5.

To make up this “limitation” without overwriting a component or building a new one, JSF 2.2 has the “workaround” called Pass Through Attributes. A new tag to inhibit to remove any custom attributes.

Declare tag using xmlns:p=””. Now, you can put “p:” in any JSF tag as attribute, like “<h:outputText p:MyAttribute=”MyValue” … />”. This will write “<input type=”text” MyAttribute=”MyValue” … />”.

Go to work:

JSF without Pass Through

<!DOCTYPE html>
<html xmlns=""
		<f:view contentType="text/html">
				<!-- Numeric input text and placeholder attribute -->
				<h:inputText ... placeholder="Age" type="number" />

There is not “placeholder” attribute

With Pass Through

<!DOCTYPE html>
<html xmlns=""
		<f:view contentType="text/html">
				<!-- Numeric input text and placeholder attribute -->
				<h:inputText ... p:placeholder="Age" p:type="number" />
There is "placeholder" attribute

There is “placeholder” attribute

Windows 8.1 – Uninstall Sentinel License Service to update Windows to 8.1

update_windows_8_1I’ve just update Windows to 8.1 version, but with a little headache named “Sentinel License Service”.

Updater not works with this service installed in your system. You need remove it to complete the installation.

Ok, then go to Control Panel, right?! No! The service not appears in programs list.

To remove it, you’ll need download an uninstall program, available on Safenet site.

First, go to Safenet site ( and download “Sentinel HASP/LDK – Command Line Run-time Installer” (13MB).

Uncompress compacted file, open Command prompt and run the following command:

C:\...\Sentinel_LDK_Run-time_cmd_line>haspdinst.exe -purge

Wait uninstallation and continue with your Windows update!

Android – Transfering data between apps and computer over USB cable

There are many Android apps where you can run some tasks without wireless connection (4G, 3G, Wi-fi or Bluetooth), only using USB cable. Below, I’ll describe an easy way to do it.

As usual, you’ll need Android Development Kit, that can be found here.

At client development, we need to change ADB ports, used by socket connections. We can do this by running the following command:

<PLATFORM-TOOLS DIR>/adb forward tcp:59900 tcp:59900

Using Java:

Runtime.getRuntime().exec("<PLATFORM-TOOLS DIR>/adb forward tcp:59900 tcp:59900");

Remember that “<PLATFORM-TOOLS DIR>” is the path to “platform-tools” directory, located in Android SDK installation directory.

We only changed the “ears” of ADB to listen the port 59900, used in our connection.

Lets send a “Hello World!”:

Socket socket = new Socket("", 59900);
BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
bos.write("Hello World!".getBytes());

Now the Client is ready, lets go to the application.

Add the permissions “android.permission.ACCESS_NETWORK_STATE” and “android.permission.INTERNET” to the AndroidManifest.xml.

Given the appropriate permissions, we do application to listen the requests coming from port 59900, using the class ServerSocket from package

ServerSocket server = new ServerSocket(59900);
Socket socket = server.accept();

With Socket object, we can get the data using getInputStream():

InputStreamReader reader = new InputStreamReader(socket.getInputStream());
BufferedReader br = new BufferedReader(reader);
msg = br.readLine();

We are working with Strings, therefore I used the class BufferedReafer, to get entire line with method readLine();

It’s done! Now we can communicate application and computer using only USB cable.

It’s not allowed using main thread to opening socket, so, you’ll need to open the socket in a separated Thread or to extend the class AsyncTask.

If you still have doubts about this method, I’ll make available the example used in this tutorial here.

  • Advertisement

  • Advertisement

  • Copyright © 1996-2010 André L. S.. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress