LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to acutally use java programs? (https://www.linuxquestions.org/questions/programming-9/how-to-acutally-use-java-programs-147852/)

veritas 02-18-2004 10:27 PM

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..

ter_roshak 02-18-2004 10:31 PM

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

veritas 02-18-2004 10:38 PM

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.

ter_roshak 02-18-2004 10:51 PM

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

moeminhtun 02-18-2004 11:59 PM

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.

german 02-21-2004 04:51 PM

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.

moeminhtun 02-21-2004 08:25 PM

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.

ter_roshak 02-21-2004 09:02 PM

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

Mega Man X 02-21-2004 09:49 PM

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 :)

german 02-22-2004 12:34 AM

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.

coolman0stress 02-22-2004 09:54 AM

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

I'll check your site in the mean time... :)

moeminhtun 02-22-2004 10:09 AM

:) 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.

coolman0stress 02-22-2004 11:15 AM

Hehe, i thought it'd be more elaborate ;)

Cool, thanks a bunch.

Looking_Lost 02-22-2004 12:25 PM

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)

caged 02-23-2004 08:37 PM

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.


All times are GMT -5. The time now is 09:20 AM.