blacksapphire08
Omnipotent Enthusiast
- Total Posts : 8447
- Reward points : 0
- Joined: 8/16/2010
- Status: offline
- Ribbons : 22

Saturday, March 19, 2011 10:29 PM
(permalink)
I'm trying to compile my .java files using the command prompt and it fails everytime. Is there a program or some other method that will do this for me?
|
MissionXneo007
Superclocked Member
- Total Posts : 106
- Reward points : 0
- Joined: 6/18/2008
- Status: offline
- Ribbons : 0
Re:Anyone familiar with Java?
Saturday, March 19, 2011 10:32 PM
(permalink)
What do you type exactly? And are you using just the normal cmd in windows?
-EVGA GTX 295 -Intel i7 920 @ 3.9 -EVGA X58 sli -3x2gb OCZ Gold DDR3 1600 -25.5" Samsung Monitor (1920x1200) -Velociraptor 150gb HD -Hitachi 2tb HD
|
Blizzie
CLASSIFIED Member
- Total Posts : 3883
- Reward points : 0
- Joined: 7/4/2007
- Location: California
- Status: offline
- Ribbons : 17

Re:Anyone familiar with Java?
Saturday, March 19, 2011 10:34 PM
(permalink)
Where are you typing to compile? Terminal? You can use: javac test.java
|
blacksapphire08
Omnipotent Enthusiast
- Total Posts : 8447
- Reward points : 0
- Joined: 8/16/2010
- Status: offline
- Ribbons : 22

Re:Anyone familiar with Java?
Saturday, March 19, 2011 11:02 PM
(permalink)
Blizzie Where are you typing to compile? Terminal? You can use: javac test.java Yes that's what i'm typing to compile my .java files in the directory that contains the files. I get the following error everytime: 'javac' is not recognized as an internal or external command, operable program or batch file, even though I have JDK and JRE installed.
|
linuxrouter
CLASSIFIED Member
- Total Posts : 4605
- Reward points : 0
- Joined: 2/28/2008
- Status: offline
- Ribbons : 104
Re:Anyone familiar with Java?
Saturday, March 19, 2011 11:07 PM
(permalink)
You need to add the JDK bin directory to your system PATH. Right-click on My Computer and go to Properties. Click Advanced and select Environment Variables. In Windows 7, you have to go to Advanced System Settings first and then you can find Environment Variables under the Advanced tab. There should be a System variable called Path. Add the bin directory for the JDK to the path. It should be under c:\Program Files\java. Then next time you open a command prompt, the javac command will be available. Here is a screenshot that may help. Just make sure to update the version number to match your JDK.
post edited by linuxrouter - Saturday, March 19, 2011 11:14 PM
CaseLabs M-S8 - ASRock X99 Pro - Intel 5960x 4.2 GHz - XSPC CPU WC - EVGA 980 Ti Hybrid SLI - Samsung 950 512GB - EVGA 1600w TitaniumAffiliate Code: OZJ-0TQ-41NJ
|
blacksapphire08
Omnipotent Enthusiast
- Total Posts : 8447
- Reward points : 0
- Joined: 8/16/2010
- Status: offline
- Ribbons : 22

