Re: java 101 question - how to run a java program



You skipped a very important step. Go back and rename the source file from .class to .java, then STRQSH, cd /home/srichter/java, and do "javac java01.java".

After you've corrected your source error (need to call the class "java01" if it's in file "java01.java"), you will end up with a ..class file in the same directory as the .java file.

Then just do "java java01" (or whatever you named it). No need to do CRTJVAPGM -- that's done implicitly when you execute the .class file the first time.

Steve Richter wrote:
working entirely from the as400 green screen ....

I create a stream file with some java source code:

class Example {
public static void main( String args[]) {
System.out.println( "This is a simple Java program." ) ;
}
}

file name is /home/srichter/java/java01.class

I compile the program:
CD DIR('/home/srichter/java')
CRTJVAPGM CLSF(java01.class)

========> first question: the program compiles successfully. Where
does the system place it? After the compile the /home/srichter/java
directory does not contain any new object. just the one source file.

Now I want to run this program ( from the green screen )
CD DIR('/home/srichter/java')
RUNJVA CLASS(java01.class) CLASSPATH(Example)

I try all different variations on the theme of running the java01
class file and the Example class it contains with no success. A lot
of "NoClassDefFoundError" errors.

How do I run my simple java program?

thanks,

Steve Richter



--
Dan Hicks
Change is inevitable -- except from a vending machine.

.



Relevant Pages

  • Re: Larkin, Power BASIC cannot be THAT good:
    ... headers), and no platform-specific macros. ... one source file. ... doesn't have classes, Java doesn't have pointers, or half of C++'s OO ... So the only languages that allow 40-year old programs to be simply ...
    (sci.electronics.design)
  • Re: functional decomposition and abstraction.
    ... So object-oriented programming is a lot easier in C++ and Java, ... A C source file, if written with globals whose scope is ... functions in that file) is very close indeed to a Java class. ... "The public education system in America is one of the most ...
    (comp.lang.java.programmer)
  • Re: Can .py be complied?
    ... But I found that the .py file is just like the source file, how can I make a program without revealing its source? ... For now, you can use pyfreeze to snap the application, which is to bundle your application to a python interpreter as a package but this will not create a portable application. ... Program in python but use jythonc to convert it into Java source files and package it into Java JAR files, then you will only need to release the JAR files without needing to release your codes. ...
    (comp.lang.python)
  • Re: eMac
    ... its source file location and its class file location. ... I understand but my goal is to send a java file to somebody who is not even a newbe. ... You really should get in the habit of naming your classes with an upper-case first letter: ... You still need to understand the issues highlighted, even if your recipient doesn't. ...
    (comp.lang.java.help)
  • Re: two public class in a file
    ... When Java finds a reference to a public class it can calculate what ... source file on the sourcepath. ... http://mindprod.com Java custom programming, consulting and coaching. ...
    (comp.lang.java.programmer)

Loading