1 / 12

CS140 Programming with Objects

CS140 Programming with Objects. Dick Steflik. What is Java. Besides being the black/brown stuff we drink it is a simple programming language that lets us develop problem solutions in terms of objects and their behaviors. This is known as the Object-Oriented Paradigm (pronounced para-dyme )

asher
Télécharger la présentation

CS140 Programming with Objects

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. CS140Programming with Objects Dick Steflik

  2. What is Java • Besides being the black/brown stuff we drink it is a simple programming language that lets us develop problem solutions in terms of objects and their behaviors. • This is known as the Object-Oriented Paradigm (pronounced para-dyme) • There are other programming languages that follow the O-O paradigm (Smalltalk, Eiffle, C++) each with their own benefits and shortcomings • Currently Java and C++ are the most commonly used

  3. Why Java for CS140 and C++ for CS240 • Java has a simpler and more complete object model • Because of its object model C++ is more complex to use • Java is safer (this will be explained later) • Java is more portable • Java excels at being a network tool where C++ excels as a desktop tool

  4. What is Java used for • Desktop application programming • 2 & 3D graphics Programming • Open Wonderland; 3D modeling, avatars, virtual worlds • JOGL (Java Open GL) • Web programming • Enterprise class servers • JBOSS/Wildfly - RedHat, Glassfish - Oracle, Websphere-IBM • Web services • Applets – Java programs that run in a web browser • Dynamic web pages, Java servlets and Java Server Pages • Mobile application programming – Android

  5. Object Orientation • Think of an object as a small, special purpose computer, complete with it’s own memory (that we’ll call it’s state) and its own set of instructions. • Instructions can be used to modify it’s memory and send /receive messages to/from other objects. • An object can only do the things it is programmed to do. • A program, is then nothing more than a collection of objects sending and receiving messages

  6. Making objects • Like most programming languages “everything must be defined before it can be used” • This is done using the class statementpublic class Example { …} • Always remember that a class is pure definition, by itself it can’t do anything. An analog of this is a cookie cutter, by itself it is just a definition of what the final cookie will look like

  7. Making a cookie • To make a cookie we take our cutter and whomp it down on a piece of cookie dough, now we have a cookie • In Java we take our class and whomp it down on some unused memory and we make an object. This is call “instantiation” or creating an instance of the class. • Each instance of a class is unique and must be identified with a unique identifier/name.

  8. Packages • To prevent coding anarchy we usually group related classes into packages, this also is used to promote the idea of “reuse” (more on this later). • Here is an example: package cs140; class student { … } • This identifies the class student as a member of the package cs140. • More on packages later

  9. Variables • Any memory used by our objects should be defined in the class definition as variable. • Variable identifiers should start with a alpha character and then can be any number of alpha or numeric characters long (can use some special characters like _ and &

  10. Primitive types • Every variable must be defined as being of some type. Types are almost identical to the types used in C and C++ • int, long, double, char, boolean • Each type has a defined range of values (see the table of types in section 4.1) • Generally type tell us three things about a variable: it’s range, it’s operations, and its memory requirements

  11. Some examples • int value = 1; //definition and initializationint total; //definition onlychar letterG = ‘G’; //internally these are in unicode not ascii (like C and C++)char aKoreanCharacter = ‘\ud55c’long aBigNumber = 12345678901234567890L;boolean switch = true;float distance = 315.24674; (32 bit, IEEE754 format, real fractional numbers) double pi = 22/7; // (64 bit, IEEE754 format, high precision real fractional number byte smallNumber = (byte)123; // range from -128 to +127short notSoSmallButNotRealBig = 23456; //range -32768 to +32767 • These are Java’s 8 primitive types, they are built into the language and are sometime call atomic types as they can’t be broken down any smaller. • All other types are types that we create via the class statement and are called “reference” types

More Related