CLASS PATH:-
If you get any message like this, $ java HelloWorld
Can't find class HelloWorld
it probably means your CLASSPATH environment variable isn't properly set up. Make sure it includes the current directory as well as the location where the classes.zip file was installed. On Unix it should look something like this:
CLASSPATH=.:/usr/local/java-1.1/lib
Under Windows it will probably look something like this
C:\JDK\JAVA\CLASSES;c:\java\lib\classes.zip
Under Unix you set CLASSPATH variables like this:
csh: % setenv CLASSPATH my_class_path
sh: % CLASSPATH=my_class_path
You'll probably want to add one of these lines to your .login or .cshrc file so it will be automatically set every time.
Under Windows you set the CLASSPATH environment variable with a DOS command like
C:\> SET CLASSPATH=C:\JDK\JAVA\CLASSES;c:\java\lib\classes.zip
You can also add this to your autoexec.bat file (Windows ME and earlier) or set it in the environment variables tab of the System control panel (Windows NT and later) You should of course point it at whichever directories actually contain your classes.
The CLASSPATH variable is also important when you run Java applets, not just when you compile them. It tells the web browser or applet viewer where it should look to find the referenced .class files. If the CLASSPATH is set improperly, you'll probably see messages like "Applet could not start."
If the CLASSPATH environment variable has not been set, and you do not specify one on the command line, then Java sets the CLASSPATH to the default:
Unix: .:$JAVA/classes:$JAVA/lib/classes.zip
Windows: .:$JAVA\classes:$JAVA\lib\classes.zip
Mac: ./$JAVA:classes/$JAVA:lib:classes.zip
Here . is the current directory and $JAVA is the main Java directory where the different tools like javac were installed.
for loop:-
sclass Count {
public static void main (String args[]) {
int i;
for (i = 0; i < 50; i=i+1) {
System.out.println(i);
}
}
}
Example.
Variable declaration inside for loop.class Count {
public static void main (String args[]) {
for (int i = 0; i < 50; i = i+1) {
System.out.println(i);
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment