Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Four Java files don't execute
Four Java files don't execute [message #1770457] Fri, 11 August 2017 18:32 Go to next message
RajibKumar Bandopadhyay is currently offline RajibKumar BandopadhyayFriend
Messages: 58
Registered: July 2014
Member
I followed Joseph P. Russell's book, Learn Java In A Weekend, ISBN: 1-931841-60-8
There are four complete codes for one particular program, explaining subclass and superclass.
The four files in Automobile.java.zip don't compile and show errors. Why?
It is said:
Quote:
Actually, you can add any
data type to a String literal, and the result will be interpreted as a String.
"The year is" + 2002
This creates a new string, even though the number 2002 isn't enclosed in quotation marks.
Java interprets anything that's added to a String literal as if it were itself a Java String
literal.The preceding code creates a new Java String : "The year is 2002".

But the codes are showing errors.

[Updated on: Fri, 11 August 2017 18:33]

Report message to a moderator

Re: Four Java files don't execute [message #1770467 is a reply to message #1770457] Sat, 12 August 2017 01:56 Go to previous messageGo to next message
Nitin Dahyabhai is currently online Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

What errors?

_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Four Java files don't execute [message #1770474 is a reply to message #1770467] Sat, 12 August 2017 06:07 Go to previous messageGo to next message
RajibKumar Bandopadhyay is currently offline RajibKumar BandopadhyayFriend
Messages: 58
Registered: July 2014
Member
Nitin Dahyabhai wrote on Fri, 11 August 2017 21:56
What errors?

Could you please unzip the files and peruse them in your Eclipse Platform?
Please find attached the error file Four_Programs.csv for your kind perusal.

Outside of Eclipse, in the Terminal, I had:
javac Automobile.java
Automobile.java:38: illegal character: \8220
String s = "Number of wheels: " + numWheels;
           ^
Automobile.java:38: ';' expected
String s = "Number of wheels: " + numWheels;
                     ^
Automobile.java:38: illegal character: \8220
String s = "Number of wheels: " + numWheels;
                              ^
Automobile.java:38: not a statement
String s = "Number of wheels: " + numWheels;
                                ^
Automobile.java:39: illegal character: \8220
s += "\nNumber of seats: " + numSeats;
     ^
Automobile.java:39: illegal character: \92
s += "\nNumber of seats: " + numSeats;
      ^
Automobile.java:39: ';' expected
s += "\nNumber of seats: " + numSeats;
              ^
Automobile.java:39: ';' expected
s += "\nNumber of seats: " + numSeats;
                       ^
Automobile.java:39: illegal character: \8220
s += "\nNumber of seats: " + numSeats;
                         ^
Automobile.java:39: not a statement
s += "\nNumber of seats: " + numSeats;
                             ^
Automobile.java:40: illegal character: \8220
s += "\nColor: " + color;
     ^
Automobile.java:40: illegal character: \92
s += "\nColor: " + color;
      ^
Automobile.java:40: ';' expected
s += "\nColor: " + color;
             ^
Automobile.java:40: illegal character: \8220
s += "\nColor: " + color;
               ^
Automobile.java:40: not a statement
s += "\nColor: " + color;
                   ^
Automobile.java:41: illegal character: \8220
s += "\nMileage: " + mileage;
     ^
Automobile.java:41: illegal character: \92
s += "\nMileage: " + mileage;
      ^
Automobile.java:41: ';' expected
s += "\nMileage: " + mileage;
               ^
Automobile.java:41: illegal character: \8220
s += "\nMileage: " + mileage;
                 ^
Automobile.java:41: not a statement
s += "\nMileage: " + mileage;
                     ^
Automobile.java:42: illegal character: \8220
s += "\nEngine running: " + engineRunning;
     ^
Automobile.java:42: illegal character: \92
s += "\nEngine running: " + engineRunning;
      ^
Automobile.java:42: ';' expected
s += "\nEngine running: " + engineRunning;
              ^
Automobile.java:42: illegal character: \8220
s += "\nEngine running: " + engineRunning;
                        ^
Automobile.java:42: not a statement
s += "\nEngine running: " + engineRunning;
                          ^
25 errors


javac AutomobileTest.java
AutomobileTest.java:12: illegal character: \8220
Automobile auto = new Automobile(4, 2, "red");
                                       ^
AutomobileTest.java:12: ';' expected
Automobile auto = new Automobile(4, 2, "red");
                                        ^
AutomobileTest.java:12: illegal character: \8221
Automobile auto = new Automobile(4, 2, "red");
                                           ^
AutomobileTest.java:12: ';' expected
Automobile auto = new Automobile(4, 2, "red");
                                            ^
AutomobileTest.java:13: illegal character: \8220
System.out.println("Created new automobile:");
                   ^
