Lecture 1 Introduction to Java Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Air Force Institute of Technology Electrical and Computer Engineering
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Object Oriented Programming in JAVA
Constants and Data Types Constants Data Types Reading for this class: L&L,
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example F Identifiers, Variables, and Constants F Primitive Data Types –byte,
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
ECE122 L2: Program Development February 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 2 Program Development.
Java Syntax Primitive data types Operators Control statements.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Chapter 2 Data Types, Declarations, and Displays
String Escape Sequences
JAVA PROGRAMMING PART II.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Chapter 2: Introducing Data Types and Operators.  Know Java’s primitive types  Use literals  Initialize variables  Know the scope rules of variables.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Java Building Elements Lecture 2 Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
DAT602 Database Application Development Lecture 5 JAVA Review.
Primitive Data Types and Operations Identifiers, Variables, and Constants Primitive Data Types Byte, short, int, long, float, double, char, boolean Casting.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
1 Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
Java Tutorial. Object-Oriented Programming Concepts Object –a representation of some item state  fields/members and should be encapsulated behavior 
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
C-Language Keywords(C99)
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Chapter 2: Java Fundamentals
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Java Programming The Language of Now & the Future* Lecture 0 An Introduction to Java Syntax for Non-C Programmers John Morris Department of Electrical.
Основы языка. 1.Переменные 2.Операторы 3.Примитивные типы 4.Массивы 5.Выражения 6.Блоки 7.Управление циклами.
Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science.
Chapter 2 Variables.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Primitive Data Types and Operations F Introduce Programming with an Example F Identifiers, Variables, and Constants F Primitive Data Types –byte, short,
1.  Algorithm: 1. Read in the radius 2. Compute the area using the following formula: area = radius x radius x PI 3. Display the area 2.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Working with Java.
Java Variables and Types
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
Sachin Malhotra Saurabh Choudhary
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Multiple variables can be created in one declaration
Variables and Primative Types
Starting JavaProgramming
Introduction to Java Programming
Basics of ‘C’.
An overview of Java, Data types and variables
elementary programming
Chap 2. Identifiers, Keywords, and Types
Module 2 Variables, Data Types and Arithmetic
Chapter 2 Primitive Data Types and Operations
Review of Java Fundamentals
Presentation transcript:

Lecture 1 Introduction to Java Erick Pranata © Sekolah Tinggi Teknik Surabaya 1

» Getting Started with Java » Variables, Constants, Data Types and Operators » Arrays » Control Flow Statements » Misc. 2 © Sekolah Tinggi Teknik Surabaya

3

» Java Standard Edition (Java SE) ˃J2SE can be used to develop client-side standalone applications or applets. » Java Enterprise Edition (Java EE) ˃J2EE can be used to develop server-side applications such as Java Servlets and Java Server Pages. » Java Micro Edition (Java ME). ˃J2ME can be used to develop applications for mobile devices such as cell phones. 4 © Sekolah Tinggi Teknik Surabaya

» TextPad » jEdit » jCreator » JBuilder » Eclipse » NetBeans » Etc. 5 © Sekolah Tinggi Teknik Surabaya

» Java Development Kit » Java Runtime Environment ˃Java Virtual Machine 6 © Sekolah Tinggi Teknik Surabaya

7 Something.java Something.class

