View Full Version : problems starting java
java2
10-09-2005, 07:45 PM
Hi, i have just installed a java compiler and wrote my first java program, copied directly from a java book. UNfortunatley it found errors in one of my lines and more precisley didn't like the full stops.
this is the program...
public class FirstVar
{
public static void main(String[] args)
{
String str = "First value";
System.out.printIn(str);
str = "Second Value";
System.out.printIn(str);
}
}
it worked for the people who wrote the book, why won't it work for me??!!! please help
little_toaster
10-09-2005, 08:00 PM
ITS BEEN A LONG TIME SINCE I DID JAVA!, I think str is a reserved word!, try a different string name!
java2
10-09-2005, 08:02 PM
I also had the same problem with this program
public class Hello
{
public static void main (String[] args)
{
system.out.printIn("Hello World");
}
}
little_toaster
10-09-2005, 08:04 PM
capital S on system
java2
10-09-2005, 08:05 PM
o yeah just noticed that. but look at my second example
Brandoe85
10-09-2005, 08:23 PM
System.out.println("Hello World");
You had a I instead of an l.
little_toaster
10-09-2005, 08:24 PM
I noticed that but for some strange reason decided that it was thew font on the forum that made it look like a i!
lol!
maybe i will relearn Java myself!
java2
10-09-2005, 08:25 PM
nope doesn't like that one either. It does show me where the error is and its telling me its on the second full stop. the one before 'print'
Brandoe85
10-09-2005, 08:33 PM
Both of the examples you posted are working for me when I make that change:
Hello.java
public class Hello
{
public static void main (String[] args)
{
System.out.println("Hello World");
}
}
EDIT: What is the error message?
java2
10-09-2005, 08:50 PM
o you mean its a little L. i see now. thankyou very much
java2
10-09-2005, 10:55 PM
Well now i have a new problem, i can now compile the programs but i can't get them to run.
This is the message the command prompt gives me...
Exception in thread "main" java.lang>NoClassDefFoundError: Then the file name
Brandoe85
10-09-2005, 11:29 PM
Is your class name and file name saved exactly the same?
class name Hello
and you saved the file as Hello.java?
java2
10-09-2005, 11:30 PM
Yep the compiler does that automatically
Brandoe85
10-09-2005, 11:39 PM
Post your code, and someone can have a look.
java2
10-09-2005, 11:43 PM
class Hello
{
public static void main (String[] args)
{
System.out.println("Hello World");
}
}
KeZZeR
10-10-2005, 11:46 PM
Have you named the class file to Hello.java? It has to be exact otherwise it won't like it
Public class Hello
{
public static void main (String[] args)
{
System.out.println("Hello World");
}
}
Save as Hello.java
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.