Jump to content

  • Log In with Google      Sign In   
  • Create Account


How do I run a .java written in notepad++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 aattss   Members   -  Reputation: 383

Like
0Likes
Like

Posted 23 May 2012 - 06:34 AM

As you see, I prefer notepad++ to Eclipse, and I was wondering, how do I run a simple .java program?

Sponsor:

#2 mrjfalk   Members   -  Reputation: 133

Like
0Likes
Like

Posted 23 May 2012 - 06:54 AM

Check out this guide on how to compile a .java file and run it in Windows using the command prompt:
http://www.skylit.com/javamethods/faqs/javaindos.html

#3 Ashaman73   Crossbones+   -  Reputation: 6846

Like
0Likes
Like

Posted 23 May 2012 - 07:16 AM

notepad => test.java
javac test.java
java -cp . test

Edited by Ashaman73, 23 May 2012 - 07:17 AM.


#4 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 23 May 2012 - 08:21 AM

As you see, I prefer notepad++ to Eclipse, and I was wondering, how do I run a simple .java program?


You need to have installed JRE (most likely you have it already) and JDK.
To compile your code you need to use javac (which is part of JDK). If you're using Windows most likely you'll need to specify full path to compiler, or you could setup environmental variable, or make batch script. As Ashaman73 wrote, all you have to do is specify names of your file(s).
Running is even easier, usually you don't need to specify full path to java.exe

#5 aattss   Members   -  Reputation: 383

Like
0Likes
Like

Posted 23 May 2012 - 11:47 AM


As you see, I prefer notepad++ to Eclipse, and I was wondering, how do I run a simple .java program?


You need to have installed JRE (most likely you have it already) and JDK.
To compile your code you need to use javac (which is part of JDK). If you're using Windows most likely you'll need to specify full path to compiler, or you could setup environmental variable, or make batch script. As Ashaman73 wrote, all you have to do is specify names of your file(s).
Running is even easier, usually you don't need to specify full path to java.exe


Which file do I turn into a .exe? the .class or .java? Neither seems to work.

At least I finally was able to javac it.

#6 incertia   Crossbones+   -  Reputation: 777

Like
0Likes
Like

Posted 23 May 2012 - 12:09 PM

You don't turn anything into an .exe. The Java VM will run the .class file that you specify. 'java Derp' will look for Derp.class and run its main().
what

#7 Ashaman73   Crossbones+   -  Reputation: 6846

Like
0Likes
Like

Posted 23 May 2012 - 12:11 PM

Which file do I turn into a .exe?

You don't turn a file into a standalone exe. Java needs always a runtime enviroment (jre) and a virtual machine (vm = java.exe) to run your program.
Compiling: javac test.java (=> this will create a class file)
Executing a single class in your virtual machine: java -cp . test

Later on, when you have a whole application, you can put it all into a jar (=zip file) and 'execute' the jar like this: java -jar my_test_application.jar

#8 SimonForsman   Crossbones+   -  Reputation: 5951

Like
0Likes
Like

Posted 23 May 2012 - 02:04 PM


Which file do I turn into a .exe?

You don't turn a file into a standalone exe. Java needs always a runtime enviroment (jre) and a virtual machine (vm = java.exe) to run your program.
Compiling: javac test.java (=> this will create a class file)
Executing a single class in your virtual machine: java -cp . test

Later on, when you have a whole application, you can put it all into a jar (=zip file) and 'execute' the jar like this: java -jar my_test_application.jar


You can also doubleclick the .jar (unless you install winrar since it tends to hijack the extension) and you can wrap the .jar in an .exe (There are lots of tools for that)
(Allthough if you make a proper installer you can just create a shortcut instead)

Edited by SimonForsman, 23 May 2012 - 02:05 PM.

I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#9 aattss   Members   -  Reputation: 383

Like
0Likes
Like

Posted 24 May 2012 - 11:43 AM

On a windows vista, how do I permanetly set the path so I don't have to set path every time I want to javac something?

#10 WavyVirus   Members   -  Reputation: 735

Like
0Likes
Like

Posted 24 May 2012 - 11:58 AM

You can add the path to javac to the PATH environment variable via Control Panel > System > Advanced system settings > Environment variables.

See https://en.wikipedia.org/wiki/PATH_(variable)#DOS.2C_OS.2F2.2C_and_Windows

Edited by WavyVirus, 24 May 2012 - 12:01 PM.


#11 cmasupra   Members   -  Reputation: 145

Like
0Likes
Like

Posted 24 May 2012 - 03:42 PM

2 things:

1) I assume you don't like Eclipse because of it's complexity. I recommend using the free version of JCreator to learn Java. Very simple Java IDE. Then later on, try NetBeans if you still don't like Eclipse. I don't like Eclipse, but I do like NetBeans. You can also try the full version of JCreator, but I don't recommend that for learning.

2) This is what you have to do to compile and run a .java file using the command line. Add Java to the Classpath (google it). Then open the command prompt. Go to the directory where you saves your .java file. Type "javac myfile.java" without quotes. Then type "java myfile.class" without quotes. "javac" compiles your .java file to a .class file. Then "java" runs your .class file.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS