LinuxQuestions.org
Visit Jeremy's Blog.
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 02-18-2004, 10:27 PM   #1
veritas
Member
 
Registered: Aug 2003
Location: Dallas,TX
Distribution: Ubuntu Server, Slackware, Red Hat 6.1
Posts: 241

Rep: Reputation: 30
how to acutally use java programs?


I'm taking a computer science class right now and we are currently working with java (last year was c++, but the school switched to java because of the AP computer science board requirements), and I have yet to find an use for java besides the web. I know you can compile your source code into byte code, but only people with that certain java executable can run it.

I'm just wondering how your supposed to distribute your programs to people that do not have the program that runs the byte code. Last year, we could make our c++ code into an exe file so anyone with windows could run it.

Is there any way to do this with java? My computer science teacher will not give me a straight answer. Maybe its because she has no training or certification in java. but there must be someone out there that know how to actually use the programs you compile with other computers..
 
Old 02-18-2004, 10:31 PM   #2
ter_roshak
Member
 
Registered: May 2001
Location: Everett, WA
Distribution: Gentoo, RedHat
Posts: 102

Rep: Reputation: 15
Once you compile the java source into byte-code, you can run it on any compatible machine that has the Java Runtime Environment installed... Therefore, you can type java <filename> of any .class file and expect it to execute. The language is not 100% portable though.

-Josh
 
Old 02-18-2004, 10:38 PM   #3
veritas
Member
 
Registered: Aug 2003
Location: Dallas,TX
Distribution: Ubuntu Server, Slackware, Red Hat 6.1
Posts: 241

Original Poster
Rep: Reputation: 30
Yes, i knew about the java command to run the byte code, but i just did not understand how you are supposed to use it on machines without the RE installed.. Sorta disapointing that its not 100% portable. But I guess if one writes java programs for the linux community, mostly everyone with have the java command and therefore could use your programs. I just wish we stuck with c++... Oh well.
 
Old 02-18-2004, 10:51 PM   #4
ter_roshak
Member
 
Registered: May 2001
Location: Everett, WA
Distribution: Gentoo, RedHat
Posts: 102

Rep: Reputation: 15
There are compilers out there that will allow you to compile the code into a binary, or a .exe file that will be what I think you are looking for, unfortunately, I don't know of any free ones. I know there are quite a few arguments both ways, for and against Java and I am undecided myself. It does seem to cut down on de-bugging quite a bit.

-Josh
 
Old 02-18-2004, 11:59 PM   #5
moeminhtun
Member
 
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647

Rep: Reputation: 30
You can integrate the JRE into your program, and legelly distribute it together as well. That would solve all the problems including the JRE incompatible problems. And you can write the batch script (very simple one) to run the program so that the user doesn't need to know how to run the java program using the "java" commands. He can just normally run like a normal windows or Linux programs.

So the tips is that, always try to integrate the JRE into your program as an internal folder when you distribute it, and run your Java program with your own JRE. You could avoid so many problems by doing so.
Or you can give a choice for ppl to choose like "JRE integrated version" for those who don't know what is going on and "Without JRE version" for those who exactly know what to do.

Java is great. You will have no regret learning it.

Last edited by moeminhtun; 02-19-2004 at 02:17 AM.
 
Old 02-21-2004, 04:51 PM   #6
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
um... what parts of Java are not 100% portable? Last I heard, Sun had something like 2000 tests they performed on candidate JRE's to ensure that the language was 100% portable... unless of course you get into JNI or the Runtime class...

