Interesting Facts About YOU - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Interesting Facts About YOU

Description:

Oh Dear! The result of writing Fortran in Java... Avoid static except for main ... String s1 = 'yes'; String s2 = 'yes'; if(s1 == s2) System.out.println('same' ... – PowerPoint PPT presentation

Number of Views:56
Avg rating:3.0/5.0
Slides: 28
Provided by: daveel1
Category:
Tags: you | dear | facts | interesting | yes

less

Transcript and Presenter's Notes

Title: Interesting Facts About YOU


1
Interesting Facts About YOU!
  • You each made an average of thirty errors
    compiling each exercise last term
  • For every error per person in the morning, there
    were 2.5 errors in the afternoon

2
The Moral
  • You are morning people after all (unlike me)
  • If I can make the TUEs and THUs at 900 so can
    you!
  • Come in early and do lots of programming

3
How to Avoid Over 80 of Your Mistakes
4
The Most Common Mistakes -
  • The most common error is missing a semicolon or a
    comma
  • String s Every line ends with a
  • Fred.method(arg1, 12) // needs comma

5
Arguments and Operators
  • The next most common error is missing a between
    strings or similar
  • System.Out.println(root is r)
  • People often put
  • System.Out.println(root is , r)
  • The number of errors went up a lot when methods
    were taught

6
Undefined variables
  • The most common semantic error is using a
    variable which has not been defined or to a
    lesser extent not initialised
  • Think carefully about types and your style of
    declaration

7
Static Confusion
  • non-static variable in a static context
  • Oh Dear! The result of writing Fortran in Java
  • Avoid static except for main()
  • Keep main() SHORT

8
Use of in Conditionals
  • If (x 2) something
  • In C or C this compiles
  • is assignment
  • is the comparison operator

9
Right Hand Side ! LHS
  • All variables have a type
  • All expressions return a type
  • These MUST be the same
  • Well you can use a cast
  • int i 0
  • Double b 10.2
  • i (int) b

10
1. Compile and run
  • public class Fred
  • public static void main()
  • System.out.println(Hello)

What Happens?
11
2. After Execution
  • String types new String20
  • What will the first element of the array contain?
  • An empty String?
  • The null value?
  • Zero?

12
3. What will be Printed?
  • Integer x1 new Integer(5)
  • Integer x2 x1
  • Integer x3 new Integer(5)
  • if(x1 x2) System.out.println(x1 x2)
  • if(x1 x3) System.out.println(x1 x3)

13
4. What will be printed?
  • String s1 yes
  • String s2 yes
  • if(s1 s2) System.out.println(same)
  • if(s1 ! s2) System.out.println(different)
  • (very trick question!)

14
5. What is printed out?
  • int counts
  • System.out.println(counts counts)

15
6. What is printed out?
  • int counts
  • counts new int10
  • System.out.println(counts counts)

16
7. What is printed out?
  • int ids
  • ids new int5
  • System.out.println(ids2)

17
8. What is printed out?
  • String names
  • names new String5
  • System.out.println(names2)

18
9. String to int
  • String age 97
  • int freds_age

How can I get freds_age from age?
19
10. int to String
  • String age
  • int freds_age 99

How can I turn freds_age into a String?
20
11. What will happen?
  • public class Example
  • public Boolean flags new Boolean4
  • public static void main(String args)
  • Example E new Example()
  • System.out.println(Flag 1 is
    E.flags1)

21
12. What will be the result?
  • public int adder(int N)
  • return 0x100 N

In n of calling n adder(2)
22
13. How many String Objects are created here?
  • String A, B, C
  • A new String(1234)
  • B A
  • C A B

23
  • 14. What keyword is used to derive once class
    from another?
  • 15. What keyword is used to state that a certain
    set of methods must be implemented by a class?

24
  • 16. A variable in a class is defined as
  • protected int age
  • Why does the keyword protected make age more
    visible!?

25
17. This is Student.java
  • Public class Student
  • String name
  • int age
  • boolean male
  • Module subjects
  • public class Module
  • String module_code
  • int Semester
  • int mark

What message is generated by javac?
26
18. Which line will cause a compilation failure?
  • double fred
  • boolean bill
  • int 2fred
  • String _lucy
  • float ron

27
19. Define the following
  • A primitive
  • An Object Reference
  • Which can have the value zero?
  • Which can have the value null?
Write a Comment
User Comments (0)
About PowerShow.com