-1

I got a strange problem in my windows 7 system running jdk1.6.0_33

When I try to run a simple java program from command prompt, it opens a new window (something like java frame) and suddenly disappears. There is no result shown on command prompt also I am unable to terminate the process (using Ctrl+C) or close command prompt after this. A java process is created each time I do this. I tried to kill process using Task Manager, but that too didn't work.

I am able to run the same program using eclipse. Here is my program

class HelloWorld{
    public static void main(String [] args)
    {
        System.out.println("Hello World");
    }
}

Environment variables are set as follows:

Path=C:\Program Files\Java\jdk1.6.0_33\bin
classpath=.

Commands I used are,

javac HelloWorld.java
java HelloWorld

Why is this happening? Thanks in Advance.

Sree
  • 635
  • 4
  • 10
  • 2
    please provide commands which you are using to run your app – Alex Stybaev Dec 18 '12 at 07:47
  • If you run java -version and javac -version on command prompt what you get? – Smit Dec 18 '12 at 07:48
  • 1
    how are you running your program from command prompt? – vishal_aim Dec 18 '12 at 07:48
  • which command are you using to compile and run? – Mohammod Hossain Dec 18 '12 at 07:49
  • @Alex Stybaev Please find updated question – Sree Dec 18 '12 at 07:50
  • "Commands I used are," where you type those commands? – Nikolay Kuznetsov Dec 18 '12 at 07:52
  • Run `cmd` then `cd` to folder where Hello.class is – Nikolay Kuznetsov Dec 18 '12 at 07:53
  • @smith getting same result – Sree Dec 18 '12 at 07:55
  • @Nikolay Kuznetsov javac HelloWorld.java and java HelloWorld – Sree Dec 18 '12 at 07:56
  • @Nikolay Kuznetsov : I did the same. I used those commands from the directory where java file is located. And my classpath is set to . – Sree Dec 18 '12 at 07:58
  • @Sree What do you mean by getting same result? Are they returning you correct java and javac – Smit Dec 18 '12 at 07:58
  • @sree have u got class file after compile? – Mohammod Hossain Dec 18 '12 at 07:58
  • @Sree follow this link to setup java environment variables. I think your classpath is the issue. [This Link](http://www.roseindia.net/java/java-classpath.shtml) – Smit Dec 18 '12 at 08:04
  • @MohammodHossain Yes I got classfile created after compile – Sree Dec 18 '12 at 08:37
  • Are you getting any exception after running class file using java className – Mohammod Hossain Dec 18 '12 at 08:39
  • @smit javac -version returns javac 1.6.0_33 but java -version creates a new window that disappears. I set session classpath using set classpath command but that too failed. – Sree Dec 18 '12 at 08:42
  • @MohammodHossain no exceptions. As I mentioned, a new window is opened and immediately disappeared. Command prompt is not returned to new command line. – Sree Dec 18 '12 at 08:47
  • @Sree As I said earlier `java -version` supposed to return you `java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_25-b06) Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)` That means your classpath is issue. I provided link in my previous comment use that and see both commands returns proper version. – Smit Dec 18 '12 at 16:46
  • @smit Yes, it is supposed to run but its not. My classpath is set to current directory. I tried to run it using java -classpath option but that too gave same result. It was working previously but it stopped working. If it is issue with classpath, it is supposed to show some exception, right? There is no exception shown. – Sree Dec 18 '12 at 18:02
  • @Sree You current classpath shows `classpath=.`. Better you change it as provided link says. if both command returns proper `version` then you can run your `HelloWord` program. just try that once and see what happens. Nobody can help you without looking at your machine. So consider this as your last resort. – Smit Dec 18 '12 at 18:18
  • @smit I had tried that already. It could be something with my system, which I cannot figure out. As I mentioned in my question, when I give java command to run the program, cursor moves to next line and a new window (like on which appears when we do a swing program) is opened and disappears suddenly. There my command prompt stops working. It do not return to new line. I pressed Ctrl+C to stop that, but its not responding. Same time a java process is created (found it in task manager). That means my java program is running... – Sree Dec 18 '12 at 18:34
  • @Sree Try on different machine. If it works there that means something wrong with your current system. This is your last resort. – Smit Dec 18 '12 at 19:08

2 Answers2

0

I'm not sure, but I think this is what happens if you use java versus javaw from the command prompt on Windows:

References:

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
-2

If your java class path is configured correctly.

type javac command in command prompt

You will get java compiler information.

After compile the class find your folder location if any .class file is created.

Mohammod Hossain
  • 4,134
  • 2
  • 26
  • 37