Having error using system properties in java

1k Views Asked by At

i'm new to java. I've been learning applets and all and i've been trying to make a simple program that uses the system class to get the properties of the machine. In simple words,i'm trying to output the windows name,its version and the architecture. I tried doing something. When i tried running it through the appletviewer,it runs but when i try running it on a server it shows some errors.What could possibly be wrong with the code? Please help,since i'm new to this. Heres the link to the applet.

http://ashish.club-tec.co.il/sysf.html

and heres the code

import java.applet.*;
import java.awt.*;


public class sysf extends Applet
{
Label l1,l2;
String p;
public void init()
{
    l1=new Label("Operating system is ");
    l2=new Label("");
    add(l2);
    add("Center",l1);

    p=System.getProperty("user.name");
    l2.setText("Hi "+p+",your system info is as follows");
    p= System.getProperty("os.name");
    l1.setText(l1.getText()+p);
    p=System.getProperty("os.version");
    p=" version "+p+" ";
    l1.setText(l1.getText()+p);
    p=System.getProperty("os.arch");
    p=" and architecture is "+p+" ";
    l1.setText(l1.getText()+p);
 }
}

Thanks!

2

There are 2 best solutions below

0
On

You'll need to set up a custom applet security policy. Here is a tutorial that covers that including setting a policy to enable user.home to be read:

http://geosim.cs.vt.edu/Java/MigModel/help/Policies.html

This sort of pain is mostly specific to Applets. Java is extremely restrictive with Applets for security reasons. If you want to learn Java, a better approach would be to learn desktop JSE or start working with servlets.

0
On

The error is that your Applet doesn't contain this class.

Somewhere in the packaging of your Applet, you either forgot to include this class, or didn't update the web link to the Applet to refer to this class.

As an aside, it's generally good from to capitalize classes.

Error output follows

load: class sysf.class not found.
java.lang.ClassNotFoundException: sysf.class
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassNotFoundException: sysf.class