AutomobileTest.java:13: ';' expected
System.out.println("Created new automobile:");
                    ^
AutomobileTest.java:13: '(' or '[' expected
System.out.println("Created new automobile:");
                                          ^
AutomobileTest.java:13: illegal character: \8221
System.out.println("Created new automobile:");
                                           ^
AutomobileTest.java:13: ';' expected
System.out.println("Created new automobile:");
                                            ^
AutomobileTest.java:16: illegal character: \8220
System.out.println("Started Engine");
                   ^
AutomobileTest.java:16: ';' expected
System.out.println("Started Engine");
                    ^
AutomobileTest.java:16: illegal character: \8221
System.out.println("Started Engine");
                                  ^
AutomobileTest.java:16: not a statement
System.out.println("Started Engine");
                            ^
AutomobileTest.java:18: illegal character: \8220
auto.color = "black";
             ^
AutomobileTest.java:18: illegal character: \8221
auto.color = "black";
                   ^
AutomobileTest.java:18: not a statement
auto.color = "black";
              ^
AutomobileTest.java:19: illegal character: \8220
System.out.println("Painted it black");
                   ^
AutomobileTest.java:19: ';' expected
System.out.println("Painted it black");
                    ^
AutomobileTest.java:19: illegal character: \8221
System.out.println("Painted it black");
                                    ^
AutomobileTest.java:21: illegal character: \8220
System.out.println("Drove it 12.8 miles");
                   ^
AutomobileTest.java:21: ';' expected
System.out.println("Drove it 12.8 miles");
                    ^
AutomobileTest.java:21: not a statement
System.out.println("Drove it 12.8 miles");
                          ^
AutomobileTest.java:21: ';' expected
System.out.println("Drove it 12.8 miles");
                            ^
AutomobileTest.java:21: illegal character: \8221
System.out.println("Drove it 12.8 miles");
                                       ^
AutomobileTest.java:21: not a statement
System.out.println("Drove it 12.8 miles");
                                  ^
AutomobileTest.java:22: illegal character: \8220
System.out.println("Here are the results:");
                   ^
AutomobileTest.java:22: ';' expected
System.out.println("Here are the results:");
                    ^
AutomobileTest.java:22: ';' expected
System.out.println("Here are the results:");
                                ^
AutomobileTest.java:22: illegal character: \8221
System.out.println("Here are the results:");
                                         ^
AutomobileTest.java:22: illegal start of expression
System.out.println("Here are the results:");
                                          ^
30 errors


javac Truck.java
Truck.java:47: illegal character: \8220
s += "\nHas trailer: " + hasTrailer;
     ^
Truck.java:47: illegal character: \92
s += "\nHas trailer: " + hasTrailer;
      ^
Truck.java:47: ';' expected
s += "\nHas trailer: " + hasTrailer;
           ^
Truck.java:47: illegal character: \8220
s += "\nHas trailer: " + hasTrailer;
                     ^
Truck.java:47: not a statement
s += "\nHas trailer: " + hasTrailer;
                       ^
Truck.java:48: illegal character: \8220
s += "\nTailer full: " + trailerFull;
     ^
Truck.java:48: illegal character: \92
s += "\nTailer full: " + trailerFull;
      ^
Truck.java:48: ';' expected
s += "\nTailer full: " + trailerFull;
              ^
Truck.java:48: illegal character: \8220
s += "\nTailer full: " + trailerFull;
                     ^
Truck.java:48: not a statement
s += "\nTailer full: " + trailerFull;
                       ^
Truck.java:49: illegal character: \8220
s += "\nTrailer mileage: " + trailerMileage;
     ^
Truck.java:49: illegal character: \92
s += "\nTrailer mileage: " + trailerMileage;
      ^
Truck.java:49: ';' expected
s += "\nTrailer mileage: " + trailerMileage;
               ^
Truck.java:49: illegal character: \8220
s += "\nTrailer mileage: " + trailerMileage;
                         ^
Truck.java:49: not a statement
s += "\nTrailer mileage: " + trailerMileage;
                           ^
15 errors


javac TruckTest.java
TruckTest.java:10: illegal character: \8220
Truck truck = new Truck("silver");
                        ^
TruckTest.java:10: ';' expected
Truck truck = new Truck("silver");
                         ^
TruckTest.java:10: illegal character: \8221
Truck truck = new Truck("silver");
                               ^
TruckTest.java:10: ';' expected
Truck truck = new Truck("silver");
                                ^
TruckTest.java:11: illegal character: \8220
System.out.println("Created a new truck:");
                   ^
TruckTest.java:11: ';' expected
System.out.println("Created a new truck:");
                    ^
