views:

87

answers:

7

hi ,

i am trying to setup java in my Ubuntu LUcid linux .

I checked my machine whether i am having JAva already installed in my machine.

when i tried for java -version it showed me

aruna@aruna-desktop:/usr/bin$ java -version java version "1.6.0_18" OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-4ubuntu3) OpenJDK Server VM (build 16.0-b13, mixed mode)

how can i start my java coding .. Where can i save my java files..

EDIT

I tried an example as you said but while running it is showing me the error as

aruna@aruna-desktop:~/Desktop/java$ javac MyFirstJavaProg.java The program 'javac' can be found in the following packages: * openjdk-6-jdk * ecj * gcj-4.4-jdk * gcj-4.3 Try: sudo apt-get install

+6  A: 

The Java Tutorials are practical guides for programmers who want to use the Java programming language to create applications. They include hundreds of complete, working examples, and dozens of lessons

skaffman
Where can i save my Java files and execute ??
Aruna
Read the tutorial
skaffman
the irony (makes 15 chars)
JoseK
+3  A: 

The "best" way depends on you, here is better option:

read a book & tutorials
write some code
play around

As a kick start:

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

Save this into a file having name MyFirstJavaProg.java in any DIR say /home/user/one/
goto terminal
fire following commands from that dir

javac MyFirstJavaProg.java

this will compile your code and will generate a .class file
to run that fire

java MyFirstJavaProg  
org.life.java
and yes follow the tutorial suggested by skaffmen
org.life.java
+1  A: 

What you have is the Java Runtime Environment, which allows java programs to run. To write your own, you will need the Java Development Kit, a text editor and a command line. However, I would strongly suggest you use an Integrated Development Environment such as Eclipse, as it will make your life much easier.

Tassos Bassoukos
At this level it is more important to keep it simple, to allow him to go through the Java Tutorial exercises.
Thorbjørn Ravn Andersen
A: 

You need to make sure that the jdk bin directory is on the path and then you can save and 'execute' your Java files anywhere you like.

My configuration in ~/.bashrc:

JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.20
export JAVA_HOME
export JDK_HOME=$JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
Jeroen Rosenberg
You should also state how you got the Sun Java 6 JDK on the system.
Thorbjørn Ravn Andersen
A: 

in ubuntu use synaptic manager and install JDK-6 with follwoing command

sudo apt-get install JDK-6

once you are done with installing JDK ,you can start programming.

giri
There's no such package in Lucid Lynx (at least not in the standard package repositories).
Bolo
+2  A: 

So your Java is running :-)

For developing you will need the javac command which will translate your java source files into java bytecode which can be interpreted by your virtual maschine. It should be already installed on your system because java -v tells you, an Open Java Developer Kit is installed.

There is no special place for saving your files. I keep my source files in my home directory under ~/coding/java/projects/foo/

You can just create them with your favorite editor and compile them with javac.

For larger projects it makes sense to use some of the bigger IDEs which will support an VCS integration, some fancy code completion and simple navigation in the project beside lots of helpful plugins. I favor Eclipse, but there are enough others. Anyway you will maybe feel some kind of lost with these and for the basics IMHO its better to use a simple texteditor:

Thats for the tools, now for the learning :-) There are a lot of resources for learning java out there such as tutorials like:

How fast and what you need for your learning depends on the background you have and what you are trying to achive.

I personally like learning out of books a lot more than reading some tutorials on the net. A perfect introduction to java and object oriented programming is in my view

echox
javac is not accepting in my machine
Aruna
try a `whereis java` to find out where your java installation is. There should be an bin directory with javac. Add this to your PATH.
echox
@echox, installing the OpenJDK JRE does not give javac. It is in the JDK.
Thorbjørn Ravn Andersen
You are right, I only saw JDK, not the "JRE" part. My fault. You have to install the OpenJDK JDK :-) See http://openjdk.java.net/install/
echox
+2  A: 

sudo apt-get install default-jdk

This will install the Java Development Kit so that you can use javac, java compiler.

You can save your files anywhere. I'd recommend to use an IDE for a beginner. NetBeans will do fine:

sudo apt-get install netbeans.

tulskiy