common errors v2

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

Upload: asu-online

Post on 17-May-2015

1.730 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Common errors v2

Common Errors and Solutions

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

Instructor: Andreea Molnar

Page 2: Common errors v2

Outline

•Disclaimer

•Names

•Brackets

•Semicolons

Page 3: Common errors v2

Disclaimer

Page 4: Common errors v2

These are common errors I have seen as a teaching assistant, and are based solely on my experience.

Page 5: Common errors v2

Everyone is different, therefore:

• some of you will not make these mistakes

• others will not make these mistakes after seeing this presentation

• For others it may be a good resource to consult

Page 6: Common errors v2

Error Category

Page 7: Common errors v2

Names

Page 8: Common errors v2

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

Page 9: Common errors v2

public class Hello World {

}

Is the class name Hello or World?

Page 10: Common errors v2

public class Hello World {

}

After the first string –Hello – a bracket is

expected.

Page 11: Common errors v2

public class Hello World {

}

Page 12: Common errors v2

public class Hello World {

}

Page 13: Common errors v2

public class HelloWorld {

}

public class Hello {

}

public class World {

}

Page 14: Common errors v2

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

Page 15: Common errors v2

public class HelloWorld {

public static void main(String [] args) {

int Britteny Spears;

}

}

Page 16: Common errors v2

public class HelloWorld {

public static void main(String [] args) {

int Britteny Spears;

}

}

After the first string –Brittney

– a ; is expected.

Page 17: Common errors v2

public class HelloWorld {

public static void main(String [] args) {

int Britteny Spears;

}

}

Page 18: Common errors v2

public class HelloWorld {

public static void main(String [] args) {

int BrittenySpears;

int Britteny;

int Spears;

}

}

Page 19: Common errors v2

public class HelloWorld {

public static void main(String [] args) {

//this is the best

int brittenySpears;

int britteny;

int spears;

}

}

Page 20: Common errors v2

Brackets

Page 21: Common errors v2

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

Page 22: Common errors v2

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

Page 23: Common errors v2

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 24: Common errors v2

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

Page 25: Common errors v2

public class HelloWorld {

public static void main(String [] args) {

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

}

}

Page 26: Common errors v2

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 27: Common errors v2

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 28: Common errors v2

public class HelloWorld

public static void main(String [] args) {

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

}

}

Bracket missing

Bracket expected

Page 29: Common errors v2

Enjoy finding the other errors.

Page 30: Common errors v2

Semicolons

Page 31: Common errors v2

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

Page 32: Common errors v2

public class HelloWorld {

public static void main(String [] args) {

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

}

}

Page 33: Common errors v2

Summary

•Names are a single string.

•Brackets always come in pairs.

•Semicolons end a statement.

Page 34: Common errors v2

Thank you