1 / 13

Agenda

Agenda. Hierarchy of computer 1 st , 2 nd , 3 rd generation of programming languages Compiler, executable Java jargons – JDK, IDE, JRE, JVM Statement, Identifier, variable, declaration, initialization, keywords What types do you know? What’s type casting?

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. Agenda Hierarchy of computer 1st, 2nd, 3rd generation of programming languages Compiler, executable Java jargons – JDK, IDE, JRE, JVM Statement, Identifier, variable, declaration, initialization, keywords What types do you know? What’s type casting? Arithmetic, logical, rational, assignment operators

  2. statements • A set of instructions • A semicolon is required to indicate the end of a statement. • Related statements are enclosed by curly braces ({ }) to begin and end the instructions.

  3. Topics • Conditional control structure if –else if – else if nested if –else switch • Object scanner, Math, Random

  4. Quiz example int aNumber; ? ? aNumber = 10; ?

  5. In two statements, declare a variable named numBeads and assign it the value 5. • What is the final value of yourNumber after the last statement executes? int myNumber = 5; int yourNumber = 4; myNumber = yourNumber * 2; yourNumber = myNumber + 5;

  6. The java.util package contains a class named Vector . Write a statement that makes the Vector class accessible to an application. • Determine the appropriate data type for each of the following values: a) the number of basketballs in a department store. b) the price of a basketball. c) whether a basketball player has received a jersey or not.

  7. What package is loaded automatically? • Why we can use System.out.println without using import • What are the 2 ways to write comments? • What is the entry point(function/method) for the program to execute? • What is the difference between System.out.print and System.out.println. • What primitive data type do you know?

  8. Int num1 = 5; Int num2 = 3; Int result; double doubleNum1 = 5; double doubleNum2 = 3; double doubleResult; result = num1 / num2; doubleResult = num1 / num2; System.out.println("num1 / num2: " + result);

  9. Using the following declarations, rewrite the statements to include the appropriate type casting, rounding where necessary. If type casting is not necessary, explain why: int j = 5; double k = 1.6; int y; double z; a) y = j * k; b) z = j * k; c) z= k * k;

  10. Consider the code segment if (n == 1) k++; else if (n == 4 ) k += 4; If the given segment is rewritten in the form if(/*condition*/) 1 /* assignment statement */ 2 • (1) n == 1 && n == 4 (2) k += n • (1) n == 1 && n == 4 (2) k += 4 • (1) n == 1 || n == 4 (2) k += 4 • (1) n == 1 || n == 4 (2) k += n • (1) n == 1 || n == 4 (2) k = n - k

  11. Explain why the following names are illegal? 139 139Abc fast One class Slow.Sally double gold;Nugget hopper-gee

  12. Quiz exercises Write a switch structure that uses the character myChar. It should increment the integer variable y if myChar is either a capital or small letter G. It should decrement y if myChar is either a capital or a small letter M. If myChar is anything else, add 100 to y.

  13. Assume num1 and num2 contain integer values. Write an if-else if statement that displays one of the following messages as appropriate: First number is larger. Second number is larger. Numbers are equal.

More Related