EzDevInfo.com

applet interview questions

Top applet frequently asked interview questions

JavaFX is now out: Are Applets and Java Desktop officially dead/dying? [closed]

JavaFX is now out, and there are promises that Swing will improve along with JavaFX. Gone will be the days of ugly default UI, and at long last we can create engaging applications that are comparable to Flash, Air, and Silverlight in terms of quality.

  1. Will this mean that Java Applets that hail from 1990's are dead and not worth going back to?

  2. Same with Java Desktop: What will be compelling for us Java Developers to use it rather than JavaFX?


Source: (StackOverflow)

How to combine two Jar files

Is it possible to combine two jar files such that in an applet tag I can simply do something like

archive="jarjar.jar/jar1.jar"...  ...archive="jarjar.jar/jar2.jar"... instead of
archive="jar1.jar"... ...archive="jar2.jar"...

I need to only have one jar file so putting two jar files in a folder will not help me.


Source: (StackOverflow)

Advertisements

How can I get early access to Oracle Java updates, so I can test my RIA and avoid fire-drills when these updates are made public?

Having had our application stop working when customers installed the 7u45 update, we're wondering what more we can do in the future to be ready for these updates up-front and avoid release-day support nightmares.

(Per the Java version numbering scheme, the next Critical Patch Update, planned for January 14, will be 7u51. The next Limited Update (date unknown) will be 7u60.)

I've poked around the Oracle and OpenJDK websites, and not found anything particularly useful. The main Oracle page for Java SE has an Early Access Downloads section. It has three links that have potential, but don't pan out:

An answer to the second question I linked above points to an OpenJDK bug report that was filed back in August. (It has a "CAP" label, which might stand for "Compatibility and Performance"?) So clearly some people are able to test their applications against these updates. Any pointers on how to join that club are much appreciated!


Source: (StackOverflow)

socket programming multiple client to one server

How do you handle multiple client to connect to one server? I have this LogServer.java

import javax.net.ssl.*;
import javax.net.*;
import java.io.*;
import java.net.*;

public class LogServer {
  private static final int PORT_NUM = 5000;
  public static void main(String args[]) {
    ServerSocketFactory serverSocketFactory =
      ServerSocketFactory.getDefault();
    ServerSocket serverSocket = null;
    try {
      serverSocket =
        serverSocketFactory.createServerSocket(PORT_NUM);
    } catch (IOException ignored) {
      System.err.println("Unable to create server");
      System.exit(-1);
    }
    System.out.printf("LogServer running on port: %s%n", PORT_NUM);
    while (true) {
      Socket socket = null;
      try {
        socket = serverSocket.accept();
        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(
          new InputStreamReader(is, "US-ASCII"));
        String line = null;
        while ((line = br.readLine()) != null) {
          System.out.println(line);
        }
      } catch (IOException exception) {
        // Just handle next request.
      } finally {
        if (socket != null) {
          try {
            socket.close();
          } catch (IOException ignored) {
          }
        }
      }
    }
  }
}

and an embedded applet with part of the code like this e.g

import java.io.*;
import java.util.logging.*;

public class LogTest
{
  private static Logger logger = Logger.getAnonymousLogger();

  public static void main(String argv[]) throws IOException
  {
    Handler handler = new SocketHandler("localhost", 5000);
    logger.addHandler(handler);
    logger.log(Level.SEVERE, "Hello, World");
    logger.log(Level.SEVERE, "Welcome Home");
    logger.log(Level.SEVERE, "Hello, World");
    logger.log(Level.SEVERE, "Welcome Home");
  }
}

now the question is if I run "java LogServer" on the server, it will open the application and waiting for input stream and if I open my site, it will start streaming the log. But if I open one more using other computer/network, the second site does not log the stream. seems like it's because the first one still bind to port 5000.

How do I handle this? How does socket actually work with multiple client / one server?


Source: (StackOverflow)

Warning on Permissions attribute when running an applet with JRE 7u45

I've just upgraded JRE to 7u45, and my applet receives a warning message on start-up, saying " This application will be blocked in a future Java security update because the JAR file manifest does not contain the Permissions attribute." Then I added the following two attributes to the manifest of my applet Jar file (self-signed):

Permissions: all-permissions
Codebase: *

However the warning message didn't disappear. I doubt that I'm missing some other things, but can't find them out after hours of research. Anybody else knows the solution?

Update

Trusted applet that is signed with a valid certificate can't run either. The yellow warning message doesn't show up but another error dialog is displayed saying the applet is blocked by the security settings, while changing the security level or something else in Java Control Panel doesn't help.


Source: (StackOverflow)

