Sunday, June 2, 2013

how to check if the jre/jdk is a 64 bits jre/jdk ?

solution :

Using -d64, the jre/jdk will report an error in the case it is not a 64 bits version.

rudy@vostro:~/opt/jdk1.7.0_17/bin$ ./java -d64 version
Error: This Java instance does not support a 64-bit JVM.
Please install the desired version.

rudy@vostro:~/opt/jdk1.7.0_06/bin$ ./java -d64 version
Error: Could not find or load main class version

By the way :-) It is also written in the message that is returned :-)

rudy@vostro:~/opt/jdk1.7.0_21/bin$ ./java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

Thursday, September 22, 2011

import static and enumerations

If you want to use the constants of an enumeration and do not want to prefix the constants of the enumeration by the enumeration name then you have to use import static.

Example :

public enum Enum1 {   

import static Enum1.*;

public class Main {

    public static void main(String[] args) {
        Enum1 enum1 = value1;

That's all folks !

Friday, May 27, 2011

Breadcrumb navigation and Eclipse

Have a look to "Show in Breadcrumb" (right-click). It is a nice functionnality.
If you don't know... What is Breadcrumb ?
The problem is that it is not easy to disable it.
But there is a way :  Press Ctrl+3 and type "bread" and click on "toggle java editor breadcrumb".

That's all folks.


Wednesday, May 25, 2011


I have found a good document on MVC : Model-View-Controller Architecture
Some explanations :
  1. There is a class with a main method that will instantiate the model, the view and the controller.
  2. It is in the controller constructor that the model and the view are passed.
  3. In the view there are several buttons. Behind each button there is a different action. The action that is triggered by the button is not processed by the view ! But by the controller. It is the controller that will make the view aware that in the case that a button is pushed that it is the controller that will perform the action and this occurs in the constructor of the controller (in our example).
  4. In the controller, there is a method actionPerformed where all the magic will occur. The  actionPerformed is called and is passed an action. Depending on which action was passed (a String is linked to the action and decoded), the controller will execute a method of the model.
  5. This is imho not complete enough to understand everything on MVC.

Tuesday, May 17, 2011

Signed Applets Running in Unrestricted Mode

Some context : Use a library of encryption and decryption of messages (not developed by me). The encryption/decryption must happen on the client and not on the server.

Solution : It was decided to use a non visual applet to make use of the library. The library uses a Bouncy Castle provided.
As soon as the Bouncy Castle  provider is added you'll get an error message like this : access denied ( insertProvider.BC)

As you can read the applet can't make use of
Security.addProvider(new BouncyCastleProvider());

The developer has several possibilities.

1. Make use of a policy file
The computer where the applet is executed can decide to grant permissions to the applet Java using a file named .java.policy in the user home directory.

example :
grant {
  permission "insertProvider.*";
  permission java.util.logging.LoggingPermission "control";

grant {
  permission java.util.PropertyPermission "user.dir", "read";
  permission java.util.PropertyPermission "user.dir", "write";
  permission "<<ALL FILES>>", "read";
  permission "<<ALL FILES>>", "write";
This will solve the problem but it is rather not convenient because you have to ask every user that uses the applet  to copy the .java.policy file into his home directory and there are chances that your customer will not accept this solution.

2a. Signing the applet and run in unrestricted mode

If the applet is signed then the code will run unrestricted. Totally unrestricted ? You'll see. :-)
The procedure to sign the applet using a test certificate can be found here (a good example).


As you can read into the title you have to sign using a RSA key.
keytool -genkey -keyalg RSA -keystore test_store -alias rsatest

But in the case of Bouncy Castle, it is NOT enough !

You have to embed your code into a special bloc of code.

        AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                // privileged code goes here, for example:
                Security.addProvider(new BouncyCastleProvider());
                return null; // nothing to return

This time it will be successful and you are in unrestricted mode.

Hope it helps.


Pointers :

==>applet security basics
==>Can distribution of a .java.policy file be eliminated
==>How RSA Signed Applet Verification Works in Java Plug-in
==>How to Sign Applets Using RSA-Signed Certificates
==>Deploying RSA Signed Applets in Java Plug-in
==>How to Deploy RSA-Signed Applets in Java Plug-in
==>Signed applet getting access denied
==>How Can An Applet Read Files On The Local File System
==>Self Signed Applet Can it access Local File Systems