Veritas, you can also compile java source or bytecode into native executables with Excelsior Jet (http://www.excelsior-usa.com/jet.html , Windoze) or GCJ (http://gcc.gnu.org/java/ , most others). They are not perfect though, and I have read that GCJ does a terrible job of compiling Swing or AWT into native machine code.

HTH

B.
 
Old 02-21-2004, 08:25 PM   #7
moeminhtun
Member
 
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647

Rep: Reputation: 30
Sorry. What I meant is "version incompatibilty" problem.
For example, your program uses the build-in new features of J2sdk1.4 like "logging" or/and "xml processing", this program wouldn't run on the earlier versions of jdk like 1.2 or 1.3.
 
Old 02-21-2004, 09:02 PM   #8
ter_roshak
Member
 
Registered: May 2001
Location: Everett, WA
Distribution: Gentoo, RedHat
Posts: 102

Rep: Reputation: 15
Calling a language 100% portable is a very tall order to fill. 2000 heresay tests does not call it 100%, and the clause that you add at the end indicates that it's not 100% portable, so what's the argument?

Quote:
unless of course you get into JNI or the Runtime class...
-Josh
 
Old 02-21-2004, 09:49 PM   #9
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
Who said that C++ is portable and that the user does not have to install anything?. That's a wrong argument. Sure, as long as you are doing console applications, C++ can be used in any platforms (yet, there might be some differences with headers, as conio.h which g++ does not have, but borland does). The first step you go into graphics, C++ portability is over. You have to choose an graphics API to create windows. If you use windows native API calls, your code is stuck with Windows Environment. If you choose GTK or QT you can port your program, but you will still have to make peoples install those libraries to run your application (pretty much the same with Java).

About Java being only useful for the web, well, you still must to have the Java plugin installed to run a Java applet. Same goes to flash or whatever you want to use on the Web.

Any game that you buy, also includes updates to either your graphics card or DirectX or both. There's not wrong shipping JRE, DirectX or even GTK and QT or any other updates you want to do to the user's system, within your programs.

But saying that C++ is portable and Java is only useful for the web is something I really have to disagree. Also, as long as the user has JRE installed, distributing your programs online is much easier then C++... Compiled java applications (.class) are really small compared with a final .exe.

Well, at least that's how I see Java
 
Old 02-22-2004, 12:34 AM   #10
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
Quote:
Originally posted by ter_roshak
Calling a language 100% portable is a very tall order to fill. 2000 heresay tests does not call it 100%, and the clause that you add at the end indicates that it's not 100% portable, so what's the argument?
I suppose what I meant was that although it is trivial to write Java code which will not port to a different platform (such as JNI code), I don't believe the JRE or JDK imposes any platform-specific restrictions on the developer (IE, any shortcomings of Java are more or less universal shortcomings, with obvious exceptions like Swing/AWT doesn't work without an X server and path names look different). I guess you're right. It's not 100% portable. It does as good a job as any language I know of, though.

B.
 
Old 02-22-2004, 09:54 AM   #11
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
moeminhtun, any tutorials, etc, on how to in corperate your own JRE into your apps?

I'll check your site in the mean time...
 
Old 02-22-2004, 10:09 AM   #12
moeminhtun
Member
 
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647

Rep: Reputation: 30
Don't think a lot. It's damned simple. Download the jre "the self extracting version" from sun microsystem which will extract as the stand-alone directory.
Say, your project main folder is "MyProjects", just copy the "jre" directory into your project folder. That's it.
Then you write a batch file in your project directory to run your java program, in which you write a simple script to give the PATH variable to the JRE and run your java program.
That's it. Your Java program will run on its own JRE.
 
Old 02-22-2004, 11:15 AM   #13
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Hehe, i thought it'd be more elaborate

Cool, thanks a bunch.
 
Old 02-22-2004, 12:25 PM   #14
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
The initial comparison is a bit misleading anyway as has been pointed out:


Quote:
I'm just wondering how your supposed to distribute your programs to people that do not have the program that runs the byte code. Last year, we could make our c++ code into an exe file so anyone with windows could run it.

It isn't very portable if it can only run on windows. How are you supposed to distribute the exe file to people who don't have windows? (without them running an wine or another program)
 
Old 02-23-2004, 08:37 PM   #15
caged
Member
 
Registered: Jan 2004
Location: new zealand
Distribution: Mandrake,Slackware
Posts: 165

Rep: Reputation: 30
java is a good language to know. keep it up and learn what ya can then you can abondon it if you dont like it. going from c++ to java is just a sideways step i think, they both have advantages and they both have simularitys.

Java and C++ are both Object Orientated.
Java binarys are operating system independant. (mostly)

I havent actually done any C++ yet. iv been meaning to get around to it. I done a bit of C ages ago. Are there any people here who did any A or B programming?

have fun.
Ben.
 
  


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
can't run my java programs crazyzombie Linux - Newbie 1 09-23-2005 01:42 PM
Opening programs in Java Diederick Programming 6 06-27-2005 03:58 PM
Grip not acutally ripping thebeast Linux - Software 4 09-12-2004 09:02 PM
How to run Java programs in a sandbox fpmc Programming 0 07-07-2004 03:57 AM
Java programs adcripps Linux - Newbie 2 03-04-2002 01:03 PM


All times are GMT -5. The time now is 08:27 AM.

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