308-203A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.

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

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
Java Syntax Primitive data types Operators Control statements.
Some basic I/O.
BASIC JAVA. Hello World n // Hello world program public class MyFirstJavaProgram { public static void main(String args[]) { char c = 'H'; String s =
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
JAVA PROGRAMMING PART II.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Java Building Elements Lecture 2 Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University
DAT602 Database Application Development Lecture 5 JAVA Review.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
“Introduction to Programming With Java” Lecture - 6 U MESH P ATIL
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
JAVA—Bitwise. Compiling/Executing a Java Application Source Code Java Compiler ByteCode > Java Interpreter Machine Code >
From C++ to Java A whirlwind tour of Java for C++ programmers.
Problem Solving using the Java Programming Language May 2010 Mok Heng Ngee Day 5: Arrays.
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.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
 The if statement and the switch statement are types of conditional/decision controls that allow your program.  Java also provides three different looping.
Primitive data Week 3. Lecture outcomes Primitive data – integer – double – string – char – Float – Long – boolean Declaration Initialisation Assignments.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
OOP (pre) Basic Programming. Writing to Screen print will display the string to the screen, the following print statement will be appended to the previous.
August 6, 2009 Data Types, Variables, and Arrays.
Java Programming Java Basics. Data Types Java has two main categories of data types: –Primitive data types Built in data types Many very similar to C++
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
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.
“Great leaders are never satisfied with current levels of performance. They are restlessly driven by possibilities and potential achievements.” – Donna.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
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.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Programming in JAVA – II (A Whirlwind Tour of Java) Course Lecture Slides.
Object Oriented Programming Lecture 2: BallWorld.
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement.
Chapter 4: Control Structures I
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Lecture 2: Data Types, Variables, Operators, and Expressions
Primitive Data, Variables, Loops (Maybe)
An Introduction to Java – Part I
Chapter 2.
Introduction to Programming in Java
null, true, and false are also reserved.
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Java so far Week 7.
Chapter 2: Java Fundamentals
Control Structure Chapter 3.
Java’s Central Casting
Names of variables, functions, classes
Arrays Wellesley College CS230 Lecture 02 Thursday, February 1
Agenda Types and identifiers Practice Assignment Keywords in Java
Control Structure.
Presentation transcript:

A Introduction to Computing II Lecture 1: Java Review Fall Session 2000

Primitive data types Type byte char short int long float double boolean Values [-128, 127] [0, 65,536] [-32,768, 32,767] [-2,147,483,648, 2,147,483,647] [-9,223,372,036,854,775,807, 9,223,372,036,854,775,806] [ e-45, e+38] [ e-324, e+308] { false, true} Size 8 bit 16 bit 32 bit 64 bit 32 bit 64 bit “1 bit”

Variable declarations [ = ] ; Examples: char x = ‘a’; int i, j = 5, k; float pi = ;

Variable declarations [ = ] ; Examples: char x = ‘a’; int i, j = 5, k; float pi = ; ‘a’ x

Variable declarations [ = ] ; Examples: char x = ‘a’; int i, j = 5, k; float pi = ; ‘a’ x ?? i 5 j k

Variable declarations [ = ] ; Examples: char x = ‘a’; int i, j = 5, k; float pi = ; ‘a’ x ?? i 5 j k pi

Assignments and expressions = ; Examples: double pi, radius, circ;... circ = 2 * pi * radius ; int x; boolean xGreaterThanFive;... xGreaterThanFive = (x > 5);

Assignments and expressions = ; Examples: double pi, radius, circ;... circ = 2 * pi * radius ; int x; boolean xGreaterThanFive;... xGreaterThanFive = (x > 5); pi 1.0 radius circ ????

Assignments and expressions = ; Examples: double pi, radius, circ;... circ = 2 * pi * radius ; int x; boolean xGreaterThanFive;... xGreaterThanFive = (x > 5); pi 1.0 radius circ =

Assignments and expressions = ; Examples: double pi, radius, circ;... circ = 2 * pi * radius ; int x; boolean xGreaterThanFive;... xGreaterThanFive = (x > 5); 10 x xGreaterThanFive ????

Assignments and expressions = ; Examples: double pi, radius, circ;... circ = 2 * pi * radius ; int x; boolean xGreaterThanFive;... xGreaterThanFive = (x > 5); 10 x xGreaterThanFive true =

Type-casting ( ) Converts one type to another. Examples: float f = 1.5; int j = (int) f; // j == 1 short s = 200; double d = (double) s; // d == 2.0e2

Strings and Arrays Examples: String str = “Hi there”; char myArr[3]; myArr[0] = ‘c’; myArr[1] = ‘a’; myArr[2] = ‘t’;

Strings and Arrays Examples: String str = “Hi there”; char myArr[3]; myArr[0] = ‘c’; myArr[1] = ‘a’; myArr[2] = ‘t’; str “Hi there”

