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

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

Basic Java Programming Teguh Sutanto, M.Kom.. Tujuan Mahasiswa dapat menyebutkan berbagai tipe data dan operato.
Variabel, Tipe Data & Operator Teguh Sutanto, M.Kom.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Introduction to Computer Programming CSC 1401: Introduction to Programming with Java Lecture 2 Wanda M. Kunkle.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Basic Input/Output and Variables Ethan Cerami New York
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Computer Science 101 Introduction to Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
COMPUTER SCIENCE I C++ INTRODUCTION
Introducing Java.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Java Applications & Program Design
Expressions and Interactivity Chapter 3. 2 The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Often.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
CS107 Introduction to Computer Science Java Basics.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Computer Science 101 Introduction to Programming.
Chapter 1 Introduction. Goal to learn about computers and programming to compile and run your first Java program to recognize compile-time and run-time.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Week 1 Algorithmization and Programming Languages.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
Getting Started With Java September 22, Java Bytecode  Bytecode : is a highly optimized set of instructions designed to be executed by the Java.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
Slides prepared by Rose Williams, Binghamton University Console Input and Output.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Java Programming: From the Ground Up
Introduction to the C Language
Console Output, Variables, Literals, and Introduction to Type
Java programming lecture one
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
Introduction to the C Language
Introduction to C++ Programming
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Dasar-Dasar Pemrograman 2: Java Basics
Presentation transcript:

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

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

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

Sumber/Ref

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

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

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

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.

How to program DesidnCodeCompile

Struktur Dasar Pemrograman Java

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

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.

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

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

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.

Contoh Variable

Pembahasan

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

Pembahasan

Mengisi variable dari luar

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

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.