Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECP4136 Java Technology Tutorial 2. Overview Replacement class? Previous tutorials What you’ve learnt Tasks for this tutorial session.

Similar presentations


Presentation on theme: "ECP4136 Java Technology Tutorial 2. Overview Replacement class? Previous tutorials What you’ve learnt Tasks for this tutorial session."— Presentation transcript:

1 ECP4136 Java Technology Tutorial 2

2 Overview Replacement class? Previous tutorials What you’ve learnt Tasks for this tutorial session

3 Previous tutorials Setup Java SDK Add system path “Hello World” –classes, instantiate object Java Doc… Tutorial question – Circle calculation app –Preview on GUI

4 What you’ve learnt Overview of Java Technology public class HelloWorld { public static void main(String[ ] args) { // Data and expressions } Chapter 1

5 What you’ve learnt Date and expressions public class HelloWorld { public static void main(String[ ] args) { // Data and expressions } Chapter 2

6 Data and Expressions Variable vs constants Eight primitive data types –byte, short, int, long –float, double –char –boolean Expressions –expression tree –precedence of operator Data conversion GUI – next tutorial

7 Data and Expressions Variable vs constants Eight primitive data types –byte, short, int, long –float, double –char –boolean Expressions –expression tree –precedence of operator Data conversion GUI – next tutorial

8 Data conversion Widening conversions / Narrowing conversions What about char (16 bits)? byte8 bits short16 bits int32 bits long64 bits float32 bits double32 bits ? ?

9 Data conversion “All widening conversions that go from an integer type to another integer type, preserve the numeric value exactly.” FromTo byteshort, int, long, float, or double shortint, long, float, or double charint, long, float, or double intlong, float, or double longfloat or double floatdouble FromTo bytechar shortbyte or char charbyte or short intbyte, short, or char longbyte, short, char, or int floatbyte, short, char, int, or long doublebyte, short, char, int, long, or float byte8 bits short16 bits int32 bits long64 bits float32 bits double64 bits Widening conversions Narrowing conversions * char – 16 bits

10 Data conversion “The widening conversions that result in a floating point value can lose precision.” (least significant digits may be lost) FromTo byteshort, int, long, float, or double shortint, long, float, or double charint, long, float, or double intlong, float, or double longfloat or double floatdouble byte8 bits short16 bits int32 bits long64 bits float32 bits double64 bits Widening conversions Narrowing conversions * char – 16 bits FromTo bytechar shortbyte or char charbyte or short intbyte, short, or char longbyte, short, char, or int floatbyte, short, char, int, or long doublebyte, short, char, int, long, or float

11 Data conversion “An exception to the space-shrinking situation in narrow conversion is when we convert a byte/short to a char. These are still considered narrowing conversion because the sign bit is incorporated to the new character value.” FromTo byteshort, int, long, float, or double shortint, long, float, or double charint, long, float, or double intlong, float, or double longfloat or double floatdouble byte8 bits short16 bits int32 bits long64 bits float32 bits double64 bits Widening conversions Narrowing conversions * char – 16 bits FromTo bytechar shortbyte or char charbyte or short intbyte, short, or char longbyte, short, char, or int floatbyte, short, char, int, or long doublebyte, short, char, int, long, or float

12 Data conversion “Since a character value is unsigned, a negative integer will be converted into a character that has no particular relationship to the original integer value.” FromTo byteshort, int, long, float, or double shortint, long, float, or double charint, long, float, or double intlong, float, or double longfloat or double floatdouble byte8 bits short16 bits int32 bits long64 bits float32 bits double64 bits Widening conversions Narrowing conversions * char – 16 bits FromTo bytechar shortbyte or char charbyte or short intbyte, short, or char longbyte, short, char, or int floatbyte, short, char, int, or long doublebyte, short, char, int, long, or float

13 Data conversion boolean value cannot be converted to any other primitive type and vice versa” FromTo byteshort, int, long, float, or double shortint, long, float, or double charint, long, float, or double intlong, float, or double longfloat or double floatdouble byte8 bits short16 bits int32 bits long64 bits float32 bits double64 bits Widening conversions Narrowing conversions FromTo bytechar shortbyte or char charbyte or short intbyte, short, or char longbyte, short, char, or int floatbyte, short, char, int, or long doublebyte, short, char, int, long, or float * char – 16 bits

14 Current Tasks Common programming practices Trial-and-error – learn from mistakes Debug – DebugMe.java Tutorial questions from MMLS Refer to: http://pesona.mmu.edu.my/~yong.yean.sheng/ecp4136/tut02.htm


Download ppt "ECP4136 Java Technology Tutorial 2. Overview Replacement class? Previous tutorials What you’ve learnt Tasks for this tutorial session."

Similar presentations


Ads by Google