Running a Simple Java Program in Windows 7

Hello:
Learning Java.
I have Windows 7 64 bit. I have following Java installed:
C:\Program Files\Java\jdk1.6.0_21\demo>java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b17, mixed mode)
My path is as follows:
C:\Program Files\Java\jdk1.6.0_21\demo>path
PATH= C:\Program Files\Java\jdk1.6.0_21\bin;C:\Windows\system32;C:\Windows;C:\Wi
ndows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files
(x86)\QuickTime\QTSystem\
When I try to run a program called Exampleprogram.java as follows, I see below error:
C:\Program Files\Java\jdk1.6.0_21\demo>java exampleprogram.java
Exception in thread "main" java.lang.NoClassDefFoundError: exampleprogram/java
Caused by: java.lang.ClassNotFoundException: exampleprogram.java
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: exampleprogram.java. Program will exit.
C:\Program Files\Java\jdk1.6.0_21\demo>
Will appreciate your early help. Thanks.
Victor

Recomplied and still no luck. I gave a different name to the program and still getting the same error as follows:
C:\Program Files\Java\jdk1.6.0_21\bin>dir hel*
Volume in drive C is WINDOWS7PRO
Volume Serial Number is EB0E-8900
Directory of C:\Program Files\Java\jdk1.6.0_21\bin
10/03/2010 11:29 AM 269 helloworld.java
10/03/2010 11:33 AM 429 HelloWorldApp.class
2 File(s) 698 bytes
0 Dir(s) 123,998,978,048 bytes free
C:\Program Files\Java\jdk1.6.0_21\bin>java helloworld.java
Exception in thread "main" java.lang.NoClassDefFoundError: helloworld/java
Caused by: java.lang.ClassNotFoundException: helloworld.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: helloworld.java. Program will exit.
C:\Program Files\Java\jdk1.6.0_21\bin>
Thoughts please.

