getting started java fundamentals csc207 – software design summer 2011 – university of toronto...

16
Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Upload: jeremy-page

Post on 13-Dec-2015

218 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Getting Started

Java Fundamentals

CSC207 – Software Design

Summer 2011 – University of Toronto – Department of Computer Science

Page 2: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Java

• Released in 1995 by Sun Microsystems

• Key characteristics:– Object Oriented language– Suitable for web and network programming– Portable

• Java programs are platform independent

Page 3: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

NetBeans IDE

• You can download it, together with JDK, from:– http://www.oracle.com/technetwork/java/javas

e/downloads/jdk-netbeans-jsp-142931.html

• Quick Start:– Create a new project– Basic Java program structure– The popular “Hello World” !

Page 4: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Project Management

• We use DrProject– https://stanley.cdf.toronto.edu/drproject/csc207-2011-05

– Wiki pages– Code Repository– Project Ticketing – Mailing List !

Page 5: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Code Repository

• Checking out from the repository – Directly to the NetBeans

Team > Subversion > Checkout

– You can check out all of the lecture codes from:

svn co https://stanley.cdf.toronto.edu/svn/csc207-2011-05/All/lectureCode

– Sample Project:• LectureCode1

Page 6: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Programming Fundamentals

• Keywords

• Method

• Variable

• Constant

• Assignment

• Comparison

• Selections

• Iteration• Comment• Containers• Encapsulation• Scoping• Libraries

– Graphics– Input / Output– Network

Page 7: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Java Keywords

Page 8: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Practice Code 1

Write a program which takes two numbers from the input and prints the result of their basic numerical calculations

(addition, subtraction, division, reminder)

Improve the output formatting: \b\t\n\r\"\'\\

backspacetabnewlinecarriage returndouble quotesingle quotebackslash

Page 9: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Primitive Data Types

• Java is a strictly-typed language– All variables must first be declared before they can be used

• int x; // variable declaration• x = 1; // variable assignment

• int y = 2; // variable declaration and assignment

Type

byteshortintlong

floatdouble

Storage

8 bits16 bits32 bits64 bits

32 bits64 bits

Min Value

-128-32,768-2,147,483,648< -9 x 1018

+/- 3.4 x 1038 with 7 significant digits+/- 1.7 x 10308 with 15 significant digits

Max Value

12732,7672,147,483,647> 9 x 1018

Numeric P.D.Ts

Page 10: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Primitive Data Types

• char – All Unicode characters

• boolean– True / False– Boolean b = true;

• String– String name = “Hesam”;– String fullName;– fullName = name + “Esfahani”;

uppercase letterslowercase letterspunctuationdigitsspecial symbolscontrol characters

A, B, C, …a, b, c, …period, semi-colon, …0, 1, 2, …&, |, \, …carriage return, tab, ...

Page 11: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Primitive Data Types

• Default Values

Data Type Default Value (for fields)

byte 0

short 0

int 0

long 0L

float 0.0f

double 0.0d

char '\u0000'

String (or any object)  

null

boolean false

Page 12: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Methods

• Contains program statements– Logically cohesive

• Program is composed of classes

• Each class contains– Methods– Attributes

Page 13: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Comments

• Java Comments are in three forms:

// this comment runs to the end of the line

/* this comment runs to the terminating symbol, even across line breaks */

/** this is a javadoc comment */

Page 14: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Control Structures

• Conditional Statements– If - else– Switch

• Comparison– Equals ==– Not Equal !=– Greater >– Greater or Equal >=– Less than <– Less than or equal <=

• Logic Operations– Logical AND &&– Logical OR II

Practice Code cntd. :

Get the operator from the input, as well.

Practice Code cntd.:

say if the two number are equal, or the greater one

Page 15: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science

Control Structures

• Iteration– While– For– Do - while

Practice Code cntd :

print “a” n times, where n is the result of operation

Page 16: Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science