PDA

View Full Version : how to program java on Ubuntu ?



tunechi
April 21st, 2011, 05:27 PM
hi guys , i recently installed OPENJDK java 6 Runtime , anyways , i made a helloworld program to test it , in windows first i write in cmd javac HelloWorld.java , then java HelloWorld , i tried it here but it didnt work , i saved the file on desktop , how can i execute it and run it ?

thank you

orzechowskid
April 21st, 2011, 05:35 PM
hi,

are you not able to edit your file? Run javac? Run java? Something else? what were the exact error messages you received?

tunechi
April 21st, 2011, 05:37 PM
hi,

are you not able to edit your file? Run javac? Run java? Something else? what were the exact error messages you received?
Satellite-L305:~/Desktop$ Run javac HelloWorld.java
Run: command not found
----Satellite-L305:~/Desktop$ 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: 217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 21)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 66)
Could not find the main class: HelloWorld.java. Program will exit.
-----Satellite-L305:~/Desktop$

simeon87
April 21st, 2011, 05:39 PM
You have to type:


javac HelloWorld.java

to compile and


java HelloWorld

to run.

r-senior
April 21st, 2011, 05:40 PM
Try
java HelloWorld

You only need to specify the .java extension when you are compiling:


javac HelloWorld.java

tunechi
April 21st, 2011, 05:50 PM
You have to type:


javac HelloWorld.javato compile and


java HelloWorldto run.

lol , thats what i do on windows :D , anyways here is what i got
"-----Satellite-L305:~/Desktop$ javac HelloWorld.java
The program 'javac' can be found in the following packages:
* openjdk-6-jdk
* ecj
* gcj-4.4-jdk
* gcj-4.5-jdk
Try: sudo apt-get install <selected package>
"
i already download and installed openJDK java 6 Runtime ? what should i do now

thanks

orzechowskid
April 21st, 2011, 06:18 PM
the Java runtime is only a piece of Java called the JRE. It lets you run Java programs. If you want to compile your own, you need to install the whole JDK. Try 'sudo apt-get install openjdk-6-jdk' and then see if the javac command shows up on your computer.

tunechi
April 21st, 2011, 06:31 PM
the Java runtime is only a piece of Java called the JRE. It lets you run Java programs. If you want to compile your own, you need to install the whole JDK. Try 'sudo apt-get install openjdk-6-jdk' and then see if the javac command shows up on your computer.

thank you , donwloading hope it works

stchman
April 21st, 2011, 11:21 PM
You need to install the whole shooting match(JDK), not just the JRE.



sudo apt-get -y install sun-java6-bin sun-java6-fonts sun-java6-jdk sun-java6-jre sun-java6-plugin
Remember to enable the partner repository for 10.04 and later for the SUN(Oracle) Java.

Once this is done you can create/edit/compile Java programs as you would on any platform.