Programming Environments

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.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
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.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Programming Environments DrJava is not Java! It is an integrated environment for developing Java programs DrJava integrates the Edit => Compile => Run.
Hello, world! Dissect HelloWorld.java Compile it Run it.
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
Java Basics. Java High-level language  More readable for humans  Need to be translated to machine language for execution Compilers  CPU-independent.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Today’s topic:  Arithmetic expressions. Arithmetic expressions  binary (two arguments) arithmetic operators  +, -, *, /, % (mod or modulus)  unary.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Mixing integer and floating point numbers in an arithmetic operation.
Primitive Data Types. Identifiers What word does it sound like?
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Final Jeopardy Fundamen tal Java Numerical Data type Boolean Expressi on If/THEN/ WHILE Miscellan eous
COMP Primitive and Class Types Yi Hong May 14, 2015.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
Topic 4 Expressions and variables Based on slides bu Marty Stepp and Stuart Reges from "Once a person has understood.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Georgia Institute of Technology Introduction to Java, and DrJava part 1 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology.
Object Oriented Programming Lecture 2: BallWorld.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Information and Computer Sciences University of Hawaii, Manoa
Basic concepts of C++ Presented by Prof. Satyajit De
Programming Environments
Chapter 2 Variables.
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Today’s topic: Arithmetic expressions.
Chapter 2 Basic Computation
Primitive Data, Variables, Loops (Maybe)
Java package classes Java package classes.
Computer Programming Methodology Introduction to Java
Chapter 2 Basic Computation
Building Java Programs Chapter 2
Principles of Computer Programming (using Java) Chapter 2, Part 1
Unit-2 Objects and Classes
An Introduction to Java – Part I, language basics
Introduction to Java, and DrJava part 1
Building Java Programs
Building Java Programs
Chapter 2 Variables.
Sridhar Narayan Java Basics Sridhar Narayan
Java Basics.
Variables & Data Types Java.
Building Java Programs
Building Java Programs Chapter 2
CS 200 Primitives and Expressions
Introduction to Java, and DrJava
Chapter 2 Programming Basics.
Building Java Programs
Introduction to Primitives
Introduction to Primitives
Building Java Programs
Building Java Programs Chapter 2
Introduction to Java, and DrJava
Introduction to Java, and DrJava part 1
Chapter 2 Variables.
Just Enough Java 17-May-19.
Agenda Packages and classes Types and identifiers Operators
Building Java Programs
Presentation transcript:

Programming Environments DrJava is not Java! It is an integrated environment for developing Java programs DrJava integrates the Edit => Compile => Run cycle Other: jGrasp, BlueJ, Eclipse

Java Program Development Cycle Edit => Compile => Run Edit: create Program.java Compile: create Program.class javac Program.java Run java Program Program.java – human readable Program.class – machine readable

Compiled vs Interpreted Language Compiled – whole program is translated before it can be run; once compiled can run many times Ensures that the whole program obeys language rules Analogy: Translating a book before it can be mass printed Interpreted – only the line currently executing is translated; re-translated every time the program is run Allows for immediate feedback, faster development cycle Analogy: Translator for a guest speaker

Java Primitive Types boolean – for true/false values char – for single character values short, int, long – for integer values short [ -32,768 … 32,767 ] int [ -2,147,483,648 … 2,147,483,647 ] long [ -9,223,372,036,854,775,808 … 9,223,372,036,854,775,807 ] float, double – for real values float has smaller range than double

In how many ways can you say X = X + 1 ? X = X – 1; X = X * 5; X = X / 5; X -= 1; X *= 5; X /= 5; X--; --X; you are you’re u r Java Only

X++ vs ++X X = 5; X = 5; Y = X++; Y = ++X; Y is now 5 X is now 6 2: update the value of X 1: update the value of X Y = X++; Y = ++X; 1: “use” the value of X 2: “use” the value of X Y is now 5 X is now 6 X is now 6 Y is also 6

System.out.println(X++); System.out.println(++X); X++ vs ++X X = 5; X = 5; 2: update X 1: update X System.out.println(X++); System.out.println(++X); 1: “use” the value of X 2: “use” the value of X displays 5 X is now 6 X is now 6 displays 6

Integer Division Dividing integers always yields integer value 7 / 3 = 2 int x = 7; int y = 3; int z1 = x / y; // z1 is now 2 double z2 = x / y; // z2 is now 2 In Matlab true division Remainder operator % 7 / 3 = 2 and 1 left over, so 7 % 3 = 1 9 / 5 = 1 and 4 left over, so 9 % 5 = 4 21 / 5 = 4 and 1 left over, so 21 % 5 = 1 In Matlab rem( a, b )

Remainder % Operator Use if ( n % 2 == 0 ) { System.out.println( “n is even “ ); } if ( n % 5 == 0 ) System.out.println( “n is divisible by 5 “ ); player = ( player + 1 ) % n;

do-while loop while ( something-is-true ) { action 1; action 2; ... action n } do-while guaranteed to execute at least once do { action 1; action 2; ... action n } while ( something-is-true ) Java Only

return in void methods void drawCirclesRow( double x, double y, double r, int n) { if (n <= 0) return; // OK when without value } ... rest of the code here ...

Enhanced for Loop void printArray( double[] data ) { for (int i = 0; i < data.length; i = i + 1) double curValue = data[ i ]; System.out.print( curValue + “ “ ); }

Enhanced for Loop void printArray( double[] data ) { for (int i = 0; i < data.length; i = i + 1) double curValue = data[ i ]; System.out.print( curValue + “ “ ); } void printArray( double[] data ) { for (double curValue : data ) System.out.print( curValue + “ “ ); } for each value in data

Enhanced for Loop void printArray( double[] data ) { for (int i = 0; i < data.length; i = i + 1) double curValue = data[ i ]; System.out.print( curValue + “ “ ); } void printArray( double[] data ) { for (double curValue : data ) System.out.print( curValue + “ “ ); } for each value in data

Enhanced for Loop void dawBalloons( ) { for (int i = 0; i < balloons.length; i = i + 1) Balloon b = balloons.get( i ]); b.draw(); } void drawBalloons( ) { for (Balloon b : balloons ) b.draw(); } for each balloon ...