Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pert II: Basic Java Programming Teguh Sutanto, M.Kom.

Similar presentations


Presentation on theme: "Pert II: Basic Java Programming Teguh Sutanto, M.Kom."— Presentation transcript:

1 Pert II: Basic Java Programming Teguh Sutanto, M.Kom. teguh.sutanto@gmail.com teguh@stikom.edu http://blog.stikom.edu/teguh http://teguhsutanto.blogspot.com

2 Tujuan Pembelajaran Pembelajar memahami struktur dasar pemrograman dengan bahasa Java Memahami variabel dan tipe data

3 Materi Hari ini Mengenal Java Struktur dasar pemrograman Java Penulisan kode program (coding) Kompilasi program Menjalankan program

4 Sumber/Ref www.ntu.edu.sg/home/ehchua/programming/java/J1a_Introduction.html

5 A computer program A computer program or application is a set of instructions, written in a programming language that enables a computer to perform some specifi ed task

6 A program is a sequence of instructions (called programming statements), executing one after another - usually in a sequential manne

7 Java? Java is a general-purpose language developed by Sun Microsystems in the early 1990s. Java was originally designed to program smart consumer electronic devices. Java’s creators identified three main goals for their new language: 1.Platform independence—Java programs should be capable of running on any computer. 2.Security—Java programs should not be susceptible to hackers’ code and dangerous viruses. 3.Reliability—Java programs should not “crash.”

8 JVM Java’s creative team designed an abstract computer implemented in software called the Java Virtual Machine (JVM). You cannot go to a store and buy a JVM computer. Instead you install software on your computer that simulates a JVM computer. The JVM is not a piece of hardware, but it pretends to be one. The machine language of the JVM is called bytecode. Java programs are fi rst compiled into bytecode, and then executed.

9 How to program DesidnCodeCompile

10 Struktur Dasar Pemrograman Java

11 Variable: The Holders of Information Sebuah tempat untuk menyimpan data, contoh: Angka 365 merepresentasikan jumlah hari dalam satu tahun Angka 37 derajat celcius menunjukkan suhu normal tubuh manusia Nama seorang aktor favorit, Jet Lee

12 Variable di mata seorang programer JumlahHari suhuTubuh aktorFavorit Programmer Variables in algebra are letters of the alphabet, like x and y, but in computer languages, they can also be any descriptive names like sum, answer, or first_value.

13 A variable is a named memory location capable of storing data of a specified type

14 So...what is Variable? Computer programs manipulate (or process) data. A variable is used to store a piece of data for processing. It is called variable because you can change the value stored. More precisely, a variable is a named storage location, that stores a value of a particular data type. In other words, a variable has a name, a type and stores a value. A variable has a name (or identifier), e.g., radius, area, age, height. The name is needed to uniquely identify each variable, so as to assign a value to the variable (e.g., radius=1.2), and retrieve the value stored (e.g., radius*radius*3.1416). A variable has a type. Examples of type are: – int: for integers (whole numbers) such as 123 and -456; – double: for floating-point or real numbers, such as 3.1416, -55.66, having an optional decimal point and fractional part; – String: for texts such as "Hello", "Good Morning!". Text strings are enclosed within a pair of double quotes.

15 A variable can store a value of that particular type. It is important to take note that a variable in most programming languages is associated with a type, and can only store value of the particular type. For example, a int variable can store an integer value such as 123, but NOT real number such as 12.34, nor texts such as "Hello". The concept of type was introduced into the early programming languages to simplify intrepretation of data made up of 0s and 1s.

16 Contoh Variable

17

18 Pembahasan

19

20 Deklarasi Variable A variable must be declared before it can be used. A variable declaration specifi es – the type of data that the variable can hold, for example int or double, and – the name of the variable. varType varName; // Declare a variable of a type varType varName1, varName2,...; // Declare multiple variables of the same type varType varName = initialValue; // Declare a variable of a type, and assign an initial value varType varName1 = initialValue1, varName2 = initialValue2,... ; // Declare variables with initial values varType varName; // Declare a variable of a type varType varName1, varName2,...; // Declare multiple variables of the same type varType varName = initialValue; // Declare a variable of a type, and assign an initial value varType varName1 = initialValue1, varName2 = initialValue2,... ; // Declare variables with initial values

21

22

23 Pembahasan

24 Mengisi variable dari luar

25 Pembahasan Line 7: int chirps; On line 7, we declare an integer variable, chirps, that is intended to hold the number of chirps per minute. Line 8: double temperature; The statement on line 8 is also a variable declaration. The variable temperature holds the air temperature. Because the computation of the temperature requires division by 6.6, temperature is declared as double. Line 9: Scanner input new Scanner(System.in) ; The name input refers to a “ Scanner object.”

26 Line 10: System.out.print("Enter the number of chirps/minute: "); Line 10 is an output statement that prompts the user for data. A “user friendly” program should always supply a prompt when interactive input is required. It is also a good idea to remind the user of the type of units that are expected, that is, chirps/minute rather than chirps/second. Line 11: chirps input.nextInt(); The statement on line 11 demonstrates the Scanner object in action. The Scanner object, input, accepts or reads one integer from the keyboard. In fact, the program pauses indefinitely until the user types an integer and presses the Enter key. Once the user supplies an integer, that number is assigned to the variable chirps. The Scanner object, input, expects an integer (input. nextInt() ). If the user enters a decimal number or a character other than whitespace (spaces, tabs, or new lines), a runtime error terminates the execution of the program and the system issues an error message. Because the Scanner object skips leading whitespace, a user can legally enter “ 77”—the spaces are ignored. Line 12: temperature chirps/6.6 4; The value stored in chirps is used to compute the air temperature. The result of the computation is assigned to the variable temperature. Line 13: System.out.println("The temperature is "temperature"C"); The program displays the value stored in temperature along with some explanatory text.


Download ppt "Pert II: Basic Java Programming Teguh Sutanto, M.Kom."

Similar presentations


Ads by Google