03Reference and primitive data types

5 10 b α β marcel turcotte iti 1121 introduction to

This preview shows page 35 - 42 out of 81 pages.

5 ... 10 b ... α β Marcel Turcotte ITI 1121. Introduction to Computing II
Image of page 35

Subscribe to view the full document.

Preamble Data types Call-by-value Scope Memory representation Primitive vs reference types Comparison operators Comparison operators: primitive and reference types What will happen and why? i n t a = 5; I n t e g e r b = new I n t e g e r ( 5 ) ; i f ( a < b ) { System . out . p r i n t l n ( ”a < b” ) ; } e l s e i f ( a == b ) { System . out . p r i n t l n ( ”a == b” ) ; } e l s e { System . out . p r i n t l n ( ”a > b” ) ; } References.java:7: operator < cannot be applied to int,java.lang.Integer if (a < b) ^ References.java:9: operator == cannot be applied to int,java.lang.Integer else if (a == b) ^ 2 errors Marcel Turcotte ITI 1121. Introduction to Computing II
Image of page 36
Preamble Data types Call-by-value Scope Memory representation Primitive vs reference types Comparison operators i n t a = 5 ; I n t e g e r b = new I n t e g e r ( 5 ) ; i f ( a < b ) { System . out . p r i n t l n ( ”a < b” ) ; } e l s e i f ( a == b ) { System . out . p r i n t l n ( ”a == b” ) ; } e l s e { System . out . p r i n t l n ( ”a > b” ) ; } a ... 5 ... b ... α β 5 value γ γ References.java:7: operator < cannot be applied to int,java.lang.Integer if (a < b) ^ References.java:9: operator == cannot be applied to int,java.lang.Integer else if (a == b) ^ 2 errors Marcel Turcotte ITI 1121. Introduction to Computing II
Image of page 37

Subscribe to view the full document.

Preamble Data types Call-by-value Scope Memory representation Primitive vs reference types Comparison operators i n t a = 5 ; I n t e g e r b = new I n t e g e r ( 5 ) ; i f ( a < b ) { System . out . p r i n t l n ( ”a < b” ) ; } e l s e i f ( a == b ) { System . out . p r i n t l n ( ”a == b” ) ; } e l s e { System . out . p r i n t l n ( ”a > b” ) ; } a ... 5 ... b ... 5 value References.java:7: operator < cannot be applied to int,java.lang.Integer if (a < b) ^ References.java:9: operator == cannot be applied to int,java.lang.Integer else if (a == b) ^ 2 errors Marcel Turcotte ITI 1121. Introduction to Computing II
Image of page 38
Preamble Data types Call-by-value Scope Memory representation Primitive vs reference types Comparison operators i n t a = 5 ; I n t e g e r b = new I n t e g e r ( 5 ) ; i f ( a < b ) { System . out . p r i n t l n ( ”a < b” ) ; } e l s e i f ( a == b ) { System . out . p r i n t l n ( ”a == b” ) ; } e l s e { System . out . p r i n t l n ( ”a > b” ) ; } a 5 b 5 value References.java:7: operator < cannot be applied to int,java.lang.Integer if (a < b) ^ References.java:9: operator == cannot be applied to int,java.lang.Integer else if (a == b) ^ 2 errors Marcel Turcotte ITI 1121. Introduction to Computing II
Image of page 39

Subscribe to view the full document.

Preamble Data types Call-by-value Scope Memory representation Primitive vs reference types Comparison operators Comparison operators and reference types What will be the result? MyInteger a = new MyInteger ( 5 ) ; MyInteger b = new MyInteger ( 10 ) ; i f ( a < b ) { System . out . p r i n t l n ( ”a e q u a l s b” ) ; } e l s e { System . out . p r i n t l n ( ”a does not equal b” ) ; } Less.java:14: operator < cannot be applied to MyInteger,MyInteger if ( a < b ) { ^ 1 error Marcel Turcotte ITI 1121. Introduction to Computing II
Image of page 40
Preamble Data types Call-by-value Scope Memory representation Primitive vs reference types Comparison operators Remarks I These error messsages are produced by pre-1.5 Java compilers I Starting with Java 1.5, autoboxing masks the “problem” I
Image of page 41

Subscribe to view the full document.

Image of page 42
You've reached the end of this preview.
  • Spring '10
  • Samaan
  • Marcel Turcotte

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern