CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Programming in JAVA – II (A Whirlwind Tour of Java) Course Lecture Slides.

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.
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
Lecture 2: Object Oriented Programming I
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Review Java.
Hello, world! Dissect HelloWorld.java Compile it Run it.
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
DAT602 Database Application Development Lecture 5 JAVA Review.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
CSE 131 Computer Science 1 Module 1: (basics of Java)
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.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Slides prepared by Rose Williams, Binghamton University Chapter 5 Defining Classes II.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Universidad Nacional de Colombia Facultad de Ingeniería Departamento de Sistemas ertificación en AVA.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Controlling Program Flow. Data Types and Variable Declarations Controlling Program Flow.
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.
Introduction to Java Java Translation Program Structure
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
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.
CompSci 100E JB1.1 Java Basics (ala Goodrich & Tamassia)  Everything is in a class  A minimal program: public class Hello { public static void main(String[]
Object Oriented Programming Lecture 2: BallWorld.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Methods, classes, and Objects Dr. Jim Burns. Question  Which of the following access modifiers is the default modifier?  public  private  protected.
Information and Computer Sciences University of Hawaii, Manoa
Introduction to Classes and Objects
Elementary Programming
Yanal Alahmad Java Workshop Yanal Alahmad
Yanal Alahmad Java Workshop Yanal Alahmad
Lecture 2: Data Types, Variables, Operators, and Expressions
Chapter 2.
Introduction to Programming in Java
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
An Introduction to Java – Part I, language basics
Classes and Objects 5th Lecture
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Recap Week 2 and 3.
Object Oriented Programming in java
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Java Basics Data Types in Java.
In this class, we will cover:
Java’s Central Casting
Classes, Objects and Methods
Presentation transcript:

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Programming in JAVA – II (A Whirlwind Tour of Java) Course Lecture Slides 17 May 2010

JAVA Duke, the JAVA mascot Java 1.0 was first released by Sun Microsystems in Java became popular for web programming. "Write Once, Run Anywhere" (WORA) philosophy. Key design principles: -Platform independence -Security -Stability

How Java works!

Programming in JAVA – I Basic concepts in Java Values Variables Complex data/objects Methods Expressions Conditionals Loops

Programming in JAVA English to JAVA translation: Piece of data: value Kind of data: type Place to store a value: variable Structured group of variables: object Kind of object: class Object of a particular class: class instance Variable belonging to an object: instance variable

Programming in JAVA Values and Types : All data values in Java have a type The type of a value determines: Allowed operations Memory representation Allowed operations Conversion to other types Allowed operations Types are program invariants Help to catch errors Default initial values (if omitted) are based on type

Programming in JAVA Primitive Types: EIGHT basic pre-defined types: values on which Java can operate directly. byte, short, int, long, float, double, boolean, char Plus, special support for character strings - using java.lang.String class

Programming in JAVA - II Numeric Types in Java are characterized by their size (how much memory they occupy) Integral types Floating point types SizeRange (inclusive) byte1 byte-128: 127 short2 bytes-32,768: 32,767 char2 bytes0: 65,535 int4 bytes-2 31 : long8 bytes-2 63 : float4 bytes : ( )·2 127 double8 bytes : ( )·2 1023

Strings Built-in non-primitive type “String” String s1 = “my string”; Strings are sequence of characters “UF” “Pugh Hall” string literals + means concatenation “Pugh” + “ ” + “Hall” => “Pugh Hall” Automatic conversion of numbers to strings “Go” “UF” => Go2UF Text in a String is immutable

Variables Variables store values myScore = 100; isRaining = true; monthlySalary = ; PI = ; myName = “Buzz Aldrin”; All variables must be declared!

Variables Assignment statement “ = “ int myScore = 100; boolean isRaining = true; float monthlySalary = ; double PI = ; String myName = “Buzz Aldrin”; Variables must store values of the correct type myScore = true; isRaining = 1; Prevent nonsensical calculations

Initializing Variables Preferred usage: Combine declaration and value initialization in one step: String myCar = “Mustang”; Boolean isRaining = true; Default initial values (unless specified) are based on type.

Default type values Default initial values (unless explicitly specified) are based on type. TypeDefault value byte0 short0 int0 long0L float0.0f double0.0d char'\u0000' String (or any Object) null booleanfalse

Methods A set of instructions referenced by a name that can be called whenever required public class Report{ public static void main(String args[]){ printHelloWorld(); } //simple print method public static void printHelloWorld(){ System.out.println(“Hello World!”); }

Demystifying the main( ) method public static void main (String args[ ]) “The boss function!” : When you execute a class with the Java interpreter, the runtime system starts by calling the class's main() method. The main() method then calls all the other methods required to run your application. The keyword public indicates that the method can be called by any object. The keyword static indicates that the method is a class method, which can be called without the requirement to instantiate an object of the class. The keyword void indicates that the method doesn't return any value. String args[] - “an array of strings”: Mechanism through which the runtime system passes command line arguments to your application.

“Parameters” vs “Arguments” Parameters specify data that must be provided in an invocation public getName (String ufid, int year) { … searchUFID = ufid; searchYear=year; … } Arguments are the actual values supplied to a method String name = getName (“ ”, 2010);

Naming Conventions KindIdentifier ClassGradeBook VariableinitialGrade ConstantMAXIMUM_GRADE MethodgetStudentGrade

Java Expressions Compute values of different types Boolean values: 10>5 Numeric values: 2+3, 5%2 String values: “Pugh”+” Hall” Object values: new GradeBook();

Control Flow Statements Use a condition to choose which action to take. If, Else If, Else (Multi-way decisions, Nested decisions) Switch-case While, Do-While For /java/nutsandbolts/flow.html /java/nutsandbolts/flow.html

{ if (latitude > 0) animal = "polar bear"; else animal = "penguin"; } { if (latitude > 0) animal = "polar bear"; else animal = "penguin"; } Control Flow Statements If, Else-If, Else (Multi-way decisions, Nested decisions) public String dominant() { String animal; if (isFrigid()) else animal = “cat"; return animal; } public String transport() { … if (isFrigid()) return "skis"; else if (isTropical()) return "surfboard"; else return "bicycle"; }

Get more info! (Online) Search keywords: Java data types Java basics Floating point numbers Java Class methods vs Instance methods Java statements