TruckTest.java:11: not a statement
System.out.println("Created a new truck:");
                            ^
TruckTest.java:11: ';' expected
System.out.println("Created a new truck:");
                             ^
TruckTest.java:11: illegal character: \8221
System.out.println("Created a new truck:");
                                        ^
TruckTest.java:11: illegal start of expression
System.out.println("Created a new truck:");
                                         ^
TruckTest.java:15: illegal character: \8220
System.out.println("Started engine and attached trailer");
                   ^
TruckTest.java:15: ';' expected
System.out.println("Started engine and attached trailer");
                    ^
TruckTest.java:15: ';' expected
System.out.println("Started engine and attached trailer");
                                      ^
TruckTest.java:15: illegal character: \8221
System.out.println("Started engine and attached trailer");
                                                       ^
TruckTest.java:17: illegal character: \8220
System.out.println("Loaded trailer");
                   ^
TruckTest.java:17: ';' expected
System.out.println("Loaded trailer");
                    ^
TruckTest.java:17: illegal character: \8221
System.out.println("Loaded trailer");
                                  ^
TruckTest.java:17: not a statement
System.out.println("Loaded trailer");
                           ^
TruckTest.java:22: illegal character: \8220
System.out.println("Delivered load 127.75 miles away "
                   ^
TruckTest.java:22: ';' expected
System.out.println("Delivered load 127.75 miles away "
                    ^
TruckTest.java:22: not a statement
System.out.println("Delivered load 127.75 miles away "
                              ^
TruckTest.java:22: ';' expected
System.out.println("Delivered load 127.75 miles away "
                                  ^
TruckTest.java:22: illegal character: \8220
System.out.println("Delivered load 127.75 miles away "
                                                     ^
TruckTest.java:23: illegal character: \8220
		+ "and drove back empty to get another load");
		  ^
TruckTest.java:23: ';' expected
		+ "and drove back empty to get another load");
		            ^
TruckTest.java:23: ';' expected
		+ "and drove back empty to get another load");
		                       ^
TruckTest.java:23: ';' expected
		+ "and drove back empty to get another load");
		                              ^
TruckTest.java:23: illegal character: \8221
		+ "and drove back empty to get another load");
		                                           ^
28 errors

[Updated on: Sat, 12 August 2017 07:15]

Report message to a moderator

Re: Four Java files don't execute [message #1770479 is a reply to message #1770474] Sat, 12 August 2017 08:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
The files all contain bogus “ and ”instead of ". I know the difference is subtle to see. Replace every strange double quote with the proper expected double quote you get from your keyboard.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Four Java files don't execute [message #1770482 is a reply to message #1770479] Sat, 12 August 2017 12:48 Go to previous messageGo to next message
RajibKumar Bandopadhyay is currently offline RajibKumar BandopadhyayFriend
Messages: 58
Registered: July 2014
Member
Thank you! You are my teacher! I should have noticed! This had happened once while I was writing Adobe(then Macromedia) Flash program, many years back. I should have remembered.
Error repetition is a sin in programming!
But how come the debuggers could not catch the errors?

[Updated on: Sat, 12 August 2017 13:11]

Report message to a moderator

Re: Four Java files don't execute [message #1770489 is a reply to message #1770482] Sat, 12 August 2017 15:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
If it doesn't compile, it doesn't debug. The compiler already points out where the problem starts with an error message...

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Four Java files don't execute [message #1770490 is a reply to message #1770489] Sat, 12 August 2017 16:21 Go to previous messageGo to next message
RajibKumar Bandopadhyay is currently offline RajibKumar BandopadhyayFriend
Messages: 58
Registered: July 2014
Member
Quote:
If it doesn't compile, it doesn't debug.
Okay, thanks!
Have you perused the Four_Programs.csv created by Eclipse, attached earlier? How do I interpret the error codes in that file? It doesn't say about the '' marks.

[Updated on: Sat, 12 August 2017 16:22]

Report message to a moderator

Re: Four Java files don't execute [message #1770502 is a reply to message #1770490] Sat, 12 August 2017 20:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
I did and it marked that location as an unexpected token. Clearly this is not a common/typical problem that warrants special handling for more helpful error messages.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Four Java files don't execute [message #1770504 is a reply to message #1770502] Sun, 13 August 2017 02:38 Go to previous message
RajibKumar Bandopadhyay is currently offline RajibKumar BandopadhyayFriend
Messages: 58
Registered: July 2014
Member
Okay. I understood. Thanks.
Previous Topic:Bug? Convert to Maven Project
Next Topic:caps lock reversed
Goto Forum:
  


Current Time: Thu Apr 25 21:44:04 GMT 2024

Powered by FUDForum. Page generated in 0.08321 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top