Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    29
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    29
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #5
    New Coder
    Join Date
    May 2012
    Posts
    29
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    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.

  • #7
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,727
    Thanks
    41
    Thanked 191 Times in 190 Posts
    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

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •