Pemrograman Dasar. Basic Elements Of Java

Similar documents
First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Chapter 2 Introduction to Java programming

ECE 122. Engineering Problem Solving with Java

Variables, Constants, and Data Types

CS 106 Introduction to Computer Science I

JavaScript: Control Statements I

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

Introduction to Java. CS 3: Computer Programming in Java

Java Programming Fundamentals

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Number Representation

Introduction to Java

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

C++ Language Tutorial

A list of data types appears at the bottom of this document. String datetimestamp = new java.sql.timestamp(system.currenttimemillis()).

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Objective-C Tutorial

Chapter 1 Java Program Design and Development

Habanero Extreme Scale Software Research Project

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Chapter 2 Elementary Programming

Computer Programming Tutorial

Chapter 2: Elements of Java

J a v a Quiz (Unit 3, Test 0 Practice)

Java programming for C/C++ developers

Informatica e Sistemi in Tempo Reale

Java Interview Questions and Answers

Programming Languages CIS 443

Java Crash Course Part I

Useful Number Systems

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

The programming language C. sws1 1

Comparative Study of C, C++, C# and Java Programming Languages

2 ASCII TABLE (DOS) 3 ASCII TABLE (Window)

This section describes how LabVIEW stores data in memory for controls, indicators, wires, and other objects.

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

CSI 333 Lecture 1 Number Systems

Lecture 1 Introduction to Java

Example of a Java program

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

Install Java Development Kit (JDK) 1.8

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Numbering Systems. InThisAppendix...

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

Object-Oriented Programming in Java

An Overview of Java. overview-1

Binary Representation

Sources: On the Web: Slides will be available on:

Ecma/TC39/2013/NN. 4 th Draft ECMA-XXX. 1 st Edition / July The JSON Data Interchange Format. Reference number ECMA-123:2009

Overview. java.math.biginteger, java.math.bigdecimal. Definition: objects are everything but primitives The eight primitive data type in Java

Tokens and Python s Lexical Structure

Chapter 7D The Java Virtual Machine

Chapter 4: Computer Codes

AP Computer Science Java Subset

So far we have considered only numeric processing, i.e. processing of numeric data represented

Database Extensions Visual Walkthrough. PowerSchool Student Information System

DNA Data and Program Representation. Alexandre David

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Lecture 5: Java Fundamentals III

INTERNATIONAL TELECOMMUNICATION UNION

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Introduction to Visual C++.NET Programming. Using.NET Environment

Week 1: Review of Java Programming Basics

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

The C Programming Language course syllabus associate level

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

PL / SQL Basics. Chapter 3

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Generalizing Overloading for C++2000

Crash Course in Java

.NET Standard DateTime Format Strings

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Outline Basic concepts of Python language

Compiler Construction

Field Properties Quick Reference

MS ACCESS DATABASE DATA TYPES

C Programming Tutorial

Chapter 3 Operators and Control Flow

Explain the relationship between a class and an object. Which is general and which is specific?

El Dorado Union High School District Educational Services

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Object Oriented Software Design

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Chapter 3. Input and output. 3.1 The System class

Transcription:

Pemrograman Dasar Basic Elements Of Java

Compiling and Running a Java Application 2

Portable Java Application 3

Java Platform Platform: hardware or software environment in which a program runs. Oracle has two products that implement Java Platform Standard Edition (Java SE) 7: Java SE Development Kit (JDK) 7 Java SE Runtime Environment (JRE) 7. 4

Java Platform SE 7 5

Typical Java Development Environment

Basic Lexical Elements Character set 16-bit Unicode Legal characters Keywords Reserved words, special meaning, illegal for identifiers Identifiers Names of declared entities, e.g. variables, constants Variables A variable is a storage location, something that can hold a value to which a value can be assigned Literals Constants or values, e.g. 12, 17.9, Hello 7

Basic Lexical Elements Other notations Operators, e.g. +, -, *, /, etc. Block symbols, e.g. pair of {} Comments Help developers, ignored by compiler e.g. /* Program 1 */ // Function to count Circle area 8

Character Set Java programs are written using Unicode character set (16 bit), which include: Capital letters: A.. Z Small letters: a.. z Numbers: 0.. 9 Punctuation marks, e.g.!,,,?, etc. Other characters or symbols, e.g. Arithmetic symbols, e.g. +, -, /, etc. from many natural languages Pengantar Bahasa C - TIF UB 2010 9

Keywords Keywords cannot be used as identifiers (reserved) because they have special meaning within the language. abstract continue for new switch assert default goto package synchronized boolean do if private this break double implements protected throw byte else import public throws case enum instanceof return transient catch extends int short try char final interface static void class finally long strictfp volatile const float native super while Pengantar Bahasa C - TIF UB 2010 10

Identifiers (Naming) Used for names of declared entities such as variables, constants, and labels Must start with a letter, followed by letters, digits, or both. Identifiers are case-sensitive The terms letter and digit are broad in Unicode: if something is considered a letter or digit in a human language, you can probably use it in identifiers. "Letters" can come from Chinese, Korean, Gurmukhi, Georgian, Devanagari, and almost any other script written in the world today. Pengantar Bahasa C - TIF UB 2010 11

