Common errors v2

1,931 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,931
On SlideShare
0
From Embeds
0
Number of Embeds
1,458
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Common errors v2

  1. 1. Common Errors and Solutions CST200 – Week 1: Common Errors when Starting to write and compile Java Code Instructor: Andreea Molnar
  2. 2. Outline • Disclaimer • Names • Brackets • Semicolons
  3. 3. Disclaimer
  4. 4. These are common errors I have seen as a teaching assistant, and are based solely on my experience.
  5. 5. 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
  6. 6. Error Category
  7. 7. Names
  8. 8. Names (e.g. class names, variable names, method names) are a single string!
  9. 9. Is the class name Hello or World? public class Hello World { }
  10. 10. public class Hello World { } After the first string –Hello – a bracket is expected.
  11. 11. public class Hello World { }
  12. 12. public class Hello World { }
  13. 13. public class HelloWorld { } public class Hello { } public class World { }
  14. 14. Keep in mind, it is not only class names, variable names and method names have to be composed of a single connected string.
  15. 15. public class HelloWorld { public static void main(String [] args) { int Britteny Spears; } }
  16. 16. public class HelloWorld { public static void main(String [] args) { int Britteny Spears; } } After the first string –Brittney – a ; is expected.
  17. 17. public class HelloWorld { public static void main(String [] args) { int Britteny Spears; } }
  18. 18. public class HelloWorld { public static void main(String [] args) { int BrittenySpears; int Britteny; int Spears; } }
  19. 19. public class HelloWorld { public static void main(String [] args) { //this is the best int brittenySpears; int britteny; int spears; } }
  20. 20. Brackets
  21. 21. Every open bracket has to be closed in the program!!!
  22. 22. As a rule of thumb check that every bracket you open is closed somewhere in the program: (), [], {}.
  23. 23. 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).
  24. 24. Every open bracket has to be closed in the program!!!
  25. 25. public class HelloWorld { public static void main(String [] args) { System.out.println(“Hello World”); } }
  26. 26. public class HelloWorld { //beginning of the class body public static void main(String [] args) { System.out.println(“Hello World”); } } //end of the class body
  27. 27. public class HelloWorld { public static void main(String [] args) { //beginning of the method body System.out.println(“Hello World”); } //end of the method body }
  28. 28. Bracket missing public class HelloWorld public static void main(String [] args) { System.out.println(“Hello World”); } } Bracket expected
  29. 29. Enjoy finding the other errors.
  30. 30. Semicolons
  31. 31. You have to learn to love ; in Java. Every statement in Java ends with a ;.
  32. 32. public class HelloWorld { public static void main(String [] args) { System.out.println(“Hello World”); } }
  33. 33. Summary • Names are a single string. • Brackets always come in pairs. • Semicolons end a statement.
  34. 34. Thank you

×