Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

command line arguments

Thread view: 
summer_haven - 14 Jul 2006 13:07 GMT
hello all..
im new to java, starting year one next year in university and going
through some questions that have been used in the past for newbies..

i need help on a command line question. basically i have written a
program (works on textpad) but wish for it to run on command prompt
(windows xp) so that i simply type:

java calculation 0 10.0 2 ... so it outputs the answer (in this case
5.0). however after attempting this, only error messages appear
(NoClassDefFoundError:calculation)

here is the code:

import java.util.Scanner;
import java.io.*;

public class Calculation {
    public static void main (String[]args)
    {
       for (int i = 0; i < args.length; i++)
           System.out.println(args[i]);

    Scanner in = new Scanner(System.in);

    System.out.println("Please Enter Velocity - in meters");
    double v = in.nextDouble();

    System.out.println("Please Enter velocity - in meters/seconds");
        double u = in.nextDouble();

    System.out.println("Please Enter Time - in seconds");
        double t = in.nextDouble();

{
        System.out.println("The acceleration is " + ((v-u)/t));
}
    }

}

thanks for any help!
Sara
Andrew Thompson - 14 Jul 2006 13:40 GMT
> hello all..
> im new to java, starting year one next year in university and going
[quoted text clipped - 5 lines]
>
> java calculation ..

Java is case sensitive, so that needs to be..

> public class Calculation {

 java Calculation

..if you are working from the directory that contains this
'default package' class, you should be able to start it with
either..
 java Calculation
..or..
 java -classpath . Calculation

The second form explicitly adds the current directory ('.')
to the classpath.

> thanks for any help!

A better group for those learning Java is comp.lang.java.help

HTH

Andrew T.
Joe - 14 Jul 2006 13:44 GMT
>[snip]
> i need help on a command line question. basically i have written a
[quoted text clipped - 12 lines]
> public class Calculation {
> [snip]

For starters, since Java is case sensitive try capitalizing Calculation
on the command line.  Also try setting the classpath argument to your
current directory (assuming you are running from the directory the
Calculation.class file is in).  This would read:

java -cp . Calculation 0 10.0 2

--Joe


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.