1 / 18

IDS 201 Introduction to Business Programming (Fall 2013)

IDS 201 Introduction to Business Programming (Fall 2013). Week1. Interface.

taini
Download Presentation

IDS 201 Introduction to Business Programming (Fall 2013)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IDS 201Introduction to Business Programming (Fall 2013) Week1

  2. Interface • There are a number of situations in software engineering when it is important for disparate groups of programmers to agree to a "contract" that spells out how their software interacts. Each group should be able to write their code without any knowledge of how the other group's code is written. Generally speaking, interfaces are such contracts.

  3. Example public interface OperateCar{ // constant declarations, if any method signatures // An enum with values RIGHT, LEFT intturn(Direction direction, double radius, double startSpeed, double endSpeed); intchangeLanes(Direction direction, double startSpeed, double endSpeed); intsignalTurn(Direction direction, booleansignalOn); intgetRadarFront(double distanceToCar, double speedOfCar); intgetRadarRear(double distanceToCar, double speedOfCar); ...... // more method signatures } The method signatures have no braces and are terminated with a semicolon.

  4. IDE: Eclipse • Download and install on your computers http://www.eclipse.org/downloads/

  5. Identifier • An identifier in Java can be a variable name, function/subroutine/method name, class name, or object name. • It is a sequence of one or more characters. It must begin with a letter or underscore and must consist entirely of letters, digits, and underscores. • No space is allowed in identifiers. • Case-sensitive: Upper case and lower case letters are considered to be different. • Some reserved words in Java can not be used for other purposes. (e.g. public, class, int, static, main, if, while, …)

  6. Valid or Non-valid? • N • abc • 201ids • _ids • _201ids • Hello World • helloWorld • hElloWORLD • A_long_string_name • public • public_static

  7. Camel Case • When a name / an identifier is made up of several words, such as HelloWorld or interestRate, it is customary to capitalize each word, except possibly the first; this is sometimes referred to as camel case.

  8. Compound Names • Consist of several ordinary names separated by periods. (Compound names are also called qualified names. e.g. System.out.println) • A compound name is a kind of path to an item through one or more levels of containment.

  9. Variable • A name used to refer to data stored in memory is called a variable. • Can store different types of data. • Integer, real number, string, objects… • Data can change. Physical address Name variable1 00101110 00101111 00110000 variable2 … …… variable3 10111010 ……

  10. Declare and Define Variables • Declaration means creating a primitive or Object reference variable, but with no assignment of value or object respectively. • int x; // declaration of x of type int • Car myCar; // declaration of myCar an object of type Car • Definition is when we assign values or Object to them. • int x = 5; • Car myCar = new Car();

  11. Assignment • Two ways to assign a vale to a variable. • Declare a variable first and then do assignment int x; x = 5; • Define a variable • int x = 5;

  12. Assignment • Two steps to assign values to variables ⟨variable⟩ = ⟨expression⟩; Calculate the expression value Assign the calculated value to the variable • e.g. value = 2*3; value = 5; value = value + 12;

  13. Types and Literals • 8 primitive types • byte, short, int, long • float, double • Char • boolean • Any data value stored in the computer’s memory must be represented as binary numbers: 0, 1. • One single 0 or 1 is called one bit. • 1 byte = 8 bits Integers Real Numbers Single Character One of Two Logic Values

  14. Binary Number Each digit"1" in a binary number represents a power of two, and each "0" represents zero (index starts from 0, direction: right to left) 0001 is 2 to the zero power, or 1 0010 is 2 to the 1st power, or 2 0100 is 2 to the 2nd power, or 4 1000 is 2 to the 3rd power, or 8. 0111 = 0 + 4 + 2 + 1 = 7 An N-bit two's-complement numeral system can represent every integer in the range −(2N− 1) to +(2N− 1 − 1)

  15. Range of Primitive Types

  16. Real Numbers • The maximum value for a float is about 1038. A float can have about 7 significant digits. (So that 32.3989231134 and 32.3989234399 would both have to be rounded off to about 32.398923 in order to be stored in a variable of type float. • A double takes up 8 bytes, can range up to about 10308, and has about 15 significant digits. • Usually, we use double for real numbers.

  17. char • It occupies 2 bytes in memory. • A character in a program must be surrounded by single quotes. ‘A’, ‘*’,’_’, etc. • The quotes are not part of the value and are not stored in the variables.

  18. Literals • A name for a constant value is called a literal. • Character literals • ‘A’, ‘*’, ‘\t’: tab, ‘\n’: linefeed, ‘\’’: single quote, ‘\\’: backslash • Real literals • double: 1.2, 1.2e3 :1.2*103 • float: 1.2F • Integer literals • Ordinary integers such as 1000 and -32 are literals of type byte, short, or int, depending on their size. You can make a literal of type long by adding “L” as a suffix.

More Related