Output When Running File
#1
Posted 08 February 2011 - 09:39 PM
/**
* @(#)Calculate.java
*
*
* @author
* @version 1.00 2011/2/8
*/
public class Calculate {
public static void main(String args[]) {
int number1;
int number2;
System.out.print( "Enter first integer:");
number1=input.nextInt();
System.out.print("Enter second integer:");
number2=input.nextInt();
//display results
System.out.printf( "\nSum is %d\n", ( number1+number2));
System.out.printf("Product is %d\n", (number 1*number2));
System.out.printf("Difference is %d\n", (number1-number2));
}//end main
}//end class Calculate
#2
Posted 11 February 2011 - 06:18 PM
//Fig. 2.1: Welcome1.java
//Text-printing program.
public class Welcome1
{
// main method begins execution of Java application
public static void main( String[] args )
{
System.out.println( "Welcome to Java Programming!" );
} // end method main
} //end class Welcome 1
#3
Posted 13 February 2011 - 09:32 PM
If it is a problem with JCreator then I would first look and see if your the path to your JDK is configured correctly. On the menu, go to Configure -> Options -> JDK Profiles. Click new and find the directory of the Java JDK.
If it is not a problem with compiling the program but running it, I am not sure how to configure the path of the JRE. I might try installing the JRE then re-installing JCreator.
#4
Posted 16 February 2011 - 12:05 AM
FireFox54, on 13 February 2011 - 09:32 PM, said:
If it is a problem with JCreator then I would first look and see if your the path to your JDK is configured correctly. On the menu, go to Configure -> Options -> JDK Profiles. Click new and find the directory of the Java JDK.
If it is not a problem with compiling the program but running it, I am not sure how to configure the path of the JRE. I might try installing the JRE then re-installing JCreator.
#5
Posted 16 February 2011 - 01:01 AM
#6
Posted 16 February 2011 - 01:46 AM
C:\Program Files\Java\jdk1.6.0_11\bin>javac.exe c:\welcome1.java
C:\Program Files\Java\jdk1.6.0_11\bin>
Lofland_00, on 16 February 2011 - 12:05 AM, said:
#7
Posted 16 February 2011 - 02:52 AM
If you don't understand this tell me what you understand the JDK, the compiler, the JRE, and the interpreter is and I will the try to explain it to you.
Lofland_00, on 16 February 2011 - 01:46 AM, said:
C:\Program Files\Java\jdk1.6.0_11\bin>javac.exe c:\welcome1.java
C:\Program Files\Java\jdk1.6.0_11\bin>
#8
Posted 16 February 2011 - 03:12 AM
Exception in thread "main" java.lang.NoClassDefFoundError: c:\welcome1/class
Caused by: java.lang.ClassNotFoundException: c:\welcome1.class
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: c:\welcome1.class. Program will exit.
FireFox54, on 16 February 2011 - 02:52 AM, said:
If you don't understand this tell me what you understand the JDK, the compiler, the JRE, and the interpreter is and I will the try to explain it to you.
#9
Posted 16 February 2011 - 03:29 AM
1. In your program Welcome1 had a uppercase 'w' . In the command window, you put a lowercase w. Java is case sensitive.
2. When you use the interpreter, you shouldn't put the filename extension. The interpreter will automatically knows that the file extension will be either .jar or .class .
Try running with the command -> java Welcome1
Lofland_00, on 16 February 2011 - 03:12 AM, said:
Exception in thread "main" java.lang.NoClassDefFoundError: c:\welcome1/class
Caused by: java.lang.ClassNotFoundException: c:\welcome1.class
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: c:\welcome1.class. Program will exit.
#10
Posted 16 February 2011 - 02:21 PM
Exception in thread "main" java.lang.NoClassDefFoundError: Welcome1
Caused by: java.lang.ClassNotFoundException: Welcome1
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Welcome1. Program will exit.
FireFox54, on 16 February 2011 - 03:29 AM, said:
1. In your program Welcome1 had a uppercase 'w' . In the command window, you put a lowercase w. Java is case sensitive.
2. When you use the interpreter, you shouldn't put the filename extension. The interpreter will automatically knows that the file extension will be either .jar or .class .
Try running with the command -> java Welcome1
#11
Posted 16 February 2011 - 05:59 PM
Lofland_00, on 16 February 2011 - 02:21 PM, said:
Exception in thread "main" java.lang.NoClassDefFoundError: Welcome1
Caused by: java.lang.ClassNotFoundException: Welcome1
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Welcome1. Program will exit.
#12
Posted 17 February 2011 - 02:00 PM
That worked.
C:\>java Welcome1
Welcome to Java Programming!
That Worked....so now the question is what am I doing wrong in JCreator? If all else fails..I can build in JCreator and then run in Cmd prompt to test right?
FireFox54, on 16 February 2011 - 05:59 PM, said:
#13
Posted 17 February 2011 - 05:11 PM
You can test / run in JCreator. To do this, make sure the file you are working on is contained in the active project.
Right click on the project that the file is in and click "Set as Active Project"
Click F5 to test / run the file with the main method in the active project
If you want to build or run an individual file go to the build / run menu and click build file / run file.
(btw if you tell JCreator to run the file it will automatically compile it before running.)
Lofland_00, on 17 February 2011 - 02:00 PM, said:
That worked.
C:\>java Welcome1
Welcome to Java Programming!
That Worked....so now the question is what am I doing wrong in JCreator? If all else fails..I can build in JCreator and then run in Cmd prompt to test right?
#14
Posted 15 March 2011 - 08:25 PM
/**
* @(#)GradeBook.java
*
* GradeBook application
*
* @author
* @version 1.00 2011/3/14
*/
class GradeBook
{
// display a welcome message to the GradeBook User
public void displayMessage ( String courseName )
{
System.out.println( "Welcome to the Grade Book for\n%!\n!", courseName );
}//end method displayMessage
}//end class GradeBook
import java.util.Scanner; //program uses Scanner
public class GradeBookTest
{
//main method begins program execution
public static void main(String args[] )
{
//create Scanner to obtain input from command window
Scanner input = new Scanner( System.in);
// create a GradeBook object and asisgn it to myGradeBook
GradeBook myGradeBook = new GradeBook();
//prompt for and input course name
System.out.println( "Please enter the course name:" );
String nameOfCourse = input.nextLine(); //read a line of text
System.out.println(); //outputs a blank line
//call myGradeBook's displayMessage method
myGradebook.displayMessage ( nameOfCourse );
}//end main
}//end class GradeBookTest
then I get this error when trying to run?
/**
* @(#)GradeBook.java
*
* GradeBook application
*
* @author
* @version 1.00 2011/3/14
*/
class GradeBook
{
// display a welcome message to the GradeBook User
public void displayMessage ( String courseName )
{
System.out.println( "Welcome to the Grade Book for\n%!\n!", courseName );
}//end method displayMessage
}//end class GradeBook
import java.util.Scanner; //program uses Scanner
public class GradeBookTest
{
//main method begins program execution
public static void main(String args[] )
{
//create Scanner to obtain input from command window
Scanner input = new Scanner( System.in);
// create a GradeBook object and asisgn it to myGradeBook
GradeBook myGradeBook = new GradeBook();
//prompt for and input course name
System.out.println( "Please enter the course name:" );
String nameOfCourse = input.nextLine(); //read a line of text
System.out.println(); //outputs a blank line
//call myGradeBook's displayMessage method
myGradebook.displayMessage ( nameOfCourse );
}//end main
}//end class GradeBookTest
Then I get this error when trying to run in command prompt:
C:\Users\kathy.kimbrough\Documents\World College\Java\Assignments\Gradebook>java
GradeBook
Exception in thread "main" java.lang.NoClassDefFoundError: GradeBook
Caused by: java.lang.ClassNotFoundException: GradeBook
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: GradeBook. Program will exit.
FireFox54, on 17 February 2011 - 05:11 PM, said:
You can test / run in JCreator. To do this, make sure the file you are working on is contained in the active project.
Right click on the project that the file is in and click "Set as Active Project"
Click F5 to test / run the file with the main method in the active project
If you want to build or run an individual file go to the build / run menu and click build file / run file.
(btw if you tell JCreator to run the file it will automatically compile it before running.)
#15
Posted 16 March 2011 - 01:08 AM
Btw, unlike JCreator, the command prompt will not automatically compile when you tell it to run a project.
#16
Posted 16 March 2011 - 02:21 PM
#17
Posted 16 March 2011 - 05:35 PM
If there is not a folder named "classes" check to see if JCreator or the cmd prompt gives you any errors when you try to compile. If JCreator, doesn't give you any errors, it is probably creating the .class file
Lofland_00, on 16 March 2011 - 02:21 PM, said:
#18
Posted 16 March 2011 - 06:09 PM
c GradeBook.java
GradeBook.java:19: class, interface, or enum expected
import java.util.Scanner; //program uses Scanner
^
1 error
#19
Posted 17 March 2011 - 05:28 PM
Lofland_00, on 16 March 2011 - 06:09 PM, said:
c GradeBook.java
GradeBook.java:19: class, interface, or enum expected
import java.util.Scanner; //program uses Scanner
^
1 error