Strings and Arrays Examples: String str = “Hi there”; char myArr[3]; myArr[0] = ‘c’; myArr[1] = ‘a’; myArr[2] = ‘t’; str “Hi there” myArr ?? [0] [1] [2]

Strings and Arrays Examples: String str = “Hi there”; char myArr[3]; myArr[0] = ‘c’; myArr[1] = ‘a’; myArr[2] = ‘t’; str “Hi there” myArr ‘c’ ‘a’ ‘t’ [0] [1] [2]

A simple program public class hello { public static void main(String args[ ]) { System.out.println(“Hello world”); }

Making decisions (If only the only “if ” in “life” were between the “l” and the “e”) if ( ) then ; Example int x = 10; if (x > 5) { System.out.println(“x is greater than 5”); }

Making decisions (If only the only “if ” in “life” were between the “l” and the “e”) if ( ) then ; Example int x = 10; boolean xGreaterThanFive = (x > 5); if (xGreaterThanFive) { System.out.println(“x is greater than 5”); }

Making decisions ? : Shorthand for if x = (condition ? a : b); if (condition) x = a ; else x = b ;

Making decisions ? : Example int x = 10; System.out.println( (x>5) ? “x is greater than 5” : “x is less than 6”);

Making decisions switch ( ) { case : ; … default: }

Making decisions Example: char myChar = getAChar(); switch (myChar) { case ‘a’: option_a(); break; case ‘b’: option_b(); break; case ‘c’: option_c(); break; default: System.out.println(“Unknown option”); }

Loops while ( ) ; Example: int j = 0; while (j < 3) { System.out.println(j); j++; } Output: 0 1 2

Loops do while ( ); Example: int j = 0; do { System.out.println(j); j++; } while (j < 3) ; Output: 0 1 2

Loops for ( ; ; ) ; Example: for (int j = 0; j < 3; j++) System.out.println(j); Output: 0 1 2

Another simple program public class reverse { public static void main(String args[ ]) { for (int i = args.length-1; i >= 0; i--) System.out.println(args[i] + “ ”); System.out.println(“\n”); }

Reference variables The variable “points” to some data somewhere is the kind of object being referenced Strings and arrays are treated as references (as are user-defined types) Special value: null ;

Reference variables Example: Thing x = theBlob; Thing y = null; y = x; boolean same = (x == y); null x y theBlob

Reference variables Example: Thing x = theBlob; Thing y = null; y = x; boolean same = (x == y); x y theBlob ??? same

Reference variables Example: Thing x = theBlob; Thing y = null; y = x; boolean same = (x == y); x y theBlob true same

Strings are references, too Example: String a = “YO!”; String b = “YO!”; boolean same = (a == b);

Strings are references, too Example: String a = “YO!”; String b = “YO!”; boolean same = (a == b); a “YO!”

Strings are references, too Example: String a = “YO!”; String b = “YO!”; boolean same = (a == b); a “YO!” b

Strings are references, too Example: String a = “YO!”; String b = “YO!”; boolean same = (a == b); a “YO!” b false!! same

Strings are references, too Example: String a = “YO!”; String b = “YO!”; boolean same = a.equals(b); a “YO!” b true same

Arrays are references, too Example: int[ ] foo = new int[2]; int[ ] bar = foo; foo[0] = 523; bar[0] = 325; System.out.println(foo[0]);

Arrays are references, too Example: int[ ] foo = new int[2]; int[ ] bar = foo; foo[0] = 523; bar[0] = 325; System.out.println(foo[0]); foo ?? [0] [1]

Arrays are references, too Example: int[ ] foo = new int[2]; int[ ] bar = foo; foo[0] = 523; bar[0] = 325; System.out.println(foo[0]); foo ?? [0] [1] bar

Arrays are references, too Example: int[ ] foo = new int[2]; int[ ] bar = foo; foo[0] = 523; bar[0] = 325; System.out.println(foo[0]); foo 523 ?? [0] [1] bar

Arrays are references, too Example: int[ ] foo = new int[2]; int[ ] bar = foo; foo[0] = 523; bar[0] = 325; System.out.println(foo[0]); foo 325 ?? [0] [1] bar

Arrays are references, too Example: int[ ] foo = new int[2]; int[ ] bar = foo; foo[0] = 523; bar[0] = 325; System.out.println(foo[0]); foo 325 ?? [0] [1] bar Output: 325!!!

Arrays are references, too Example: int[ ] foo = new int[2]; int[ ] bar = (int[ ]) foo.clone(); foo[0] = 523; bar[0] = 325; System.out.println(foo[0]); foo 523 ?? [0] [1] bar 523 ?? [0] [1]

Arrays are references, too Example: int[ ] foo = new int[2]; int[ ] bar = (int[ ]) foo.clone(); foo[0] = 523; bar[0] = 325; System.out.println(foo[0]); foo 523 ?? [0] [1] bar Output: ?? [0] [1]

Any Questions?