common errors

31
Common Errors and Solutions CST200 – Week 1: Common Errors when Starting to write and compile Java Code Instructor: Andreea Molnar

Upload: andreeamolnar

Post on 23-Jun-2015

2.510 views

Category:

Software


3 download

TRANSCRIPT

Page 1: Common errors

Common Errors and Solutions

CST200 – Week 1: Common Errors when Starting to write and compile Java Code

Instructor: Andreea Molnar

Page 2: Common errors

Outline

• Disclaimer

• Names

• Brackets

• Semicolons

Page 3: Common errors

Error Category

Page 4: Common errors

Names

Page 5: Common errors

Names (e.g. class names, variable names, method names) are a single string!

Page 6: Common errors

public class Hello World {

}

Is the class name Hello or

World?

Page 7: Common errors

public class Hello World {

}

After the first string –Hello –

a bracket is expected.

Page 8: Common errors

public class Hello World {

}

Page 9: Common errors

public class Hello World {

}

Page 10: Common errors

public class HelloWorld {

}

public class Hello {

}

public class World {

}

Page 11: Common errors

Keep in mind, it is not only class names, variable names and method names have to be composed of a single connected string.

Page 12: Common errors

public class HelloWorld {

public static void main(String [] args) {

int Britteny Spears;

}

}

Page 13: Common errors

public class HelloWorld {

public static void main(String [] args) {

int Britteny Spears;

}

}

After the first string –Brittney – a ; is expected.

Page 14: Common errors

public class HelloWorld {

public static void main(String [] args) {

int Britteny Spears;

}

}

Page 15: Common errors

public class HelloWorld {

public static void main(String [] args) {

int BrittenySpears;

int Britteny;

int Spears;

}

}

Page 16: Common errors

public class HelloWorld {

public static void main(String [] args) {

//this is the best

int brittenySpears;

int britteny;

int spears;

}

}

Page 17: Common errors

Brackets

Page 18: Common errors

Every open bracket has to be closed in the program!!!

Page 19: Common errors

As a rule of thumb check that every bracket you open is closed somewhere in the program: (), [], {}.

Page 20: Common errors

For the purpose of this class use curly brackets –{}- at the beginning and the end of a class and a method (more about these in the next week).

Page 21: Common errors

Every open bracket has to be closed in the program!!!

Page 22: Common errors

public class HelloWorld {

public static void main(String [] args) {

System.out.println(“Hello World”);

}

}

Page 23: Common errors

public class HelloWorld {

//beginning of the class body

public static void main(String [] args) {

System.out.println(“Hello World”);

}

} //end of the class body

Page 24: Common errors

public class HelloWorld {

public static void main(String [] args) {

//beginning of the method body

System.out.println(“Hello World”);

} //end of the method body

}

Page 25: Common errors

public class HelloWorld

public static void main(String [] args) {

System.out.println(“Hello World”);

}

}

Bracket missing

Bracket expected

Page 26: Common errors

Enjoy finding the other errors.

Page 27: Common errors

Semicolons

Page 28: Common errors

You have to learn to love ; in Java. Every statement in Java ends with a ;.

Page 29: Common errors

public class HelloWorld {

public static void main(String [] args) {

System.out.println(“Hello World”);

}

}

Page 30: Common errors

Summary

• Names are a single string.

• Brackets always come in pairs.

• Semicolons end a statement.

Page 31: Common errors

Thank you