Can you sign a Java applet but keep it in the sandbox (NOT give it full access to user's computer)?

Thanks to Oracle's latest changes, it appears I have to sign an applet even though I don't need or want it to have unrestricted access to the user's computer (which is why its currently unsigned). In particular, I don't want the warning they show for signed applets:

This application will run with unrestricted access which may put your computer and personal information at risk.

...which will scare the people using it.

Is it possible to sign an applet but mark it in some way to say "but keep using the sandbox"?

The only reason I'm signing it is that as of Version 7, Update 40, Oracle has further increased the nagging users have to deal with when running unsigned applets. It used to be that you could check a box saying you trusted an applet once, and that would be remembered. As of Update 40, it's only remembered for that browser session; the warning reappears if you close the browser and come back later. They've also said they're going to disable unsigned applets entirely in "a future version" of the Java plug-in.


Source: (StackOverflow)

"application blocked by security settings" prevent applets running using oracle SE 7 update 51 on firefox on Linux mint

Background

Complete fresh installation of Oracle Java SDK (32-bit) on Linux. The installation is correct, the plugin is correctly installed.

Problem

The following error ("Application Blocked by Security Settings") appears when the applet runs inside Firefox:

Mathematica graphics

Setup

Here are the steps I used:

  1. Installed Linux mint 16 on VBox: > uname -a Linux me-VirtualBox 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:12:00 UTC 2013 i686 i686 i686 GNU/Linux
  2. Cleaned all Java instances.
  3. Followed instructions to install jdk-7u51-linux-i586.tar.gz on Linux.
  4. Verified installation > java -version java version "1.7.0_51" Java(TM) SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode)
  5. Verified plugin: > pwd /home/me/.mozilla/plugins > ls -l total 0 lrwxrwxrwx 1 me me 46 Jan 22 02:42 libnpjp2.so -> /usr/lib/jvm/jdk1.7.0/jre/lib/i386/libnpjp2.so
  6. Verified Java plugin: Mathematica graphics
  7. Verified Firefox activation: Mathematica graphics Mathematica graphics
  8. Started the Java ControlPanel; set security to Medium: Mathematica graphics Mathematica graphics
  9. Clicked Apply.
  10. Restarted Firefox.

Question

How do you change the security settings to allow the applet to run?


Source: (StackOverflow)

Incompatible magic value 1008813135

I am writing a Java applet and embedding it in a web page. It used to run Mac and Windows in different browsers without problem. I was using NetBeans on the Mac to build the .jar file the applet used.

For some reason or another I decided to load the project on the Windows' NetBeans - I started getting the following error on the Windows machine when accessing the web page from any browser:

java.lang.ClassFormatError: Incompatible magic value 1008813135 in class file

Fearing that it must have been my decision to open the project on Windows that caused this error - I tried to build from the Mac's NetBeans - but the error persisted.

I started a while new project on the Mac and imported the existing source code: still same problem.

I was doing some reading about this error and it seems that the magic number expected is 0xCAFEBABE in hex which is 3405691582 in decimal, not 1008813135. So it looks like the Mac version of Java doesn't produce this file header any more? Hoe can that be? I didn't do any updates or anything.


Source: (StackOverflow)

Do beautiful, user-friendly Java applets exist? [closed]

When I use Java applets, they tend to be slow, don't integrate very well with the browser environment and often require a few click throughs ("No, I don't want to give this unsigned application free reign of my hard disk").

So, I'm curious.

Are these problems insurmountable? Are there Java applets out there which integrate well with the browser experience (in, for example, the way a well-designed Flash application does?) Can you point out any examples of really "nice" Java applets?

I'm asking this because I want to know if I should be taking a more serious look at Java-in-the-browser, or if Flash will remain dominant for the foreseeable future.

Edit: Unintentional flame bait has been removed. Sorry for any offence caused.


Source: (StackOverflow)

What does the Java Applet security warning "JAR file manifest does not contain the Permissions attribute"mean?

I have a Java Applet which needs access to the local filesystem of the client. I have created a simple certificate for my own (it is NOT certified by Verisign,Commodo, ...). I signed the jar with the following template:

del \Users\koalabruder\.keystore
"C:\Program Files\Java\jdk1.7.0_45\bin\keytool" -genkey -alias %1 -keypass kp -dname "cn=inin" -storepass ab987c
"C:\Program Files\Java\jdk1.7.0_45\bin\jarsigner.exe" -storepass abc -keypass kp %2 %1
"C:\Program Files\Java\jdk1.7.0_45\bin\keytool" -export -storepass abc -alias %1 -file %3

The simple security warning that I have "no signed certificate" has been in existence for years and is not my problem.

My problem is, that the security warning changed because one of the last Java updates:

This application will be blocked in a future Java security update because the JAR file manifest does not contain the Permissions attribute. Please contact the Publisher for more Information.

What does it mean? How can I fix it? Do I have to buy a certificate? Do I have to fix the Manifest (MANIFEST.MF)? What is the Permission attribute?

