1 / 33

Introduction to Programming

Introduction to Programming. A quick overview of Java, Object Oriented programming and the programming process. Overview. Java: the programming language Object Oriented programming Objects: attributes and method Creating Object Program source file, compilers, byte code, execution.

quincy
Download Presentation

Introduction to Programming

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. Introduction to Programming A quick overview of Java, Object Oriented programming and the programming process

  2. Overview • Java: the programming language • Object Oriented programming • Objects: attributes and method • Creating Object • Program • source file, compilers, byte code, execution

  3. Java: the programming language • A computer programming language • About 20 keywords • Strict syntax rule • Invented last decade (about 1993) • Object-oriented programming language • Java is a general-purpose, concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere."

  4. Characteristics of Java • Java is simple • Java is object-oriented • Java is distributed • Java is interpreted • Java is robust • Java is secure • Java is architecture-neutral • Java is portable • Java’s performance • Java is multithreaded • Java is dynamic

  5. Why Java? • It’s an industry standard • It’s almost entirely object-oriented • It has a vast library of predefined objects and operations • It’s more platform independent • this makes it great for Web programming • It’s more secure • It isn’t C++

  6. JDK Editions • Java Standard Edition (J2SE) • J2SE can be used to develop client-side standalone applications or applets. • Java Enterprise Edition (J2EE) • J2EE can be used to develop server-side applications such as Java servlets and Java ServerPages. • Java Micro Edition (J2ME). • J2ME can be used to develop applications for mobile devices such as cell phones.

  7. Applets, Servlets and Applications • An applet is designed to be embedded in a Web page, and run by a browser • Applets run in a sandbox with numerous restrictions; for example, they can’t read files and then use the network • A servlet is designed to be run by a web server • An application is a conventional program

  8. Object Oriented ProgrammingBasic • We start with the fundamentals ofObject Oriented Programming • Then, we apply these principles in arobot programming environment • Then, we move on to standard programming in Java

  9. The World of Object • The World consists of Objects • Objects are Noun • When we write a program objects are generally used to represent real world objects

  10. Example: Traffic System • Simulate traffic flow, traffic jams • Objects include: • Cars • Trucks • Pedestrians • Traffic Lights • The Road itself

  11. Graphical Drawing System • Allow user to draw shapes and manipulate them on screen • Objects include • Circle • Rectangle • Line

  12. Objects have a state - Attributes • An attribute is any characteristic of an object, e.g. Colour, shape etc

  13. Objects Can Do Things - Methods • An object has operations it can perform - built right into it, e.g. move

  14. Basic Objects • Objects • Nouns, things in the world • Attributes • Properties each of these things have • Methods • Actions that each of these things can do

  15. Lets Consider Shapes • Shapes have a state - attributes • Attributes of a shape: • Filled, line width, line colour, fill colour, location • Shapes can do things methods • Methods of a shape: • Fill, Empty, Move, Grow

  16. Each Shape is an Object • Properties of a Shape • Filled • Line width • Line colour • Location • Fill colour • Methods of a shape • Fill • Empty • Move • Grow

  17. There is a Structure Here • There are certain shapes of a related kind • This prototype is called a Class • Each circle is different, but they are all instances of the class Circle

  18. Each Object is an Instance of a Class • An Instance of the Class “Circle” • Two Instances of the Class “Square” • An Instance of the Class “Line”

  19. Classes • A Class is an abstract description of objects having the same attributes and methods • A specific Object is an instance of a Class • A Class is the cookie cutter - An Object is the cookie

  20. Many Different Objects from a single class

  21. How Do We Create an Object? • We use a constructor • This takes a Class and creates an Instance of the class, an object, perhaps with certain properties • “Construct an Instance of the Class Person, give it the name bill, and make its Age be 18, its height be 5 foot 9, and its weight be 12 stone.”

  22. How Do We Create an Object? • Presto! We now have an object bill, with certain attributes, and with the method Move • Bill’s Move method can now be executed

  23. Object Vocabulary • Class: Definition of an object • Objects: Nouns, things in the world. An Object is an instance of a Class • Constructor: Creates an Object from a Class • Attributes: Properties of an object • Methods: Actions that an object can do

  24. Objects and Java • Java has a keyword class which is used to create an object prototype • Every Java program defines at least one class • Here is an example

  25. So what exactly is a program?

  26. Creating and Compiling Programs • On command line • javac file.java

  27. Executing Applications • On command line • java classname

  28. Compiling a Java Program • The class file is generated from the source code by a compiler • You can run the compiler as shown below • The compiler is called javac • H:\javac House.java

  29. Steps to a program • Create the program file, e.g. House.java • Compile the file House.java to create the file House.class • H:\>javac House.java • Check that the file House.class was created (use the directory command) • The DIR command shows the newly created class file • H:\>dir • 13:54 House.java • 13:55 House.class

  30. Objects from classes • Use new to create an instance from a class definition • The instruction new House() creates a new instance of the House class • An instance isn't much use without a name; a name is assigned to an instance using the following instruction • House whiteHouse = new House(); • This creates a new instance of the House object and calls it whiteHouse

  31. A program that does something! • Here is a class which prints something • When this is compiled it can be run by the java program • The program prints Good Morning • public class Hello • { • public static void main(String [] args) • { • System.out.println("Good Morning"); • } • } Hello.java H:\>javacHellojava H:\>java Hello Good Morning H:\>

  32. And that is Programming • Create the source code • Create the class file (by compiling the source) • Run the program You use the java program to execute the class file • Try this on your computer

  33. Name conventions • Java is case-sensitive; maxval, maxVal, and MaxVal are three different names • Class names begin with a capital letter • All other names begin with a lowercase letter • Subsequent words are capitalized: theBigOne • Underscores are not used in names • These are very strong conventions!

More Related