1 / 21

Agenda

Packages and classes Types and identifiers Operators Input/output Control structures Errors and exceptions homework. Agenda. Packages and classes. How do you use the classes in the package? How packages do you know? Which package is automatically provided to all java program?

briana
Download Presentation

Agenda

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Packages and classes • Types and identifiers • Operators • Input/output • Control structures • Errors and exceptions • homework Agenda

  2. Packages and classes • How do you use the classes in the package? • How packages do you know? • Which package is automatically provided to all java program? • The compiler converts source code into machine-readable form called?? • What are reserved words? List 5. • Java application vs java applet

  3. Types and identifiers • What are identifiers? • Declaration vs initialization. • Data types? What 2 types? • Name 4 primitive types. • Integer are bounded. What does it mean? • What happens if you stores an integer value which is too big? What erros? • Give me a signature of declaration.

  4. int vs double • Which data type has more storage? • Which causes a compile-time error? Assign an int to a double or the other way around? Why • What happens when you assign a double to an int? int aInt = 7; double aDouble; aInt = aDouble; => ok?

  5. What happens when you assign an int to a double? int aInt=8; double aDouble=8.0; aDouble = aInt; => ok? • What do you prevent the compiling error when you try to assign one data type to another data type? • How does the book say about rounding a positive or negative int to the nearest numbers?

  6. Storage of numbers • What other primitive(built-in) data type uses one byte of storage? • Which bit stores the sign of the integer, what number for positive/negative? • What is the largest positive integer that can be store using byte? • How many bytes(bits) does Java use for type int? • If java uses 6 bytes for a number, what is the number range? • What are the 2 java constants for the max/min that an int can hold?

  7. Hexadecimal numbers • How a hex number is represented? With symbols … • In java, how does a hex number is represented? • How to convert from a hex to binary and from binary to hex? 4FA -> 1101 1000 1111 ->

  8. Final variables • Also called use-defined constant • What is the keyword and where is it placed? • What is a common use for a constant? • What benefit is it to have a constant?

  9. Arithmetic Operators • Arithmetic operators? • When any arithmetic operators apply to a double and an int, what happens? What is the result? 3.0 / 4 => 3 / 4.0 => (int) 3.0 / 4 => (double)3 / 4 => (double)(3 / 4 )=>

  10. Relational operators • What are they? (6 of them) • Where(how) are they used? • Can relational operators be used to compare two objects? • Can relational operators be used to compare two doubles?

  11. Logical operators • What are they? • Where(how) are they used? • What is short-circuit evaluation? if(num != 0 && scoreTotal/num > 90)… If num is 0, will this statement cause a runtime error when division by 0?

  12. Assignment operators • What are they? • What are compound assignment operators? • Is the following statement allowed? int a, b, c; a = b = c = 0;

  13. Increment and decrement operators • What are they? • i++ and i-- are equivalent? int x = 10; System.out.println( x++); => x? System.out.println( ++x); => x?

  14. Operator precedence • What would you roughly arrange the precedence for the following operators? a) increment/decrement operators b) assignment operators c) logical operators d) relational operators System.out.println(5 + 3 < 6 – 1); => output?

  15. Escape sequences • What is an escape sequence? • What is its purpose? • Name 3 examples. • Write a statement which will prints out a) welcome to the party b) His name is “Harry” c) d:\myFile\..

  16. Control structures • Nested “if” statement is equivalent to putting the two “if” in one statement with what operator? • Loophole: int n = 7; if( n > 0) if( n % 2 == 0) System.out.println(n); else System.out.println(n + “is not positive”);

  17. for loop for(initialization; termination condition; update statement) { body of the loop ..} When will be termination condition be executed, before the body or after? When will be the update statement be executed, before the body or after? for(int k = 20; k >=15; k--) System.out.print(k + “ “ ); => what will be printed?

  18. Enhanced for loop • Only for what type of data? • for( int element : data) System.out.print(element+ “ “ ); What is data? • for( boolean element : data) System.out.print(element+ “ “ ); What is data? • Can the for-each loop be used to replace or removing elements?

  19. Nested for loop for(int i=1; i<7; i++) { for(int j =0; j <=i; j++) System.out.print(“*”); } System.out.println(“”); What will be printed?

  20. Errors and exceptions • Will be covered next class.

  21. homework • Read BPJ 37 and Barron’s p68-69 • Quiz on materials of Barron’s chapter 1

More Related