Re:Anyone familiar with Java?
Saturday, March 19, 2011 11:14 PM
(permalink)
linuxrouter You need to add the JDK bin directory to your system PATH. Right-click on My Computer and go to Properties. Click Advanced and select Environment Variables. In Windows 7, you have to go to Advanced System Settings first and then you can find Environment Variables under the Advanced tab. There should be a System variable called Path. Add the bin directory for the JDK to the path. It should be under c:\Program Files\java. Then next time you open a command prompt, the javac command will be available. I did that and it said file not found when I went to compile it. Do the files have to be in the directory as javac? edit: nvm I figured out the problem (didnt close the cmd prompt first, doh!), thanks for the help!
post edited by blacksapphire08 - Saturday, March 19, 2011 11:21 PM
|
linuxrouter
CLASSIFIED Member
- Total Posts : 4605
- Reward points : 0
- Joined: 2/28/2008
- Status: offline
- Ribbons : 104
Re:Anyone familiar with Java?
Saturday, March 19, 2011 11:15 PM
(permalink)
Take a look at the screenshot I posted above. It gives an example of the Path with the bin directory. Also, make sure to put in a semicolon between each item in the Path list. You also have to restart the command prompt after making the update.
CaseLabs M-S8 - ASRock X99 Pro - Intel 5960x 4.2 GHz - XSPC CPU WC - EVGA 980 Ti Hybrid SLI - Samsung 950 512GB - EVGA 1600w TitaniumAffiliate Code: OZJ-0TQ-41NJ
|
SirMaster
FTW Member
- Total Posts : 1610
- Reward points : 0
- Joined: 7/2/2006
- Location: Sussex, WI
- Status: offline
- Ribbons : 21

Re:Anyone familiar with Java?
Sunday, March 20, 2011 0:36 PM
(permalink)
You have to have the .java files in the folder you are running the command from. Or you can just fully qualify all the paths to the file you are trying to compile and run the command from anywhere.
|
blacksapphire08
Omnipotent Enthusiast
- Total Posts : 8447
- Reward points : 0
- Joined: 8/16/2010
- Status: offline
- Ribbons : 22

