Common errors

2,580 views
2,551 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
2,580
On SlideShare
0
From Embeds
0
Number of Embeds
2,403
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Common errors

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

×