File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Java Code Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Code Error" Watch "Java Code Error" New topic

Java Code Error

Trae Carrington

Joined: Feb 01, 2008
Posts: 2
Just now getting into java with Head First Java trying to run the following code and get the error ';' expected
If(x==3) {

What is wrong?

public class DooBee {
public static void main (String[] args){
int x = 1;
while(x<3) {
If(x==3) {
Joe Ess

Joined: Oct 29, 2001
Posts: 9168

Welcome to the JavaRanch.
Java is case-sensitive. The word "if" is different from the word "If". "if" is used for flow control. "If" is undefined, and since it is followed by parenthesis, the compiler assumes you are referencing a method named "If" and complains because you haven't terminated the method call with a ";".

[How To Ask Questions On JavaRanch]
Trae Carrington

Joined: Feb 01, 2008
Posts: 2
Thanks for the help. Still new at it rather than just move on I always try to find out what causes an error so don't pick up a bad habit.
It is sorta covered in the JavaRanch Style Guide.
subject: Java Code Error
It's not a secret anymore!