Update: Here is my Manifest from the jar file

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Application-Name: inin 
Permissions: all-permissions 
Created-By: 1.7.0_45-b18 (Oracle Corporation)

Name: net/inin/transfer/ul/UlPanel.class
SHA-256-Digest: asdfasddddddddddddddddddddddddddddddddd=

Source: (StackOverflow)

OS X 10.8 Gatekeeper and Java applets

With the new release of OS X 10.8, the Gatekeeper will popup the following warning, when you try to start a signed Java applet:

enter image description here

The applet has been signed with a valid code signing certificate and will work correctly on other platforms as well as previous versions of OS X. If I change "Allow applications downloaded from:" to "Anywhere", it works correctly.

As far as I can figure out "The digital signature could not be verified", actually means something like "the signature has not been made with a Mac Developer ID".

So: Can I sign Java applets with a Mac Developer ID? Can I sign it with both a Mac Developer ID and a standard code signing certificate? Is there a better approach?


Source: (StackOverflow)

Java unsupported major minor version 52.0 [duplicate]

This question already has an answer here:

I have had this problem for the last couple of hours where I can not launch my java application as a web applet in html (I am using html 4.01, I know it doesn't work in html5). The error message it returns is java : Unsupported major.minor version 52.0

I have tried downgrading my java jre/jdk/sdk but I still get the same error message. The current version of java I am now using is 1.8.0_05. Thank you in advance.


Source: (StackOverflow)

How do I sign a Java applet for use in a browser?

I'm trying to deploy a Java applet on my website. I also need to sign it, because I need to access the clipboard. I've followed all the signing tutorials I could find but have not had any success. Here is what I've done so far:

  • Wrote an applet in NetBeans. It runs fine in the applet viewer.
  • Made a .jar file out of it.
  • Created a certificate by doing this:
keytool -genkey -keyalg rsa -alias myKeyName
keytool -export -alias myKeyName -file myCertName.crt
  • Signed it wtih jarsigner like this:
jarsigner "C:\my path\myJar.jar" myKeyName
  • Made an html file containing this:
<html>
  <body>
<applet code="my/path/name/myApplet.class" archive="../dist/myJar.jar"/>
  </body>
</html>

When I open that html file, I never get the security confirmation dialog box (and thus get the "java.security.AccessControlException: access denied" error). This happens on all browsers.

Am I missing a step?


Source: (StackOverflow)

Java applet can't open files under Safari 7 (Mac OS X 10.9)

We have a web app that uses Java applet to manipulate files on local disk. We develop it for quite a while and we already know all types with issues an applet may have with modern OS'es and browsers and latest Java versions and new security restrictions.

Yesterday Apple rolled out its new Mac OS 10.9 Mavericks with new Safari browser (7.0). I tested our web app under Safari 7 / Mac OS X 10.9 just to find that Safari 7 (probably?) blocks access to local files from Java applet.

Although the applet (signed with valid Thawte certificate, and with all security requirements specific to Java 7u45 fulfilled) runs in unrestricted mode with full access to local file system (Java security prompt says that), on attempt to access the local file it catches fileNotFoundException:

java.io.FileNotFoundException: /Users/yury/Pictures/Paris 2012/L1050258.jpg (Operation not permitted)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:146)
    at com.trackntag.a.v.a(Unknown Source)

Also when opening Java file open dialog from the applet, it displays no files and the folders in the folder selector do not have any icons (normally they should have them). When you traverse back to the root folder, you can see top level folders (bin, cores, dev, home, and so on), but you cannot browse into them.

The applet does have an access to local files with latest Firefox 24 for Mac, on the same machine (Java 7u45, Mac OS X 10.9). Same with Safari 6 and Mac OS X 10.8.5, not to mention Linux and Windows machines in various configurations: no issues with accessing local files.

Having all of above, I must conclude that we have ran into the problem specific to Safari 7.

Do you have any ideas on this issue? Any thoughts are greatly appreciated.

Cheers, Yury

EDIT (Answer): In Safari 7 there is a new security setting: Safe/Unsafe mode (I think it's for Java plug-in only). You can allow Java plugin to work in Unsafe mode either for individual websites or for all sites. In Unsafe mode the applets will have unrestricted access to local file system.

It appears that this security setting works on top of Java's own security settings (restricted/unrestricted access).

This setting is available through Safari preferences / Security tab / Internet plugins: manage website settings (then select Java plugin).

So once I already answered my own original question, I would rather rephrase it: is that possible to set Unsafe mode or override Safe mode for specific web-site / URL without asking user to set this security preference? Maybe something like Apple developer certificate would help?

Thanks again!


Source: (StackOverflow)

How to deploy a java applet for today's browsers (applet, embed, object)?

How do i deploy a java applet for modern browsers? I know there are somehow 3 possibilities but nobody tells me which one to prefer and how to use them.

Does somebody have any resources on that? i cant find any :(


Source: (StackOverflow)