Top Banner
Basic Java Programming Teguh Sutanto, M.Kom.
29

Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Dec 14, 2015

Download

Documents

Madalyn Maddux
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Basic Java Programming

Teguh Sutanto, M.Kom.

Page 2: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Tujuan

• Mahasiswa dapat menyebutkan berbagai tipe data dan operato

Page 3: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Materi

• Struktur dasar program Java• Variable• Constanta• Tipe Data• Operator

Page 4: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Buku Referensi

Page 5: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

•A computer program or application is a set of instructions,

written in a programminglanguage that enables a computer

to perform some specifi ed task

Page 6: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Mengapa Java?

• Java is small and beautiful• Java is object oriented• Java supports the Internet• Java is general purpose• Java is platform independent• Java has libraries

Page 7: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.
Page 8: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Struktur Program Java

Nama Class (Nama Program)

Isi program “{ }”Method main(String []argz)

Local variable

Page 9: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Penamaan Program/Class

• Kata Benda• Diawali dengan HurufBesar• Nama File = NamaProgram• Contoh: public class ProgramPertamax disimpan dengan nama

ProgramPertamax.java

• Tidak boleh ada spasi• Contoh: Program Pertamax

• Tidak boleh diawali dengan angka• Contoh: 1Program

Page 10: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Method public static void main(String []param)

public static void main(String []param){//code program//alur program}

Parameter Program

Every Java application contains a class with a main method. When the application starts, the instructions in the main method are executed.

Setiap program yang akan dijalankan oleh JVM harus ada method launcher yang dengan nama main(String[] a)

Page 11: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

1

2

3

SimpanCompile

Jalankan

dengan nama PrgPertamax.java

>javac PrgPertamax.java

>java PrgPertamax

Page 12: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

A keyword is a dictionary word — a word that’s built right into a language

Page 13: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Keywoards

abstract continue for newswitch assert default gotopackage do synchronized booleanif private this breakdouble implements protected throwbyte else import publicthrows case enum instanceofreturn transient catch extendsint short try charfinal interface static voidclass finally long strictfpvolatile const float nativesuper while s e

Page 14: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Alur Program

1. sequences2. repetitions3. selections4. methods5. ready-made objects6. objects you write yourself

Page 15: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Case Sensitive

• The java proGRAMMing lanGUage is case-sensitive. ThIS MEans that if you change a lowerCASE LETTer in a wORD TO AN UPPercase letter, you chANge the wORD’S MEaning. ChangiNG CASE CAN MakE the enTIRE WORD GO FROM BeiNG MEANINGFul to bEING MEaningless.

Page 16: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

public static void main(String args[]) { System.out.println(“Chocolate, royalties, sleep”);}

• main: The main starting point for execution in every Java program.• String: A bunch of text; a row of characters, one after another.• System: A canned program in the Java API. (This program accesses

some features of your computer that are outside the direct control of the Java virtual machine (JVM).)• out: The place where a text-based program displays its text. (For a

program running in Eclipse, the word out represents the Console view. • println: Display text on your computer screen

Page 17: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

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

Page 18: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Variable di mata seorang programer

JumlahHari

suhuTubuh

aktorFavoritProgrammer

365

37“Jet Lee”

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.

Note:

Page 19: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

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

Page 20: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

So…what is the var?

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

Page 21: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Variable…(cont)

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

Page 22: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Tipe Data Primitip• byte• short• int• long

Integers• float• double.Floating-point• This group includes char, which represents symbols in a

character set, like letters and numbers.Characters• This group includes boolean, which is a special type for

representing true/false values.Boolean

Page 23: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

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

Page 24: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

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

Page 25: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Contoh Variable

Page 26: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.
Page 27: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.

Pembahasan

Page 28: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.
Page 29: Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.