LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-25-2003, 09:06 AM   #1
darin3200
Guru
 
Registered: Dec 2002
Distribution: Gentoo!
Posts: 1,153

Rep: Reputation: 45
Post Beginning help with Java


I'm am trying to learning java and I hava a few questions. First, I go to download the Java Developers Kit. Should I donwload the JRE or SDK ? Secondly how do i install something that is .bin. And lastly, my book is written for windows users. Can anyone give me what to do in linux for the following.

C:\>javac Example.java (for compiling)
C:\>java Example (for running)

Thanks,
 
Old 06-25-2003, 09:16 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,397

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
you want the sdk - Standard Developement Kit

.bin - run it, it's a self executable installer

the same programs will work.
 
Old 06-25-2003, 09:20 AM   #3
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
You want the SDK (Software Development Kit). The JRE (Java Runtime Environment) is just for running java apps... not writing them.

to execute a .bin file the easiest way is to pass it to the shell...
sh j2sdk1.4.1_install.bin

and then finally the javac and java commands are the same on linux as on windows... just make sure that the jdk bin directory is in your path, that JAVA_HOME environment is setup and that your CLASSPATH is set up.

hope that helps,
jpbarto
 
Old 06-25-2003, 12:32 PM   #4
darin3200
Guru
 
Registered: Dec 2002
Distribution: Gentoo!
Posts: 1,153

Original Poster
Rep: Reputation: 45
Quote:
Originally posted by jpbarto
just make sure that the jdk bin directory is in your path, that JAVA_HOME environment is setup and that your CLASSPATH is set up.
Lost you here.

Here is what I have
Code:
/*
This is a simple, simple app.
This is called First.java.
*/
class First {
public static void main(string args[]) {
}
}
I save this as First.java in my home directory. How should I comply it with the >javac commmand.
Thanks,
 
Old 06-25-2003, 12:36 PM   #5
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
compile with
javac First.java

run with
java First

are you aware of the two common java environment variables?
JAVA_HOME
and
CLASSPATH?

JAVA_HOME points to the directory where java is installed.
for example my java compiler and sdk and everything is installed in /opt/j2sdk1.4.1
so at the command line I execute
export JAVA_HOME=/opt/j2sdk1.4.1

then the CLASSPATH contains a list of directories where Java can find its lib files (or your executable code)
so you'd want something like...
export CLASSPATH=$JAVA_HOME/lib:./
 
Old 06-25-2003, 01:08 PM   #6
darin3200
Guru
 
Registered: Dec 2002
Distribution: Gentoo!
Posts: 1,153

Original Poster
Rep: Reputation: 45
this is what I am trying
Code:
[darinf@localhost darinf]$ javac First.java
bash: ./javac: Permission denied
[darinf@localhost darinf]$ su
Password:
[root@localhost darinf]# javac First.java
bash: javac: command not found
[root@localhost darinf]# export JAVA_HOME=/usr/java/j2sdk1.4.1_03/
[root@localhost darinf]# export CLASSPATH=$JAVA_HOME/lib:./
what should I try now?
 
Old 06-25-2003, 02:06 PM   #7
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
export PATH=$PATH:/usr/java/j2sdk1.4.1_03/bin

try it with the bin at the end

string should be String if you get it going.
 
Old 06-25-2003, 02:33 PM   #8
darin3200
Guru
 
Registered: Dec 2002
Distribution: Gentoo!
Posts: 1,153

Original Poster
Rep: Reputation: 45
It doens't do anything, it just brings up another command prompt. Do I do >javac or just javac. And i always get a command not found with both. Do I have to have my code anyplace special like in /usr/java/j2sdk1.3.1_03/bin or can in just be in my home directory. Thanks for the help becaue I have no idea what I'm doing
 
Old 06-25-2003, 02:45 PM   #9
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
Simple test just to get you doing something.

add in the line System.out.println("Whoopeee! ");
inbetween the two brackets after main

You'll have to be root

copy your code to the /usr/java/j2sdk1.4.1_03/bin directory



type

javac name_of_my_file.java
then
java name_of_my_file (without the java extension)

If you don't get any errors i.e javac not found then it's cool and all you've got to do is make sure for certain the directory above is in your path
 
Old 06-25-2003, 03:49 PM   #10
darin3200
Guru
 
Registered: Dec 2002
Distribution: Gentoo!
Posts: 1,153

Original Poster
Rep: Reputation: 45
no, that didn't help. So after I write the java, where should I save it to?

Last edited by darin3200; 06-25-2003 at 04:48 PM.
 
Old 06-25-2003, 05:11 PM   #11
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
After you write the java you can save it to anywhere.
issuing the command
javac First.java
will work if the javac executable (which resides in the bin directory of your java installation) is in your PATH environment variable.
after you execute
export PATH=$PATH:/usr/java/j2sdk1.4.1_03/bin
then execute
javac --help.

If javac prints out its usage then your command shell can find the javac compiler.

next execute
javac First.java
 
Old 06-25-2003, 05:35 PM   #12
darin3200
Guru
 
Registered: Dec 2002
Distribution: Gentoo!
Posts: 1,153

Original Poster
Rep: Reputation: 45
Thanks, it works. I tried to complie first but it would show a little ^ where I was missing something and I finally got it working.
Code:
/*
This is a simple, simple app.
This is called First.java.
*/
class First {
public static void main(String args[]) {
System.out.println("Whopeeee!!! I wrote JAVA");
}
}
Its primative and simple but I love it. Of course I might dig up this thread later if I get confused. Also, I found what I did wrong, I can only run javac from the /bin directory of my j2dk directory. Is there anyway around this?

Last edited by darin3200; 06-25-2003 at 08:09 PM.
 
Old 06-26-2003, 02:40 AM   #13
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
Forgive me if I'm having a wry smile to myself but it's already being said a good few times now

To be doubly sure insert the line

PATH=$PATH:/usr/java/j2sdk1.4.1_03/bin

before the export PATH line

into /etc/profile file


logout of the gui

log back in again and it should be accessible by every user in their shell, hopefully.
 
Old 06-26-2003, 08:10 AM   #14
darin3200
Guru
 
Registered: Dec 2002
Distribution: Gentoo!
Posts: 1,153

Original Poster
Rep: Reputation: 45
yeh, wry smile all you want. Before I actually typed PATH=$PATH:/JAVA_HOME and I was thinking how that didn't lool quite right.
 
Old 06-26-2003, 08:16 AM   #15
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
Okey-dokey, it's good to keep a sense of humour about things. I'm the first to laugh at myself - which I need to do more often than not when there's a computer involved.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DISCUSSION: Beginning with Java darin3200 LinuxAnswers Discussion 27 08-11-2014 01:45 PM
Just the beginning.... woodworker97 Mandriva 5 05-20-2005 01:53 AM
A new beginning... LK873 Mandriva 13 03-08-2005 06:59 AM
very beginning vegpl Linux From Scratch 13 06-26-2004 11:56 AM
Beginning Fatal_3rr0r Programming 4 06-09-2003 08:08 PM


All times are GMT -5. The time now is 08:55 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration