SYDE223 Tutorial 3: Introduction to Java Annie En-Shiun Lee January 19, 2010.

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

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Introduction to Control Statements Presented by: Parminder Singh BCA 5 th Sem. [ Batch] PCTE, Ludhiana 5/12/ Control Statements.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
Principles of Object-Oriented Software Development The language Java.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Hello, world! Dissect HelloWorld.java Compile it Run it.
Introduction to Java Programming Language Junji Zhi University of Toronto 1.
Introduction to Programming G51PRG University of Nottingham Revision 2 Essam Eliwa.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Control Structures special statements whose purpose is to change the order of execution in a program. Sequential structures – Statements executed sequentially.
DAT602 Database Application Development Lecture 5 JAVA Review.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
Distributed Systems (236351) Tutorial 1 - Getting Started with Visual Studio C#.NET.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
Expressions An expression is a series of variables, operators, and method calls (constructed according to the syntax of the language) that evaluates to.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
1 Chapter 2: Java Fundamentals cont’d Spring Lory Al Moakar.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Selection statements Repetition statements. Lesson plan Main concepts Practice session –If- then –Switch –Nested if.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
Language Basics. VariablesOperators Expressions, Statements and Blocks Control Flow Statements.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
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,
AP Refresher Module Introduction to Java Advanced Programming. All slides copyright: Chetan Arora.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Features of JAVA PLATFORM INDEPENDENT LANGUAGE JAVA RUNTIME ENVIRONMENT (JRE) JAVA VIRTUAL MACHINE (JVM) JAVA APP BYTE CODE JAVA RUNTIME ENVIRONMENT.
Introduction to Object-oriented Programming
Information and Computer Sciences University of Hawaii, Manoa
Objects as a programming concept
Java Language Basics.
SWE 510: Object Oriented Programming in Java
University of Central Florida COP 3330 Object Oriented Programming
Yanal Alahmad Java Workshop Yanal Alahmad
Lecture 2: Data Types, Variables, Operators, and Expressions
Website: SSD1 Unit 2 Intro to Java Presentation 2.3 Website:
University of Central Florida COP 3330 Object Oriented Programming
University of Central Florida COP 3330 Object Oriented Programming
Programming Language Concepts (CIS 635)
Introduction to Programming in Java
CET 3640 – Lecture 2 Java Syntax Chapters 2, 4, 5
Starting JavaProgramming
null, true, and false are also reserved.
Introduction to Java Programming
An Introduction to Java – Part I, language basics
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
Pemrograman Dasar Smt I 2004/2005
In this class, we will cover:
Session 2: Introduction to Object Oriented Programming
In this class, we will cover:
Introduction to java Part I By Shenglan Zhang.
Presentation transcript:

SYDE223 Tutorial 3: Introduction to Java Annie En-Shiun Lee January 19, 2010

Outline 1.Java v.s. C++ 2.Language Basics 3.HelloWorld example 4.Introduction to OOP

1. Java v.s. C++

Java v.s. C++ Smaller/easier Object Oriented Programming (OOP) Single inheritance Platform independence

Java v.s. C++ Platform independence

Java v.s. C++ Java Virtual Machine No Pointers or Templates Extensive Library Simpler String and Data Structures

2. Language Basics

Variables Scope & Types – Instance variable (non static) – Class variable (static fields) static int numGears = 6; – Local variable – Parameter public static void main(String[] args)

Variables Primitive data – Byte – Short – Int – Long – Float – Double – Boolean – Char – NOTE: String is an “object”

Operators Assignment – Operand = value – Ex. int i = 0 Arithmetic: +, -, *, /, % (remainder) – Math – 2 operands

Operators Unary: +, -, ++, --, ! – One operand act on one variable – Ex. Int i = 1 i = -i i++;

Operators Equality – == – != – > – >= – < – <= conditional operators – && – ||

Operators int value1 = 1; int value2 = 2; if(value1 == value2) System.out.println("value1 == value2"); if(value1 != value2) System.out.println("value1 != value2"); if(value1 > value2) System.out.println("value1 > value2"); if(value1 < value2) System.out.println("value1 < value2"); if(value1 <= value2) System.out.println("value1 <= value2"); if((value1 == 1) && (value2 == 2)) System.out.println("value1 is 1 AND value2 is 2"); if((value1 == 1) || (value2 == 1)) System.out.println("value1 is 1 OR value2 is 1");

If-then, if-else-then int testscore = 76; char grade; 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'; } System.out.println("Grade = " + grade); }

Switch int month = 8; switch (month) { case 1: System.out.println("January"); break; case 2: System.out.println("February"); break; case 3: System.out.println("March"); break; case 4: System.out.println("April"); break; case 5: System.out.println("May"); break; case 6: System.out.println("June"); break; case 7: System.out.println("July"); break; case 8: System.out.println("August"); break; case 9: System.out.println("September"); break; case 10: System.out.println("October"); break; case 11: System.out.println("November"); break; case 12: System.out.println("December"); break; default: System.out.println("Invalid month.");break;

While while (expression) { statement(s) } int count = 1; while (count < 11) { System.out.println("Count is: " + count); count++; }

Do-While do{ statement(s) } while (expression) int count = 1; do { System.out.println("Count is: " + count); count++; } while (count < 11);

For for (initialization; termination; increment){ statement(s) } for(int i=1; i<11; i++){{ System.out.println("Count is: " + count); }

3. Hello World Example

“Main” method Each executable Java application has a “main” method. Using the keyword “private” one can restrict the access to methods to the classes within the same directory “void” means the method returns no object

4. Intro to OOP

Object Oriented Programming object has 2 characteristics – state, – behaviour Ex. Dog – State – name, color, breed, mood Mood = sad, happy, angry – Behaviour – barking, wagging tail, whining Ex. Java – State – Object store fields – Behaviour – methods

Object Oriented Programming Advantages – Modularity – Information-hiding – Code re-use – Pluggability and debugging ease

Objects Instance of the class of objects Ex. Professor Tizhoosh’s dog is named “alpha” Ex. Annie the TA’s dog is named “beta” Ex. Student A’s dog is named “delta”

Inheritance A class inherit commonly used state and behaviour from other class – Ex. Dog  small dog, big dog class SmallDog extends Dog { // new fields and methods defining a Dog would go here }

Inheritance A class inherit commonly used state and behaviour from other class – Ex. Dog  small dog, big dog class SmallDog extends Dog { // new fields and methods defining a Dog would go here class SmallDog extends Dog { // new fields and methods defining a Dog would go here } }