Similar Messages

  • How to run the simple java card program in eclipse?

    I am trying to run a simple HelloWorld program in eclipse 3.5 having java card development kit 2.2 installed in it.
    Firstly,I go to the JCWDE tab and press start..then when trying to deploy that package its giving me error like " com.hw.HelloWorld: unsupported class file format of version 50.0." can any one help me in this what is this error???n how to resolve n run this program..

    Hi,
    It is because the converter works on byte code and it only supports a subset of the Java language (see the JC specifications). It is kind of like compiling you code on Java 6 and trying to run it on Java 5. The JCDK outlines the required compiler version.
    Cheers,
    Shane

  • How to run a java program in windows 2003 server from unix server.

    Hi ,
    I want to run a java program in windows 2003 server from unix machine ..
    will RMI helps me to obtain this.
    Please tell me the procedure to do this.
    Thanks in advance,

    rmi,web services,corba,web 2.0,xml,xls,dtd,rss,ruby on rails,https,soap,tags,blog,podcast,google

  • I want to run java program on windows environment as background process

    Hi all
    I want to run java program on windows environment as background processSo command prompt return after executing java command and program on background In Linux we can do this easily �but I do not how to do this in windows
    for example look this programe
    import java.io.*;
    import java.util.*;
    public class TestClass {
         class ravi extends Thread{
              public void run(){
                   try {    
                        String target_file = "ravind.txt";
                        File targetfile = new File(target_file);
                        PrintWriter writer = new PrintWriter(new FileWriter(targetfile)) ;
                   for (int i =0 ; i < 100 ;i++ ){
                        Thread.sleep(10000);
                        writer.println(" ravindra shukla ");
              } catch (Exception e) {               
                             e.printStackTrace();
         public static void main(String[] args) {
              TestClass test1 = new TestClass();
              TestClass.ravi r1 = test1.new ravi();
              r1.start();          
    System.out.println(" return from main ");
    first i compile this
    javac TestClass.java
    then i run this by using this command
    java TestClass
    but becouse i put sleep on threads run function so it takes to much time to get return on command promt .... i want to run this programe as background process so command promt return as soon as i execute java command

    Thanks dude
    This solution �start java TestClass� works fine �. But it does not solve my problem
    It opens another black window and that black window persist till the life time of my program
    Is it possible application run on complete background without opening another black window �as in Linux

  • Problem while executing simple java program

    Hi
    while trying to execute a simple java program,i am getting the following exception...
    please help me in this
    java program :import java.util.*;
    import java.util.logging.*;
    public class Jump implements Runnable{
        Hashtable activeQueues = new Hashtable();
        String dbURL, dbuser, dbpasswd, loggerDir;   
        int idleSleep;
        static Logger logger = Logger.getAnonymousLogger();      
        Thread myThread = null;
        JumpQueueManager manager = null;
        private final static String VERSION = "2.92";
          public Jump(String jdbcURL, String user, String pwd, int idleSleep, String logDir) {
            dbURL = jdbcURL;
            dbuser = user;
            dbpasswd = pwd;
            this.idleSleep = idleSleep;
            manager = new JumpQueueManager(dbURL, dbuser, dbpasswd);
            loggerDir = logDir;
            //preparing logger
            prepareLogger();
          private void prepareLogger(){      
            Handler hndl = new pl.com.sony.utils.SimpleLoggerHandler();
            try{
                String logFilePattern = loggerDir + java.io.File.separator + "jumplog%g.log";
                Handler filehndl = new java.util.logging.FileHandler(logFilePattern, JumpConstants.MAX_LOG_SIZE, JumpConstants.MAX_LOG_FILE_NUM);
                filehndl.setEncoding("UTF-8");
                filehndl.setLevel(Level.INFO);
                logger.addHandler(filehndl);
            catch(Exception e){
            logger.setLevel(Level.ALL);
            logger.setUseParentHandlers(false);
            logger.addHandler(hndl);
            logger.setLevel(Level.FINE);
            logger.info("LOGGING FACILITY IS READY !");
          private void processTask(QueueTask task){
            JumpProcessor proc = JumpProcessorGenerator.getProcessor(task);       
            if(proc==null){
                logger.severe("Unknown task type: " + task.getType());           
                return;
            proc.setJumpThread(myThread);
            proc.setLogger(logger);       
            proc.setJumpRef(this);
            task.setProcStart(new java.util.Date());
            setExecution(task, true);       
            new Thread(proc).start();       
         private void processQueue(){       
            //Endles loop for processing tasks from queue       
            QueueTask task = null;
            while(true){
                    try{
                        //null argument means: take first free, no matters which queue
                        do{
                            task = manager.getTask(activeQueues);
                            if(task!=null)
                                processTask(task);               
                        while(task!=null);
                    catch(Exception e){
                        logger.severe(e.getMessage());
                logger.fine("-------->Sleeping for " + idleSleep + " minutes...hzzzzzz (Active queues:"+ activeQueues.size()+")");
                try{
                    if(!myThread.interrupted())
                        myThread.sleep(60*1000*idleSleep);
                catch(InterruptedException e){
                    logger.fine("-------->Wakeing up !!!");
            }//while       
        public void setMyThread(Thread t){
            myThread = t;
        /** This method is only used to start Jump as a separate thread this is
         *usefull to allow jump to access its own thread to sleep wait and synchronize
         *If you just start ProcessQueue from main method it is not possible to
         *use methods like Thread.sleep becouse object is not owner of current thread.
        public void run() {
            processQueue();
        /** This is just another facade to hide database access from another classes*/
        public void updateOraTaskStatus(QueueTask task, boolean success){
            try{         
                manager.updateOraTaskStatus(task, success);
            catch(Exception e){
                logger.severe("Cannot update status of task table for task:" + task.getID() +  "\nReason: " + e.getMessage());       
        /** This is facade to JumpQueueManager method with same name to hide
         *existance of database and SQLExceptions from processor classes
         *Processor class calls this method to execute stored proc and it doesn't
         *take care about any SQL related issues including exceptions
        public void executeStoredProc(String proc) throws Exception{
            try{
                manager.executeStoredProc(proc);
            catch(Exception e){
                //logger.severe("Cannot execute stored procedure:"+ proc + "\nReason: " + e.getMessage());       
                throw e;
         *This method is only to hide QueueManager object from access from JumpProcessors
         *It handles exceptions and datbase connecting/disconnecting and is called from
         *JumpProceesor thread.
        public  void updateTaskStatus(int taskID, int status){       
            try{
                manager.updateTaskStatus(taskID, status);
            catch(Exception e){
                logger.severe("Cannot update status of task: " + taskID + " to " + status + "\nReason: " + e.getMessage());
        public java.sql.Connection getDBConnection(){
            try{
                return manager.getNewConnection();
            catch(Exception e){
                logger.severe("Cannot acquire new database connection: " + e.getMessage());
                return null;
        protected synchronized void setExecution(QueueTask task, boolean active){
            if(active){
                activeQueues.put(new Integer(task.getQueueNum()), JumpConstants.TH_STAT_BUSY);
            else{
                activeQueues.remove(new Integer(task.getQueueNum()));
        public static void main(String[] args){
                 try{
             System.out.println("The length-->"+args.length);
            System.out.println("It's " + new java.util.Date() + " now, have a good time.");
            if(args.length<5){
                System.out.println("More parameters needed:");
                System.out.println("1 - JDBC strign, 2 - DB User, 3 - DB Password, 4 - sleeping time (minutes), 5 - log file dir");
                return;
            Jump jump = new Jump(args[0], args[1], args[2], Integer.parseInt(args[3]), args[4]);
            Thread t1= new Thread(jump);
            jump.setMyThread(t1);      
            t1.start();}
                 catch(Exception e){
                      e.printStackTrace();
    } The exception i am getting is
    java.lang.NoClassDefFoundError: jdbc:oracle:thin:@localhost:1521:xe
    Exception in thread "main" ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
    JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [../../../src/share/back/util.c:820] Please help me.....
    Thanks in advance.....sathya

    I am not willing to wade through the code, but this portion makes me conjecture your using an Oracle connect string instead of a class name.
    java.lang.NoClassDefFoundError: jdbc:oracle:thin:@localhost:1521:xe

  • How to start java.exe from a java program in windows ?

    Hi,
    I did like to know, if its possible to run java.exe from a java program on windows ? The java.exe should be visible from checking the processes that are currently running using the Task Manager on windows.

    Runtime.getRuntime().exec("java Sample");

  • Opening a Word Document with a Java program in Windows

    When running a Java program in Windows, is it possible to have a button where when it is clicked it will open a Word document?
    If so, is it hard and can someone tell me how to do it??
    Thanks

    try this instead of Excel.exe you have to use Word.exe
    1. Declare your button
                   JButton butexlcom = new JButton("Carnet Offre");
                   butexlcom.addActionListener( new ButExlCommercial(msgout));
                   butexlcom.setBounds(215,510,110,30);
                   c.add( butexlcom );
    2. run your word document.
    class ButExlCommercial implements ActionListener {
         private JTextArea msgout;
         public ButExlCommercial( JTextArea msg) {
         msgout = msg;
         public void actionPerformed( ActionEvent e ) {
              try {
                   Runtime.getRuntime().exec("c:\\Program Files\\Microsoft Office\\Office\\Excel.exe NameWordDocument");
              catch(Exception en) {
                   msgout.append( "\n*** PROBLEME WORD ***\n" );
    }

  • A simple Java program to be compiled with ojc and executed with java.exe

    Hi ,
    This thread is relevant to Oracle Java Compiler (file ojc) and jave.exe file.
    I have written a simple java program which consists of two simple simple classes and using the JDev's 10.1.3.2 ojc and java files , i'm trying to execute it after the successful compilation....
    The problem is that trying to run it... the error :
    Exception in thread "main" java.lang.NoClassDefFoundError: EmployeeTest
    appears.
    How can i solve this problem...????
    The program is as follows:
    import java.util.*;
    import corejava.*;
    public class EmployeeTest
    {  public static void main(String[] args)
       {  Employee[] staff = new Employee[3];
          staff[0] = new Employee("Harry Hacker", 35000,
             new Day(1989,10,1));
          staff[1] = new Employee("Carl Cracker", 75000,
             new Day(1987,12,15));
          staff[2] = new Employee("Tony Tester", 38000,
             new Day(1990,3,15));
          int i;
          for (i = 0; i < 3; i++) staff.raiseSalary(5);
    for (i = 0; i < 3; i++) staff[i].print();
    class Employee
    {  public Employee(String n, double s, Day d)
    {  name = n;
    salary = s;
    hireDay = d;
    public void print()
    {  System.out.println(name + "...." + salary + "...."
    + hireYear());
    public void raiseSalary(double byPercent)
    {  salary *= 1 + byPercent / 100;
    public int hireYear()
    {  return hireDay.getYear();
    private String name;
    private double salary;
    private Day hireDay;
    For compilation... i use :
    D:\ORACLE_UNZIPPED\JDeveloper_10.1.3.2\jdev\bin\ojc -classpath D:\E-Book\Java\Sun_Java_Book_I\Corejava EmployeeTest.java
    For execution , i issue the command:
    D:\ORACLE_UNZIPPED\JDeveloper_10.1.3.2\jdk\bin\java EmployeeTest
    NOTE:I tried to use the jdk of Oracle database v.2 but the error :
    Unable to initialize JVM appeared....
    Thanks , a lot
    Simon

    Hi,
    Thanks god....
    I found a solution without using Jdev.....
    C:\oracle_files\Java\Examples>SET CLASSPATH=.;D:\E-Book\Java\Sun_Java_Book_I\Corejava
    C:\oracle_files\Java\Examples>D:\ORACLE_UNZIPPED\JDeveloper_10.1.3.2\jdk\bin\javac EmployeeTest.java
    C:\oracle_files\Java\Examples>D:\ORACLE_UNZIPPED\JDeveloper_10.1.3.2\jdk\bin\java EmployeeTest
    What does Ant has to do with this?Sorry, under the Ant tree a classpath label is found....I'm very new to Java and JDev...
    You need to include the jar file that has the Day method in it inside project properties->libraries.I have not .jar file.. just some .java files under the corejava directory.... By the way , I have inserted the corejava directory to the project pressing the button Add Jar/Directory.... , but the problem insists..
    Thanks , a lot
    Simon

  • How to read system eventlog using java program in windows?

    How to read system eventlog using java program in windows?
    is there any java class available to do this ? or any one having sample code for this?
    Your friend Zoe

    Hi,
    There is no java class for reading event log in windows, so we can do one thing we can use windows system 32 VBS script to read the system log .
    The output of this command can be read using java program....
    we can use java exec for executing this system32 vbs script.
    use the below program and pass the command "eventquery"
    plz refer cscript,wscript
    import java.io.*;
    public class CmdExec {
    public static void main(String argv[]) {
    try {
    String line;
    Process p = Runtime.getRuntime().exec("Command");
    BufferedReader input =
    new BufferedReader
    (new InputStreamReader(p.getInputStream()));
    while ((line = input.readLine()) != null) {
    System.out.println(line);
    input.close();
    catch (Exception err) {
    err.printStackTrace();
    This sample program will list all the system log information....
    Zoe

  • How to read system evenlog using java program in windows

    How to read system evenlog using java program in windows???
    is there any java class available to do this ? or any one having sample code for this?
    Your friend Zoe

    Welcome to the Sun forums.
    >
    How to read system evenlog using java program in windows???>
    JNI. (No.)
    >
    is there any java class available to do this ? or any one having sample code for this?>You will generally get better help around here if you read the documentation, try some sample code and come back with a specific question (hopefully with an SSCCE included).
    >
    Your friend Zoe>(raised eyebrow) Thank you for sharing that with us.
    Note also that one '?' denotes a question, while 2 or more generally denotes a dweeb.

  • Problem in running a simple html program in netbeans 5.5.1

    Dear all
    when i am running a simple html program in netbeans 5.5.1, it is not showing the result. In url address is showing defferent. such as
    http://localhost 8084/... while i need http://mydocument and setting/...
    so i want to set the default address. from where shound i set it, so that in url address should come right.
    thanks
    From
    Rajeev Sarawat

    Hi cliff,
    Worked as per ur Suggestion , the .tld file had
    <!DOCTYPE taglib tag, I removed it, it is still not working , I m using tomcat 3.2
    I tried to run the simpletag example given with Tomcat it runs, but when I copied that example to my webapps/TagViews direcotry and corrected the package and made necessary changes in web.xml kept in
    WEB-INF direcotry , it gives the same error,
    Is there any requirement to make a war file for taglib to run or some thing like that, or is there any other requirement after making
    1) The .class file kept in install_dir/webapps/TagViews/WEB-INF/classes/Tagbeans
    2) The .tld file kept in
    install_dir/webapps/TagViews/WEB-INF/jsp/
    3) Made cahnges in web.xml kept in
    install_dir/webapps/TagViews/WEB-INF/
    4) Made the jsp file kept in
    install_dir/webapps/TagViews/jsp/
    After doing this I restarted the tomcat server and then tried http://localhost:8080/TagViews/jsp/myTag.jsp

  • I'm not able to run a simple Hello Program in java

    I have just now installed jdk 1.3.1_2.
    I have set the path and class path.
    I'm able to compile the class without any errors but am not able to run the program.
    when i say java Hello(after compiling Hello.java), i'm seeing the following error:
    Exception in thread "main" java.lang.NoclassDefFoundError:Hello
    Thanks in advance in this regard

    Hmm..
    Okay.. set aside any import or package stuffs.. lets say about a simple HelloWorld program which is called Hello.class. It resides in c:\, which means the full path is c:\Hello.class.
    Make sure you got one of your path as c:\jdk1.3\bin(assuming you are using jdk 1.3).
    If you are in the same directory as Hello.class, which is c:\>, you can execute the class file by typing:
    C:\>java Hello
    If you are not in the same directory and you wishes to run the class file, example you are in directory temp now:
    C:\Temp>java -cp C:\ Hello
    So the cp set will be just c:\. Hope that answers your question somehow.. well... if I never intepret it wrongly.

  • To run a java program on windows xp startup

    hi ,
    i have a sample HelloWorld.java program.
    i wrote a batch file to run this program as follows:
    set PATH=%PATH%;C:\Program Files\Java\jre1.6.0\bin;
    cd c:\test
    java HelloWorld
    This program runs when i click on the bat file.
    Next i add this batch file to registry to auto-start on windows startup
    However, on windows startup, i get the following:
    Exception in thread "main" java.lang.NoClassDefFoundError
    Anyone can help me? Thank you in advance!

    Hi Sergi,
    Thanks for the info. I couldn't able to login because of my internet connection.
    Thanks,
    --Srini                                                                                                                                                                                                                           

  • Can I run my java program in windows environment?

    How can i make my compiled java program run into windows environment?
    What program will i use to be able to do that?

    1. Install the JRE.
    2. Go to the command line.
    3. Type something like java myClass or java -jar myJar.jar.
    You could also use one of the many java2exe (java to executable) programs floating out there.

  • Run simple java program error

    Hi:
    I followed the step by step at "Your First Cup of Java (for Microsoft Windows)" at
    http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html#
    all the steps work, esecpt for the run program part, I get Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp. but the HelloWorldApp clases is there. and I set my path and classes path at xp enviroment
    classes %CATALINA_HOME%\common\lib\servlet.jar;c:\jdom-b8\build\jdom.jar;c:\jdom-b8\lib\xerces.jar; Library.java;c:\hsqldb\lib\hsqldb.jar
    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;c:\jdk1.4.0_02\bin; %path%
    hope you can help !
    Thank you

    The problem with running the HelloWorldApp is because you have set the classpath.
    It looks like Tomcat and others are installed on your system. Trying to run before you can walk, eh!
    This is your system CLASSPATH and points to directories that contain classes and/or *.jar files that contain classes:
    .;%CATALINA_HOME%\common\lib\servlet.jar;c:\jdom-b8\build\jdom.jar;c:\jdom-b8\lib\xerces.jar;c:\hsqldb\lib\hsqldb.jar
    I don't know why Libary.java is there in your original post because it is a source file and not a class yet; and you don't point directly at a class, only the folder or JAR it is in.
    This is your system PATH and points to directories that contain programs:
    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;c:\jdk1.4.0_02\bin;
    With XP the environment is split into two parts:
    1/ the system environment variables and will prepend to:
    2/ your user environment variables may have the same name and will append to variables in 1/. So there is no need for the %path% bit.
    Make sure that CATALINA_HOME is set to the base folder of the CATALINA(TOMCAT) installation, if you are planning to use it.
    You shouldn't need to set PATH or CLASSPATH for your user ID unless you only want that user id to have access.
    My advice (if it is your machine) is to uninstall Apache/Tomcat and anything else (such as JDOM) that isn't basic Java until you have learned the language. Then delete the CLASSPATH variable and remove the \system32\WBEM; part of the the PATH variable.
    Regards,
    Hugh.

Maybe you are looking for

  • Bridge CS2: Scripting metadata w/o XMPScript?

    Hi, I need to get at strcutured data types (bag and alt) and I can't figure out how to do this in CS2, or if it's even possible. I've looked at the sample code in the scripting guide, but it doesn't seem to be of use. Here's what I've tried so far to

  • The User Name in Mavericks Mail mail preferences Not Correctible

    Hi all, The User Name in Mavericks Mail mail preferences is incorrect for one of my accounts, so the account won't function.  It keeps asked for the password.  When I change it to the correct User Name and go to the account, the entry automatically s

  • Should be a simple question...

    Hi, When searching in Mac how what are wildcards? For instance I'm using the search tool to search for all files that are greater than 100Mb. I've clicked the plus button and put the file size criteria in, however I can't make it search for all files

  • EMERGENCY: Full Screen AIR App

    I have a player that I need to have run full screen. It works fine on my Windows box when I use .width = Screen.screens[0].bounds.width and the same for height, but when I go over to a mac, I have the Apple command bar perfectly visible, and it does

  • My Photoshop Elements 9.0.3 will not crop photos as it did in the past. When I use the crop tool, th

    My Photoshop Elements 9.0.3 will not crop photos as it did in the past. When I use the crop tool, the photo is changed to the size of a dot and is unrecognizable. Can this be fixed?