Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-24-2012, 07:20 PM   PM User | #1
Jemdt
New Coder

 
Join Date: May 2012
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
Jemdt is an unknown quantity at this point
Java file will not compile

Hi, I'm completely brand new to Java, and have been learning from the books.

In one of the book exercises, I was supposed to copy and paste two scripts (VolcanoApplication.java & VolcanoRobot.java) and compile VolcanoApplication.java so I could run the program. Unfortunately, whenever try to compile VolcanoApplication.java in Cmd (Javac C:\ etc.), no class file is created and I get this error message:



I copied the code exactly from the book:

VolcanoApplication.java:

Code:
class VolcanoApplication {
   public static void main(String[] arguments) {
        VolcanoRobot dante = new VolcanoRobot();
        dante.status = “exploring”;
        dante.speed = 2;
        dante.temperature = 510;

        dante.showAttributes();
        System.out.println(“Increasing speed to 3.”);
        dante.speed = 3;
        dante.showAttributes();
        System.out.println(“Changing temperature to 670.”);
        dante.temperature = 670;
        dante.showAttributes();
        System.out.println(“Checking the temperature.”);
        dante.checkTemperature();
        dante.showAttributes();
    }
}
VolcanoRobot.java

Code:
class VolcanoRobot {
    String status; 
    int speed; 
    float temperature; 
	  
	  
    void checkTemperature() {
    if (temperature > 660) {
    status = “returning home”;
    speed = 5;
        
		}
    }

		
void showAttributes() {
    System.out.println(“Status: “ + status);
    System.out.println(“Speed: “ + speed);
    System.out.println(“Temperature: “ + temperature);
       }
    }
I'm sure there must be a simple fix for this, but as I'm completely new to Java, I have no idea what to do. Please help!

Thanks

James
Jemdt is offline   Reply With Quote
Old 05-24-2012, 08:00 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Look at your quotations. Those are characters, not quotations themselves, you need to modify them and replace them with proper ".
Everything else looks fine, so once the quotes are fixed you can compile VolcanoRobot and then VolcanoApplication.
Fou-Lu is offline   Reply With Quote
Old 05-24-2012, 08:13 PM   PM User | #3
Jemdt
New Coder

 
Join Date: May 2012
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
Jemdt is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
Look at your quotations. Those are characters, not quotations themselves, you need to modify them and replace them with proper ".
Everything else looks fine, so once the quotes are fixed you can compile VolcanoRobot and then VolcanoApplication.
Thanks, that fixed that problem, however, I'm still receiving 2 errors after I changed the quotations. I've tried tampering around with the code, but nothing works.



Do you not what I'm doing wrong here? thanks.
Jemdt is offline   Reply With Quote
Old 05-25-2012, 12:33 AM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Looks to me like its a compilation order issue. Its been awhile since Ive clid a javac, but this is what I did (I made a package btw):
Code:
D:\Projects\JavaTest\src>set path=%PATH%;"C:\Program Files\Java\jdk1.7.0_04"\bin
D:\Projects\JavaTest\src>javac -d . volcano\VolcanoApplication.java

D:\Projects\JavaTest\src>java volcano.VolcanoApplication
Status: exploring
Speed: 2
Temperature: 510.0
Increasing speed to 3.
Status: exploring
Speed: 3
Temperature: 510.0
Changing temperature to 670.
Status: exploring
Speed: 3
Temperature: 670.0
Checking the temperature.
Status: returning home
Speed: 5
Temperature: 670.0
I've always hated the cli javac; fortunately most IDE's make that easy for you.
Fou-Lu is offline   Reply With Quote
Old 05-25-2012, 05:54 PM   PM User | #5
Jemdt
New Coder

 
Join Date: May 2012
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
Jemdt is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
Looks to me like its a compilation order issue. Its been awhile since Ive clid a javac, but this is what I did (I made a package btw):
Code:
D:\Projects\JavaTest\src>set path=%PATH%;"C:\Program Files\Java\jdk1.7.0_04"\bin
D:\Projects\JavaTest\src>javac -d . volcano\VolcanoApplication.java

D:\Projects\JavaTest\src>java volcano.VolcanoApplication
Status: exploring
Speed: 2
Temperature: 510.0
Increasing speed to 3.
Status: exploring
Speed: 3
Temperature: 510.0
Changing temperature to 670.
Status: exploring
Speed: 3
Temperature: 670.0
Checking the temperature.
Status: returning home
Speed: 5
Temperature: 670.0
I've always hated the cli javac; fortunately most IDE's make that easy for you.
Thanks, what IDE should I use?
Jemdt is offline   Reply With Quote
Old 05-29-2012, 07:26 AM   PM User | #6
dan-dan
Regular Coder

 
dan-dan's Avatar
 
Join Date: Aug 2009
Location: England
Posts: 483
Thanks: 22
Thanked 79 Times in 78 Posts
dan-dan is on a distinguished road
I'm just nearing the end of that same book. Still have my working example of that code:
PHP Code:
class VolcanoRobot {
    
String status;
    
int speed;
    
float temperature;
    
    
void checkTemperature() {
        if (
temperature 660) {
            
status "returning home";
            
speed 5;
        }
    }
    
void showAttributes() {
        
System.out.println("Status: " status);
        
System.out.println("Speed: " speed);
        
System.out.println("Temperature: " temperature);
    }

PHP Code:
class VolcanoApplication {
    public static 
void main(String[] args) {
        
VolcanoRobot dante = new VolcanoRobot();
        
dante.status "exploring";
        
dante.speed 2;
        
dante.temperature 510;
        
        
dante.showAttributes();
        
System.out.println("Increasing speed to 3.");
        
dante.speed 3;
        
dante.showAttributes();
        
System.out.println("Changing temperature to 670.");
        
dante.temperature 670;
        
dante.showAttributes();
        
System.out.println("Checking the temperature.");
        
dante.checkTemperature();
        
dante.showAttributes();
    }

I've used Notepad++, Netbeans and Eclipse. I've definately found Eclipse to be the better of the 3 for Java.
dan-dan is offline   Reply With Quote
Old 05-29-2012, 06:59 PM   PM User | #7
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
Eclipse is (even though I hate it and wish it was visual studio) excellent. I would get familiar with debug mode and watch window etc. You can learn a lot just from debugging. Also and IDE like Eclipse will attempt to precompile the code and it will throw up at errors like that- and will even underline them in little squiggles letting you know something is wrong. It also has (if I am remembering correctly) color coding so you would see it propagating down (although Notepad++ does that too)
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 05-29-2012, 07:05 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I'm a third for the Eclipse. I use it for both Java and PHP.
Yep to colour syntax (customizable as well as the formatting), auto completion available, scoping, auto format, debuggers, and lots of other fun stuff. Then you just hit the run / debug button and it compiles automatically. Exporting to a jar is also very easy to do.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:28 AM.


Advertisement
Log in to turn off these ads.