03Reference and primitive data types

5 10 b α β marcel turcotte iti 1121 introduction to

• Notes
• 81

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

5 ... 10 b ... α β Marcel Turcotte ITI 1121. Introduction to Computing II

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
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

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
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

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
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

Subscribe to view the full document.

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

{[ snackBarMessage ]}

What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern