User Login

Help Community Login:

small java app I wrote want to compile it to a single runnable file

9 replies [Last post]
Evil Monkey's picture
Evil Monkey
Moderator (Watching Over The Masses)Premium Member (Silver)The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariI'm Here To Help, & Have Proven It!Windows UserMember of VileThe JokerSomeone thinks you're a Rotten Tomato!STaRDoGG <3's you ;)
Joined: 01/22/2009
Posts: 234
Drops: 350

Hey Dog,

Learning a bit of java at the moment.

I wrote a small app that simply will take input from a user for the radius of a cirlce then spit out the Area, circumference, and diameter. Here is my code. But what I'd like to do is compile it as an exe or i'm thinking .jar file so I can simply run it in an OS environment. Can you point me in the right direction on how to do this. Doesn't seem my app "eclipse" can do this or at least I'm not seeing it. Here's my code.

<br />
/***********************************************************************<br />
  Program Name: Circle.java<br />
  Programmers Name: Glen Ciszewski<br />
  Program Description: This program will calculate the area, circumference and diameter of a circle<br />
  ***********************************************************************/<br />
import javax.swing.JOptionPane;<br />
public class Circle <br />
{<br />
<br />
   <br />
   public static void main(String[] args) <br />
   {<br />
      String userInput;      //number entered by user<br />
      int radius;            //converted input for number<br />
      double diameter;      //the diamater of the circle<br />
      double circumference;   //the circumference of the circle<br />
      double area;         //the area of the circle<br />
      <br />
      //read in the users input as string<br />
      userInput = JOptionPane.showInputDialog("Enter in the radius");<br />
      <br />
      //convert number from string to type int<br />
      radius = Integer.parseInt(userInput);<br />
      <br />
      //find the diameter<br />
      diameter = 2*radius;<br />
      <br />
      //display the diameter<br />
      JOptionPane.showMessageDialog(null,"The diameter is " + diameter,<br />
            "Results",<br />
            JOptionPane.PLAIN_MESSAGE);<br />
      <br />
      //find the circumference<br />
      circumference = 2*Math.PI*radius;<br />
      <br />
      //display the circumference<br />
      JOptionPane.showMessageDialog(null,"The circumference is " + circumference,<br />
            "Results",<br />
            JOptionPane.PLAIN_MESSAGE);<br />
      <br />
      //find the area<br />
      area = Math.PI*radius*radius;<br />
      <br />
      //display the area<br />
      JOptionPane.showMessageDialog(null,"The area is " + area,<br />
            "Results",<br />
            JOptionPane.PLAIN_MESSAGE);<br />
      System.exit(0);<br />
      <br />
    }<br />
<br />
}<br />

I Averaged: 0 | 0 votes

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
STaRDoGG's picture
From:
Olympus
STaRDoGG
Head Mucky MuckJoined the Dark SidePremium Member (Gold)I'm a Code Monkey!The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariLinux UserMac UserWindows UserI donated to GeekDrop simply because I love it!Booga Booga BoogaI took a bite of the AppleFormer Phrozen Crew MemberI'm MagicMember of VileThe Dr. put the stem on the apple!The JokerSomeone thinks you're udderly delightful!
Relationship Status:
Divorced
Joined: 01/14/2009
Posts: 2549
Drops: 2998
Mood: Curious
Re: small java app I wrote want to compile it to a single ...

First you need to strip out the html code in it (the breaks) and then just need to compile it with a java compiler (the JDK). "Compiling" runs it through the java interpreter and converts the code into an executable file.

After it's installed and added to your Windows path, you can just go to the command line and type: javac Circle.java

Then to run it, after it's compiled type: java Circle

You should be able to add the compiler to Eclipse so it can compile it for you with a button click once you have the JDK installed, since it's a commandline tool.


Necessity is the mother of invention
GeekGirl's picture
GeekGirl
Banned Member (Way To Go!)
Joined: 03/04/2009
Posts: 909
Drops: 1143
Mood: Loved
Re: small java app I wrote want to compile it to a single ...
Applause
Evil Monkey's picture
Evil Monkey
Moderator (Watching Over The Masses)Premium Member (Silver)The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariI'm Here To Help, & Have Proven It!Windows UserMember of VileThe JokerSomeone thinks you're a Rotten Tomato!STaRDoGG <3's you ;)
Joined: 01/22/2009
Posts: 234
Drops: 350
Re: small java app I wrote want to compile it to a single ...

those Html breaks aren't really in my code. When I placed it in between the code tags in the post they got added automatically. Guess i didnt' need the code tags but most forums like you to use them. I'm new to programming but not quite that Green Smile My code works but just wanted to make it something I could run outside of my dev software.

I thought I could export the project as an executable .jar file but that don't seem to be working. I'll figure it out.

Thanks.

I hope that after I die, people will say of me: "That guy sure owed me a lot of money.''

GeekGirl's picture
GeekGirl
Banned Member (Way To Go!)
Joined: 03/04/2009
Posts: 909
Drops: 1143
Mood: Loved
Re: small java app I wrote want to compile it to a single ...
Does this help at all, EM?
Evil Monkey's picture
Evil Monkey
Moderator (Watching Over The Masses)Premium Member (Silver)The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariI'm Here To Help, & Have Proven It!Windows UserMember of VileThe JokerSomeone thinks you're a Rotten Tomato!STaRDoGG <3's you ;)
Joined: 01/22/2009
Posts: 234
Drops: 350
Re: small java app I wrote want to compile it to a single ...

Good read. thanks GG Smile

I hope that after I die, people will say of me: "That guy sure owed me a lot of money.''

GeekGirl's picture
GeekGirl
Banned Member (Way To Go!)
Joined: 03/04/2009
Posts: 909
Drops: 1143
Mood: Loved
Re: small java app I wrote want to compile it to a single ...
Did it help at all EM?
Evil Monkey's picture
Evil Monkey
Moderator (Watching Over The Masses)Premium Member (Silver)The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariI'm Here To Help, & Have Proven It!Windows UserMember of VileThe JokerSomeone thinks you're a Rotten Tomato!STaRDoGG <3's you ;)
Joined: 01/22/2009
Posts: 234
Drops: 350
Re: small java app I wrote want to compile it to a single ...

A little. I didn't have time to read it all yet. I'm swamped at work. And I'm still trying to let it all soke in being new to the programing thing.

I hope that after I die, people will say of me: "That guy sure owed me a lot of money.''

GeekGirl's picture
GeekGirl
Banned Member (Way To Go!)
Joined: 03/04/2009
Posts: 909
Drops: 1143
Mood: Loved
Re: small java app I wrote want to compile it to a single ...
Well let us know Smile I hope it helps. Yeah i totally understand, and admire you for taking on a new hobby/task like that. I tried more than once but my eyes went wide each time and completely glazed over. Good luck Thumbs Up
Evil Monkey's picture
Evil Monkey
Moderator (Watching Over The Masses)Premium Member (Silver)The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariI'm Here To Help, & Have Proven It!Windows UserMember of VileThe JokerSomeone thinks you're a Rotten Tomato!STaRDoGG <3's you ;)
Joined: 01/22/2009
Posts: 234
Drops: 350
Re: small java app I wrote want to compile it to a single ...

Thanks, Yea I know what you mean. It can really give you a headache. I just wish I had more time to sit down with it and do it. Alway's wanted to learn programing. At least these classes make me do it. There only 8 weeks long though. So really how much can you learn in an 8 week class when it comes to programing?

Well I've had enough fun at work. now off to class for me!
TTYL

I hope that after I die, people will say of me: "That guy sure owed me a lot of money.''

Who's New

Simra's picture
srikanth's picture
joshter1950's picture
bittu's picture
will1981's picture
jemsrock's picture
ravichandraa's picture
baofeng2003's picture
Vibeke's picture
seyab's picture
Nateatx72's picture
Jadedend's picture
sslover332's picture
highway420's picture
lovely's picture
facebook codes exploits tips tricks Phrozen Crew
All contents ©Copyright GeekDrop 2009-2017
TOS | Privacy Policy