Re:Anyone familiar with Java?
Sunday, March 20, 2011 4:30 PM
(permalink)
I'm still a newbie with Java and I cant figure out why i'm getting errors on my math calculations. I've tried it every way I know how, maybe someone can give me a few pointers? import java.math.*;
public class mortgage { public static void main(String[] args) { int l = 250000;//loan amount double r = 0.0048;//interest rate compounded monthly int n = 360;//number of payments int payment = p;//monthly payment int balance = b;//balance of loan after each payment p = l[r(1 + r)^n]/[(1 + r)^n - 1];//errors occur on this line //printing results System.out.println("Monthly payment = " + Math.round(p));//errors on this line as well
while (int p < 0) p = -359//Mortgage Table//this part is not finished yet b = l[(1 + r)^n - (1 + r)^p]/[(1 + r)^n - 1]; System.out.println("Balance = " + p); //counter used for loop p++; } }
|
d-rock
SSC Member
- Total Posts : 927
- Reward points : 0
- Joined: 5/10/2010
- Location: Sacramento,CA
- Status: offline
- Ribbons : 9

Re:Anyone familiar with Java?
Sunday, March 20, 2011 4:37 PM
(permalink)
i could use some help.....how do i write code lol i know i know i need to get back in school.
|
joeomerta
iCX Member
- Total Posts : 296
- Reward points : 0
- Joined: 5/31/2008
- Location: Buffalo, NY
- Status: offline
- Ribbons : 0
Re:Anyone familiar with Java?
Sunday, March 20, 2011 5:12 PM
(permalink)
i use eclipse. takes care of everything in one place.
3770K ** 16GB RAM ** EVGA GTX1070 SC ** 2x120GB SSDs RAID0, 4x1TB HDDs RAID5
|
Fadekraft
Superclocked Member
- Total Posts : 160
- Reward points : 0
- Joined: 11/6/2008
- Location: Denmark!
- Status: offline
- Ribbons : 0
Re:Anyone familiar with Java?
Sunday, March 20, 2011 5:13 PM
(permalink)
The variable 'p' is undefined until you reach your while loop. You can't use the variable before it's defined, and you are trying index the variable, but you define it as single valued. I just took a java course at my university :) Edit* Also never put your main method inside a class, it needs to be outside of the classes.
post edited by Shadowhunter22 - Sunday, March 20, 2011 5:14 PM
LnfinityX3: MB: ASUS P8Z68-V, Socket 1155 CPU: Intel i5-2500K CPU Cooling: Corsair H80 Hydro Series Watercooler RAM: 8GB Corsair 1600 DHX3 Dominators (/w fan) GPU: MSI 560 GTX Ti Twin Frozr II PSU: Corsair HX 850 Watt Case: Cooler Master CM 690 II Advanced (Black) OS: Windows 7 Ultimate x64
|
Blizzie
CLASSIFIED Member
- Total Posts : 3883
- Reward points : 0
- Joined: 7/4/2007
- Location: California
- Status: offline
- Ribbons : 17

Re:Anyone familiar with Java?
Sunday, March 20, 2011 5:17 PM
(permalink)
blacksapphire08 I'm still a newbie with Java and I cant figure out why i'm getting errors on my math calculations. I've tried it every way I know how, maybe someone can give me a few pointers? import java.math.*; public class mortgage { public static void main(String[] args) { int l = 250000;//loan amount double r = 0.0048;//interest rate compounded monthly int n = 360;//number of payments int payment = p;//monthly payment int balance = b;//balance of loan after each payment p = l[r(1 + r)^n]/[(1 + r)^n - 1];//errors occur on this line //printing results System.out.println("Monthly payment = " + Math.round(p));//errors on this line as well while (int p < 0) p = -359//Mortgage Table//this part is not finished yet b = l[(1 + r)^n - (1 + r)^p]/[(1 + r)^n - 1]; System.out.println("Balance = " + p); //counter used for loop p++; } } You try to set payment = p before you define what p is It should be: public class mortgage { public static void main(String[] args) { int l = 250000;//loan amount double r = 0.0048;//interest rate compounded monthly int n = 360;//number of payments int p = l[r(1 + r)^n]/[(1 + r)^n - 1]; //errors do longer occur on this line int payment = p; //monthly payment int balance = b;//balance of loan after each payment //printing results System.out.println("Monthly payment = " + Math.round(p));//errors on this line as well while (int p < 0) p = -359//Mortgage Table//this part is not finished yet b = l[(1 + r)^n - (1 + r)^p]/[(1 + r)^n - 1]; System.out.println("Balance = " + p); //counter used for loop p++; } } You never use payment anywhere, so you might as well get rid of that line. public class mortgage { public static void main(String[] args) { int l = 250000;//loan amount double r = 0.0048;//interest rate compounded monthly int n = 360;//number of payments int p = l[r(1 + r)^n]/[(1 + r)^n - 1]; // This is the new 'payment' int balance = b;//balance of loan after each payment //printing results System.out.println("Monthly payment = " + Math.round(p));//errors on this line as well while (int p < 0) p = -359//Mortgage Table//this part is not finished yet b = l[(1 + r)^n - (1 + r)^p]/[(1 + r)^n - 1]; System.out.println("Balance = " + p); //counter used for loop p++; } } The code function is acting up.. putting 2 lines on one thing.
post edited by Blizzie - Sunday, March 20, 2011 5:21 PM
|
Fadekraft
Superclocked Member
- Total Posts : 160
- Reward points : 0
- Joined: 11/6/2008
- Location: Denmark!
- Status: offline
- Ribbons : 0
Re:Anyone familiar with Java?
Sunday, March 20, 2011 5:23 PM
(permalink)
Blizzie, not entirely correct, the variable 'p' is being redefined in the while loop, actually that code should give you compiling errors, or it shouldn't work. Edit** You are missing a ';' after the p = -359
post edited by Shadowhunter22 - Sunday, March 20, 2011 5:27 PM
LnfinityX3: MB: ASUS P8Z68-V, Socket 1155 CPU: Intel i5-2500K CPU Cooling: Corsair H80 Hydro Series Watercooler RAM: 8GB Corsair 1600 DHX3 Dominators (/w fan) GPU: MSI 560 GTX Ti Twin Frozr II PSU: Corsair HX 850 Watt Case: Cooler Master CM 690 II Advanced (Black) OS: Windows 7 Ultimate x64
|
Blizzie
CLASSIFIED Member
- Total Posts : 3883
- Reward points : 0
- Joined: 7/4/2007
- Location: California
- Status: offline
- Ribbons : 17

Re:Anyone familiar with Java?
Sunday, March 20, 2011 5:27 PM
(permalink)
Shadowhunter22 Blizzie, not entirely correct, the variable 'p' is being redefined in the while loop, actually that code should give you compiling errors, or it shouldn't work. Oh I see. The while wasn't fully finished so I ignored it, whoops. They defined p again in there. So.. import java.math.*; public class mortgage { public static void main(String[] args) { int l = 250000;//loan amount double r = 0.0048;//interest rate compounded monthly int n = 360;//number of payments int balance = b;//balance of loan after each payment int p = l[r(1 + r)^n]/[(1 + r)^n - 1];//errors occur on this line int payment = p;//monthly payment; this is not used anywhere //printing results System.out.println("Monthly payment = " + Math.round(p));//errors on this line as well while (p < 0) { // stuff happens here p = -359;//Mortgage Table//this part is not finished yet } b = l[(1 + r)^n - (1 + r)^p]/[(1 + r)^n - 1]; System.out.println("Balance = " + p); //counter used for loop p++; } }
|
Fadekraft
Superclocked Member
- Total Posts : 160
- Reward points : 0
- Joined: 11/6/2008
- Location: Denmark!
- Status: offline
- Ribbons : 0
Re:Anyone familiar with Java?
Sunday, March 20, 2011 5:31 PM
(permalink)
import java.math.*; public class mortgage { public static void main(String[] args) { int l = 250000;//loan amount double r = 0.0048;//interest rate compounded monthly int n = 360;//number of payments int balance = b;//balance of loan after each payment int p = l[r(1 + r)^n]/[(1 + r)^n - 1]; //The reason for this error is because you are indexing the variable, but // it is not defined as an indexed variable. Define it as int[] p; // It still wont work since you are using variable 'l' as indexed aswell, and it // is not defined as indexed either int payment = p;//monthly payment //printing results System.out.println("Monthly payment = " + Math.round(p));//errors on this line as well while (p < 0) { // stuff happens here p = -359; //Mortgage Table//this part is not finished yet } b = l[(1 + r)^n - (1 + r)^p]/[(1 + r)^n - 1]; //Now you are indexing variable 'b', but it is not defined as indexed. System.out.println("Balance = " + p); //counter used for loop p++; } } You are taking a wrong approach to this problem, you are using the [] brackets wrong. Use () instead to avoid indexing, I'm not even sure you want to index. (And by 'you' i mean OP ;p)
post edited by Shadowhunter22 - Sunday, March 20, 2011 5:35 PM
LnfinityX3: MB: ASUS P8Z68-V, Socket 1155 CPU: Intel i5-2500K CPU Cooling: Corsair H80 Hydro Series Watercooler RAM: 8GB Corsair 1600 DHX3 Dominators (/w fan) GPU: MSI 560 GTX Ti Twin Frozr II PSU: Corsair HX 850 Watt Case: Cooler Master CM 690 II Advanced (Black) OS: Windows 7 Ultimate x64
|
Blizzie
CLASSIFIED Member
- Total Posts : 3883
- Reward points : 0
- Joined: 7/4/2007
- Location: California
- Status: offline
- Ribbons : 17

Re:Anyone familiar with Java?
Sunday, March 20, 2011 5:35 PM
(permalink)
What do you mean indexed variable? An array? Why would an array be needed? Edit: Nevermind.. I see it. The person is using [ ] to try to represent outer brackets for math operations. I just woke up, I am dumb  All of that would have been caught if I had a compiler. So the mathematical operation needs to be expressed in this way: int p = l(r(1 + r)^n) / ((1 + r)^n - 1); I am not sure if you want to do: r*((1+r)^n) or (r(1 + r))^n or etc I will leave this to you. I think shadow and I already beat this snippet of code to death. Post if you're confused.
post edited by Blizzie - Sunday, March 20, 2011 5:39 PM
|
Fadekraft
Superclocked Member
- Total Posts : 160
- Reward points : 0
- Joined: 11/6/2008
- Location: Denmark!
- Status: offline
- Ribbons : 0
Re:Anyone familiar with Java?
Sunday, March 20, 2011 5:36 PM
(permalink)
Exactly, array, not indexed, I'm expressing myself wrong. And yes exactly, there is no need for an array. Ahh nah, we were talking past each other! But yep, it's clear now whats wrong :p
post edited by Shadowhunter22 - Sunday, March 20, 2011 5:40 PM
LnfinityX3: MB: ASUS P8Z68-V, Socket 1155 CPU: Intel i5-2500K CPU Cooling: Corsair H80 Hydro Series Watercooler RAM: 8GB Corsair 1600 DHX3 Dominators (/w fan) GPU: MSI 560 GTX Ti Twin Frozr II PSU: Corsair HX 850 Watt Case: Cooler Master CM 690 II Advanced (Black) OS: Windows 7 Ultimate x64
|
Hugh Jass
SSC Member
- Total Posts : 983
- Reward points : 0
- Joined: 10/29/2008
- Location: Los Angeles, CA
- Status: offline
- Ribbons : 3

Re:Anyone familiar with Java?
Sunday, March 20, 2011 6:25 PM
(permalink)
joeomerta i use eclipse. takes care of everything in one place. +1 and its portable too! just install your jre, eclipse and setup the workspace on a flash drive
EVGA X58 E758 i7 930 4.2GHz EVGA GTX 660 heatWare
|
Rudster816
CLASSIFIED Member
- Total Posts : 2080
- Reward points : 0
- Joined: 8/4/2007
- Location: Eastern Washington
- Status: offline
- Ribbons : 18
Re:Anyone familiar with Java?
Sunday, March 20, 2011 6:50 PM
(permalink)
Order of operations in programming is tricky, so you need to use parenthesis in order to clear it up. You also should avoid complex calculations like that on a single line, because it makes it nearly impossible to see what that line does with just looking at it. Eclipse is a great IDE for Java, you really dont need to be using the command line to compile stuff. You also get debugging tools with an IDE like Eclipse.
[22:00:32] NordicJedi: the only way i can read this chatroom is if i imagine you're all dead 
|
SirMaster
FTW Member
- Total Posts : 1610
- Reward points : 0
- Joined: 7/2/2006
- Location: Sussex, WI
- Status: offline
- Ribbons : 21

Re:Anyone familiar with Java?
Sunday, March 20, 2011 11:17 PM
(permalink)
Yeah if you are going to be writing a lot of java or more complex programs you should try out an IDE like Eclipse or Netbeans. I recommend Netbeans if you are going to be doing a lot of GUI work.
|
blacksapphire08
Omnipotent Enthusiast
- Total Posts : 8447
- Reward points : 0
- Joined: 8/16/2010
- Status: offline
- Ribbons : 22

Re:Anyone familiar with Java?
Sunday, March 20, 2011 11:26 PM
(permalink)
I've been using NetBeans and it seems to work well as a code editor but its pretty vague when it comes to figuring out errors, i'm downloading Eclipse right now. I didnt know I could just use p = "equation" or that I shouldnt use [] in place of () but it does make sense now. Thanks for the tips guys, I really appreciate it.
|
blacksapphire08
Omnipotent Enthusiast
- Total Posts : 8447
- Reward points : 0
- Joined: 8/16/2010
- Status: offline
- Ribbons : 22

|
SirMaster
FTW Member
- Total Posts : 1610
- Reward points : 0
- Joined: 7/2/2006
- Location: Sussex, WI
- Status: offline
- Ribbons : 21

Re:Anyone familiar with Java?
Monday, March 21, 2011 5:08 PM
(permalink)
|