Reputation: 53
I'm having a problem running example code that came with textbook. I"m using JDK7
on OS X
Mountain Lion. StringMutation.java
compiles fine, but running java StringMutation.class
gives me the following error
Could not find or load main class StringMutation.class
.
I am running javac StringMutation.java and java StringMutation.class in same directory the StringMutation.java and StringMutation.class are located.
If it matters to know, I have Java SE7 set as the highest priority in Java Preferences. Thank for any help.
Here is the sample code:
public class StringMutation
{
public static void main (String[] args)
{
String phrase = "Change is inevitable";
String mutation1, mutation2, mutation3, mutation4;
System.out.println ("Original string: \"" + phrase + "\"");
System.out.println ("Length of string: " + phrase.length());
mutation1 = phrase.concat (", except from vending machines.");
mutation2 = mutation1.toUpperCase();
mutation3 = mutation2.replace ('E', 'X');
mutation4 = mutation3.substring (3, 30);
// Print each mutated string
System.out.println ("Mutation #1: " + mutation1);
System.out.println ("Mutation #2: " + mutation2);
System.out.println ("Mutation #3: " + mutation3);
System.out.println ("Mutation #4: " + mutation4);
System.out.println ("Mutated length: " + mutation4.length());
}
}
Upvotes: 3
Views: 708
Reputation: 1
If you use not empty package you need to run:
java <package>.<className>
Example: java com.test.MyClass
Upvotes: 0
Reputation: 23181
Don't include ".class" in the command. You need to run: java StringMutation
Upvotes: 1