Trying to get my first java program compile.

I just iinstalled j2sdk1.4.2_05 on Wind 98 and I have set the path variable in autoexec.bat and ran the .bat.
So, now the system recognizes the javac compiler but I am still not able to run a program Welcome.java
I created a Welcome.java file and stored it in C:\java\Welcome.java
I also set the sourcepath to sourcepath=c:\java; in my autoexec.bat file.
When I compile the following way, I get the following error:
c:\javac Welcome.java
Error: Cannot read: Welcome.java
Can anybody please tell me what I am doing wrong. Do i need to set any thing else.
Radhika.

I got it to compile and run....successfully.
Problem was- When I created the file Welcome.java in Notepad, it created with the following extension-
Welcome.java.txt. I renamed it to Welcome.java and it compiled and ran fine.
Thanks,
Radhika.

Similar Messages

  • Trying to compile my first Java program !

    Hi,
    I am a new programmer.Looking to clarify a very simple doubt while compiling my first java program.
    I have set up jdk in the following directory on my PC , E:\j2sdk1.4.1_01\bin.
    Now when I create the first AClass.java file in the AClass directory under bin and try and compile it I get the following error.
    E:\j2sdk1.4.1_01\bin>java E:\j2sdk1.4.1_01\bin\AClass\AClass
    Exception in thread main
    java.lang.NoClassDefFoundError: E:\j2sdk1/4/1_01\bin\AClass\AClass
    Kindly help me how to fix this.

    hi,
    Just do this,
    set path & classpath either in the system environment veriable or in the command prompt as shown below.
    set PATH=%PATH%;E:\j2sdk1.4.1_01\bin
    set CLASSPATH=%CLASSPATH%;.
    Be careful, there is a trailing DOT (.) at the end of the classpath, and that is what needed for
    the JVM to find the class file. with this you would be able to run your program. Infact JDK1.4.x and higher
    doesn't requires classpath to be set, your system classpath variable needs a DOT (.)
    at the end of the classpath variable defined in the environment variable section of your computer or
    in the command prompt you need it to set it once for the current command prompt window before
    executing any java program.
    Regards
    Goodieguy

  • My first java program!! ALMOST done..I hope

    I've just written my first java program (part of a class I'm taking).. It's feeling kinda awkward since I'm a C++ programmer.. I've written most of the code but I'm still having problems and I thought I should show it to you to get some help..
    import java.lang.*;
    import java.util.*;
    public class Dice
    private static Random generator = new Random();
    int Die1, Die2, rolled, pairNum, pairSum;
    public Dice()
       int[] Dice_arr={Die1, Die2};
       new Random(System.currentTimeMillis());
       return;
      }//end_func_Dice
       public static roll()
         rolled = generator.nextInt(6) + 1;
         return rolled;
        }//end_func_roll
       public String toString()
         StringBuffer bfr = new StringBuffer("\n");
         System.out.println("Rolling Dice...");
          for(pairNum=0; pairNum==10; pairNum++)
            System.out.println("Pair"+pairNum+": "+Die1+","+Die2+" Sum= "+pairSum);
           }//end_for_
        }//end_func_ 
    }//end_class_Dice
    public static void main(String args[])
          for (int dieNum=0; dieNum==2; dieNum++)
            Dice.roll();
            Dice_arr[dieNum]=rolled;
           }//end_for_
         return;
        }//end_func_mainI need main to instatiate the Dice class and then use the toString to print the dice numbers and their sum 10 times..
    I hope this doesn't need much effort,
    Thanks a bunch in advance..

    Right now, my opinion in java is that it's too
    complicated for no reason compared to C++..It's not too complicated, it's just that you are new at this.
    Here's a little example of a simple class with a simple main method, the rest figure it out yourself, and with time read some java books, you won't learn java just by knowing C++.
    public class Human {
        // See this as C constants (although they're not their Equivalent)
        public static boolean MALE = true;
        public static boolean FEMALE = false;
        //member variables.
        private String name;
        private boolean sex;
        /** Creates a new instance of Human */
        public Human(String n, boolean s) {
            name = n;
            sex = s;
        }//End of CONSTRUCTOR.
        public String getName() {
            return name;
        }//End of getName
        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append("[Name: " + name);
            if(sex)
                sb.append(", sex: Male]");
            else
                sb.append(",sex: Female]");
            String returnValue = new String(sb);
            return returnValue;
        }//End of toString()
        //Just the main program, it could be at another class.
        public static void main(String[] args) {
            Human h = new Human("Pablo", Human.MALE);
            String theHumanAsAString = h.toString();
            System.out.println(theHumanAsAString);
        }//End of main method
    }//End of class

  • Error Message when running first java program

    Hi,
    I am reading "Sams Teach Yourself Java 6 in 21 Days" by Rogers Cadenhead. I am having a problem with compiling the sample program in the first part of the book, "HelloUser" which is supposed to print out "Hello (my name - Matt)" when run in the command line.
    I receive this error when trying to run it after having successfully compiled it (I enter java HelloUser while in correct folder):
    Exception in thread "main" java.lang.NoSuchMethodError: main
    I have correctly set the PATH and CLASSPATH settings for my PC (Windows XP). I am guessing that I need to define a "main" or something. I'm brand new to Java but am good with the scripting language PHP. Please tell me what I should do to correct this problem. Thanks in advance

    Here is the code for the program:
    public class HelloUser {
         public static void man(String[] arguments) {
              String username = System.getProperty("user.name");
              System.out.println("Hello " + username);
    }Here is what I enter in the Command Line:
    cd \JavaWork\j21work
    javac HelloUser.java
    java HelloUser
    There are no problems up until I enter the last line (java HelloUser) to run the program. By the way, I using JDK 6 update 1 with Windows XP.

  • Error when trying to run my first Java app

    Okay, Im new to Java programming. I started a day ago :). My question is after I compile my application like so.
    javac TestGreeting.javaIt give me a .class file. So the next step is I want to run it so I do the following.
    java TestGreeting.classWhen I run this I get this error:
    Exception in thread "main" java.lang.NoClassDefFoundError: TestGreeting/classCan some one tell me what is going on? I am running Mac OSX Leopard on a MBP. I have the latest Xcode Tools which is 3.1 if I am not mistaken.
    Thanks everyone. Go easy on a newbie :)

    The argument for the java command is the fully qualified Class Name. It is not a file name or path. You provided a file name. The JVM tried to find a class named 'class' in a package named TestGreeting. Most likely, you should have typed "java TestGreeting"
    Here is a link to a tutorial, and the Getting Started section includes a section for problem resolution.
    [http://java.sun.com/docs/books/tutorial/]

  • Getting that first java job

    Could anyone give some tips for going from graduate (BSc Comp Sci) to getting first java job? A lot of employeers want 'experience' but when you've just graduated you've only ever worked on uni assignments and not industrial ones. How do you crack this?
    Does certification impress anyone other than recruitment consultants?
    Is it a good idea to put together online portfolio of all work you've done?
    thanks

    Could anyone give some tips for going from graduate
    (BSc Comp Sci) to getting first java job? A lot of
    employeers want 'experience' but when you've just
    graduated you've only ever worked on uni assignments
    and not industrial ones. How do you crack this?
    Don't stare blindly at those numbers. Everyone says "experience preferred" and they mean it. Expect to have to take a lower starting salary than the stated one and don't write on jobs asking for more than a few years experience as those will be way over your head most likely.
    Otherwise, persevere or move to India (they seem to hire anyone who can spell the word 'computer' there).
    Does certification impress anyone other than
    recruitment consultants?
    Depends on the certification but in general yes.
    It impresses not the recruitment consultants but the non-technical people they're selling you to.
    Anyone with a grain of knowledge about certs will know that most if not all are completely useless without practical experience to back them up (and some worse than useless, think MCSE NT4 which was a disaster).
    Is it a good idea to put together online portfolio of
    all work you've done?
    Can't hurt, if it's relevant. I'd not put in time spent making levels for Doom unless you're trying for the games industry though (just an example).
    thanks

  • My first java programming - Need some help please!!!

    I have to create a simple java program which i am not good at i am ok in C but my java is quite bad. The program need to define a class called Student and with a string called StudentNAme, a integer StudentID(key), An array of 8 integers called Marks that holds the students marks for 8 modules. It also says Include appropriate accessors, mutators and constructor(s) as well as a method to update the student�s marks. Anybody please help me in this question. I prefer an simple example of this program so I can learn faster, I dont even know how to declare a class.. So sorry but please help me out and thanks in advance

    I would also suggest you try using an IDE like
    eclipse (free)
    www.eclipse.org
    This will help you get a working program much faster.But please do also tell them that if they have troubles using it, they're supposed to read the IDE manual instead of posting here.

  • My first java program. Design improvements?

    Hello all,
    I'm new to this forum (just joined today) so hi! I've been learning java for the last few months by reading a few books, and finally decided to take a crack at my first program (beyond hello world). This one is windows only. At work with a co worker we found that in windows 2000 the background images could get out of sync, so this program gives the user an alternative way to set the backgrounds.
    What I'm asking is if anyone has any time to kill and enjoys reading source code to take a look at it for me. If you see any issues with how the program was implemented and could be improved please let me know.
    Here's the link to the src: http://will.willandnikki.com/projects/bgchanger/BGChanger_src.zip
    Here's a link to my jar:
    http://will.willandnikki.com/projects/bgchanger/BGChanger.jar
    Thanks,
    Will

    Right now, my opinion in java is that it's too
    complicated for no reason compared to C++..It's not too complicated, it's just that you are new at this.
    Here's a little example of a simple class with a simple main method, the rest figure it out yourself, and with time read some java books, you won't learn java just by knowing C++.
    public class Human {
        // See this as C constants (although they're not their Equivalent)
        public static boolean MALE = true;
        public static boolean FEMALE = false;
        //member variables.
        private String name;
        private boolean sex;
        /** Creates a new instance of Human */
        public Human(String n, boolean s) {
            name = n;
            sex = s;
        }//End of CONSTRUCTOR.
        public String getName() {
            return name;
        }//End of getName
        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append("[Name: " + name);
            if(sex)
                sb.append(", sex: Male]");
            else
                sb.append(",sex: Female]");
            String returnValue = new String(sb);
            return returnValue;
        }//End of toString()
        //Just the main program, it could be at another class.
        public static void main(String[] args) {
            Human h = new Human("Pablo", Human.MALE);
            String theHumanAsAString = h.toString();
            System.out.println(theHumanAsAString);
        }//End of main method
    }//End of class

  • My first Java program does;'t work HELP

    I received the following message in the Command Prompt:Exception in thread "main" java.land.NoClassDefFoundError: Test
    How do I fix this?
    Source Code:
    import java.awt.MediaTracker;
    class Test {
    public static void main(String[] args) {
    for (int i = 0; i < args.length; i++)
    System.out.print(i == 0 ? args[i] : " " + args);
    System.out.println();

    You might want to make your class public, although I don't think that's supposed to be necessary. It's most likely a classpath issue.
    Instead of java Test, try java -cp . Test (Note the dot between -cp and Test.)
    Javapedia: Classpath
    How Classes are Found
    Setting the class path (Windows)
    Setting the class path (Solaris/Linux)
    Understanding the Java ClassLoader
    java -cp .;<any other directories or jars> YourClassNameYou get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
    javac -classpath .;<any additional jar files or directories> YourClassName.javaYou get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

  • Java program compiles but failes to run

    WHAT IS WRONG WITH THIS PROGRAM? It compiles;
    however, when I try to run it, I get the message"
    static void main not define in class car. Please help!
    class Car {
    int passanger;
    int mpg;
    int gas;
    void range() {
    System.out.println("Distance of =:" + mpg*gas);
    class Models {
    public static void main(String args[]) {
    Car Toyata=new Car();
    Car Mazada=new Car();
    Toyata.passanger=8;
    Mazada.passanger=6;
    Toyata.mpg=30;
    Mazada.mpg=25;
    Toyata.gas=16;
    Mazada.gas=17;
    System.out.println("Toyata can carry" +Toyata.passanger);
    Toyata.range();

    The program gets compiled into two classes: Car.class & Models.class.
    class Car {
    int passanger;
    int mpg;
    int gas;
    void range() {
    System.out.println("Distance of =:" + mpg*gas);
    class Models {
    public static void main(String args[]) {
    Car Toyata=new Car();
    Car Mazada=new Car();
    Toyata.passanger=8;
    Mazada.passanger=6;
    Toyata.mpg=30;
    Mazada.mpg=25;
    Toyata.gas=16;
    Mazada.gas=17;
    System.out.println("Toyata can carry" +Toyata.passanger);
    Toyata.range();
    java Car does not produce output because the main method is in the Models.class.
    java Modelsproduces output
    Toyaota can carry 8
    Distance of :=480

  • Java program Compiling using Maven

    Hi,
    I am upgrading 1.4 to 1.5 java. And in my local pc i have compiled programs and able to eploy the application. But the problem is in server when i try to compile using maven it gives a compilation error.
    If you are saying that it is an issue of maven then also i wanted to discuss this strange issue here.
    /usr/build/Application/java/com/sql/DataStoreInterface.java:686: warning: unmappable character for encoding UTF8
        [javac] �* Inserts a blank row at the specified position of the DataStore's result set buffer. Returns the number of the row added.The statement is commented but the compiler is not identified the same. When i checked encoding type using file --mime {filename} i got it like text/x-java; charset=iso-8859-1. This is not the case for all some java file types are text/x-c++; charset=us-ascii but that is not giving error.
    One more issue is elicited below.
    ] cast to java.lang.Object for a varargs call
        [javac] cast to java.lang.Object[] for a non-varargs call and to suppress this warning
        [javac]                     meth.invoke(comp, n);
        [javac]                                       ^Can any one suggest how can i solve this two issues.
    Thanks
    Rasa.

    rasa wrote:
    Hi,
    I am upgrading 1.4 to 1.5 java. And in my local pc i have compiled programs and able to eploy the application. But the problem is in server when i try to compile using maven it gives a compilation error.
    If you are saying that it is an issue of maven then also i wanted to discuss this strange issue here.
    /usr/build/Application/java/com/sql/DataStoreInterface.java:686: warning: unmappable character for encoding UTF8
    [javac] � ...� above might be a broken copyright #) symbol. In java code comments, I'd replace it with word *(copyright)*
    #) broken copyright symbol -- I've seen it broken that way in one project. I remembered this because one of colleagues made a funny remark on it. There was something like:
    ...it's not a bug, these are sacral signs with a very special meaning.
    Let me explain:
    - i with two dots means we spotted all i's and some more
    - reverted question sign means there are no questions left anymore
    - "1/2" is a math symbol for square root meaning we've got to the roots of the Universe with our product

  • Programming your first java program, hello world

    go here and do it quick and fun;
    http://www.geocities.com/jon_riley/jon/java.htm

    It is not visual, the same may we learned programming in class.I disagree. The tutorial may not have as big pictures as you have but it sure is visual:
    http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html
    Besides getting the thing done, it explains the common errors you could get, and applies to winNT and 2k (ME, anyone?) as well as win9x. Can you give any reason I should from now on recommend people using 32bit windoze to go to your page rather than the tutorial page?
    By the way, who learned programming in class?

  • First Java Programming Assignment - Grad student needs Help

    Thank-you to whomever helps me out here (I have been waiting for the Professor to respond for 2 days now, and our asignment is due by midnight 2-nite. Here is my problem. We have a value called nPer. This value is defined as a double (it needs to since, it perfoms lots of calculations). Now the assigment calls for the print line to display the field in its integer format. So I have done the following:
    nPer=Math.ceil(nPer);
    This has caused the value to be represented as 181.0. Not good enough! The value needs to be truncated and represented as 181.
    The professor has provided us with directions that use the following syntax
    (int)181.0
    Putting that exact code in my program causes JBuilder to create an error message. Ergo, its not right. I have serached all over the tutorial looking for the proper method to resolve this, however - no luck. Could some kind sole please help??? Thank-you.

    You can look at either java.math.BigDecimal, if the
    true representation of the value and rounding are a
    concern, or java.text.NumberFormat if it's simply a
    matter of display.
    Your professor must be an old C programmer. Casting a
    double to an int? Oh, my. - MODBut that's what his assignment says, display it as an int. And the cast would work; I'm assuming he just didn't use it right.

  • My first Java Program

    I will be taking Java in School in a couple of months. I thought it would be a good idea to start trying it out now. One of the books I am reading has this example problem. It basically wants you to draw a hollow square 5 by on the screen. It says to use a while loop and if statements to solve. I don't no where to start, any help/advice would be great.
    Thanks

    The Book "Thinking in JAVA" is a great way to learn the language. The Book is really usefull and explains alot of ideas and concepts.
    Plus its free so you can download it
    http://www.mindview.net/Books/TIJ/
    Good Luck!

  • One more time, programming your first java program

    go here;
    http://jonjon.0catch.com
    mirror site;
    http://geocities.com/jon_riley/jon/java.htm

    I must assume that your continued use of the forum as a signpost to your home page represents your lack of understanding of the "Terms of Use" agreement that you had to accept to be a member of the forum.
    4.5 You agree not to use the Services for any unlawful activities not otherwise covered above, including (without limitation) attempting to compromise the security of any networked account or site, operating an illegal lottery or gambling operation, stalking, or making direct threats of physical harm. Additionally, You agree not to use the Services to:
    (h) use Your My Sun account as storage for remote loading or as a door or signpost to another home page, whether inside or beyond Sun.com.
    Other sections also apply.

Maybe you are looking for

  • Airport Express can find printer but can't print to it?

    My wife wants to be able to print from her iPad to our printer (Epson RX680). The printer itself is not wireless but I was told the main purpose of the AirPort Express is to give your printer wireless printing capability. Here's my rundown. Mac Pro d

  • System clipboard

    How can i access or grant access to the system clipboard to an applet ???

  • MORE iTunes store non-connectivity

    Not only is the store not connecting, but also AVG free anti-virus can't connect in order to update. Is this related? I've done everything, just like everyone else has... deleted the anti-virus and checked the store again and still nothing. But I can

  • Entry List - Multithreads - results List

    Hi All, I'm new to threading and I have this problem: I have a very long entry list that has to be processed and based in an analysis algorithm they will be send to either an accepted or rejected list. We need to process this list in concurrency. How

  • Unable to run Adobe

    Can't run Adobe. Also can't install because a version exists. Can't remove existing Adobe because files in use by Adobe Reader.