class Something { public static void main(String[] args) { System.out.println(“Hello World!"); } 8 © Sekolah Tinggi Teknik Surabaya

9

» Started with a letter or dollar sign “$” or underscore “_” ˃ line, _line, $line » Subsequent characters may be letters, digits, dollar signs, or underscore characters » Variable names must be in mixed case starting with lowercase ˃ line, inputLine, i, j, currNode 10 © Sekolah Tinggi Teknik Surabaya

» Must be all uppercase using underscore to separate words ˃ final int NUMBER_OF_HOURS_IN_A_DAY = 24; 11 © Sekolah Tinggi Teknik Surabaya

Data TypesRemark Default Value byte8-bit signed: -128 to 127 (inclusive)0 short16-bit signed: to (inclusive)0 int 32-bit signed: -2,147,483,648 to 2,147,483,647 (inclusive) 0 long 64-bit signed: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (inclusive) 0 float32-bit floating point0.0f double64-bit floating point0.0d boolean true or false false char16-bit unicode character'\u0000' String- null 12 © Sekolah Tinggi Teknik Surabaya

» The source code representation of a fixed value; literals are represented directly in your code without requiring computation. » Example boolean result = true; char capitalC = 'C'; byte b = 100; short s = 10000; int i = ; 13 © Sekolah Tinggi Teknik Surabaya

// The number 26, in decimal int decVal = 26; // The number 26, in hexadecimal int hexVal = 0x1a; // The number 26, in binary int binVal = 0b11010; 14 © Sekolah Tinggi Teknik Surabaya

double d1 = 123.4; /** * same value as d1, * but in scientific notation **/ double d2 = 1.234e2; float f1 = 123.4f; 15 © Sekolah Tinggi Teknik Surabaya

» The Java programming language also supports a few special escape sequences for char and String literals: ˃\b (backspace) ˃\t (tab) ˃\n (line feed) ˃\f (form feed) ˃\r (carriage return) ˃\" (double quote) ˃\' (single quote) ˃\\ (backslash). 16 © Sekolah Tinggi Teknik Surabaya

long creditCardNumber = 1234_5678_9012_3456L; long socialSecurityNumber = 999_99_9999L; float pi = 3.14_15F; long hexBytes = 0xFF_EC_DE_5E; long hexWords = 0xCAFE_BABE; long maxLong = 0x7fff_ffff_ffff_ffffL; byte nybbles = 0b0010_0101; long bytes = 0b _ _ _ ; » Constraints: ˃At the beginning or end of a number ˃Adjacent to a decimal point in a floating point literal ˃Prior to an F or L suffix ˃In positions where a string of digits is expected 17 © Sekolah Tinggi Teknik Surabaya

OperatorsPrecedence postfixexpr++ expr-- unary++expr --expr +expr -expr ~ ! multiplicative* / % additive+ - shift > >>> relational = instanceof equality== != bitwise AND& bitwise exclusive OR^ bitwise inclusive OR| logical AND&& logical OR|| ternary? : assignment = += -= *= /= %= &= ^= |= >= >>>= 18 © Sekolah Tinggi Teknik Surabaya

19

20 © Sekolah Tinggi Teknik Surabaya

// declares an array of integers int[] anArray; 21 © Sekolah Tinggi Teknik Surabaya

// create an array of integers anArray = new int[10]; // create + initializing int[] anArray = { 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 }; // accessing System.out.println ("Element 1 at index 0: " + anArray[0]); 22 © Sekolah Tinggi Teknik Surabaya

23

» if-then Statement if (isMoving){ currentSpeed--; } » if-then-else Statement if (testscore >= 90) { grade = 'A'; } else if (testscore >= 80) { grade = 'B'; } else if (testscore >= 70) { grade = 'C'; } else if (testscore >= 60) { grade = 'D'; } else { grade = 'F'; } 24 © Sekolah Tinggi Teknik Surabaya

switch (month) { case 1: monthString = "January"; break; case 2: monthString = "February"; break; case 3: monthString = "March"; break; default: monthString = "Invalid month"; break; } 25 © Sekolah Tinggi Teknik Surabaya

while (count < 11) { System.out.println("Count is: " + count); count++; } do { System.out.println("Count is: " + count); count++; } while (count < 11); 26 © Sekolah Tinggi Teknik Surabaya

for(int i=1; i<11; i++){ System.out.println("Count is: " + i); } 27 © Sekolah Tinggi Teknik Surabaya

28

abstractassertbooleanbreak bytecasecatchchar classconstcontinueDefault dodoubleelseEnum extendsfinalfinallyFloat forgotoifImplements importinstanceofintInterface longnativenewPackage privateprotectedpublicReturn shortstaticstrictfpsuper 29 © Sekolah Tinggi Teknik Surabaya

This page is intentionally left blank © Sekolah Tinggi Teknik Surabaya 30

» Language Basics, ava/nutsandbolts/index.html ava/nutsandbolts/index.html 31 © Sekolah Tinggi Teknik Surabaya