Identifiers (Naming) Letters also include any currency symbol (such as $,, and ) and connecting punctuation (such as _). Identifiers can be as long as you like, but use some taste. Identifiers that are too long are hard to use correctly and actually obscure your code. Cannot use keywords (e.g. for, if, while, etc) Valid identifiers, e.g.: name, x1, _total, cubic Invalid identifiers, e.g.: 1kali, int Pengantar Bahasa C - TIF UB 2010 12

Variables A variable is a storage location, something that can hold a value to which a value can be assigned. A variable declaration states the identifier (name), type, and other attributes of a variable. e.g. float x, y; // is the same as float x; float y; float x = 3.14f, y = 2.81f; // is the same as float x = 3.14f, y = 2.81f; // is the same as float x = 3.14f; float y = 2.81f; 13

Variables Instance variables (non-static fields) Class variables (static fields) Local variables Parameters 14

Variables public class Bicycle { int cadence = 0; // instance variable static int wheels = 2; // static variable // formal parameter: decrement void applybrakes(int decrement) { speed = speed - decrement; } // local variable: states void printstates() { String states = "cadence: "+cadence+ ",speed: "+speed+", gear: "+gear; System.out.println(states); } } 15

(Data) Types Every expression has a type that determines what values the expression can produce. The type of an expression is determined by the types of values and variables used within that expression. Types are divided into the primitive types and the reference types. 16

Primitive Data Types Type Contains Default Size Range (for fields) boolean true or false 1 bit NA false char Unicode '\u0000' 16 bits or 0 to 2 16-1 or character unsigned 2 bytes '\u0000' (0) to '\uffff' byte short int Signed integer Signed integer Signed integer 0 0 0 (65535) 8 bit or -2 7 to 2 7-1 or 1 byte -128 to 127 16 bit or -2 15 to 2 15-1 or 2 bytes -32768 to 32767 32 bit or -2 31 to 2 31-1 or 4 bytes -2147483648 to 2147483647 long Signed integer float IEEE 754 floating point 0.0f singleprecision double IEEE 754 0 floating point doubleprecision 0 64 bit or -2 63 to 2 63-1 or 8 bytes -9223372036854775808 to 9223372036854775807 32 bit or 1.4E-45 to 3.4028235E+38 4 bytes 64 bit or 439E-324 to 8 bytes 1.7976931348623157E+308 17

Literals Also known as values or constants Each (data) type has literals, which are the way that constant values of that type are written. Boolean literals Character literals Integer literals Floating-point literals String literals Reference literals Class literals 18

Literals Boolean literals Only true and false Character literals Appear with single quotes, e.g. Z, a, 2, \u004e Certain special characters can be represented by an escape sequence, e.g.: \n newline (\u000a) \t tab (\u0009) \b backspace (\u0008) \r return (\u000d) \f form feed (\u000c) \\ backslash itself (\u005c) \' single quote (\u0027) \" double quote (\u0022) 19

Literals Integer literals An integer literal is of type long if it ends with the letter L or l; otherwise it is of type int. It is recommended that you use the upper case letter L because the lower case letter l is hard to distinguish from the digit 1. Values of the integral types byte, short, int, and long can be created from int literals. Values of type long that exceed the range of int can be created from long literals. 20

Literals Integer literals (cont d) Integer constants are a sequence of octal, decimal, or hexadecimal digits. The start of a constant declares the number's base: A 0 (zero) starts an octal number (base 8); a 0x or 0X starts a hexadecimal number (base 16); and any other digit starts a decimal number (base 10). E.g. all the following numbers have the same value 29 035 0x1D 0X1d 21

Literals Floating-point literals A floating-point literal is of type float if it ends with the letter F or f; otherwise its type is double and it can optionally end with the letter D or d. The floating point types (float and double) can also be expressed using E or e (for scientific notation), F or f (32-bit float literal) and D or d (64- bit double literal; this is the default and by convention is omitted). 22

Literals Floating-point literals (cont d) Expressed in either decimal or hexadecimal The decimal form consists of a string of decimal digits with an optional decimal point, optionally followed by an exponent the letter e or E, followed by an optionally signed integer. e.g. all these literals denote the same floating-point number: 18. 1.8e1.18E+2 180.0e-1 23

Literals Floating-point literals (continued) The hexadecimal form consists of 0x (or 0X), a string of hexadecimal digits with an optional hexadecimal point, followed by a mandatory binary exponent the letter p or P, followed by an optionally signed integer. The binary exponent represents scaling by two raised to a power. e.g. all these literals denote the same floating-point number (decimal 18.0): 0x12p0 0x1.2p4 0x.12P+8 0x120p-4 24

Literals Floating-point literals (continued) There are two zeros: positive (0.0) and negative (- 0.0). Positive and negative zero are considered equal when you use == but produce different results when used in some calculations. 25

Literals String literals (continued) String literals appear with double quotes, e.g. Welcome, salam, "\u0633\u064e\u0644\u064e\u0627\u0645\u064c". Any character can be included in string literals, with the exception of newline and " (double quote). Newlines are not allowed in the middle of strings. If you want to embed a newline character in the string, use the escape sequence \n. To embed a double quote use the escape sequence \". A string literal references an object of type String. 26