1 / 16

The Joy of Programming (also known as) Introduction to Object-Oriented Programming

The Joy of Programming (also known as) Introduction to Object-Oriented Programming. Resources. Java in a Nutshell from O’Reilly Java Standard Edition (JSE) download http://www.oracle.com/technetwork/java/javase/downloads/index.html

danil
Download Presentation

The Joy of Programming (also known as) Introduction to Object-Oriented 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. The Joy of Programming (also known as) Introduction to Object-Oriented Programming

  2. Resources • Java in a Nutshell from O’Reilly • Java Standard Edition (JSE) download http://www.oracle.com/technetwork/java/javase/downloads/index.html (download the SDK, not the JRE; you may not want it bundled with NetBeans; you can also download the documentation from this link) • Java API Documentation http://docs.oracle.com/javase/7/docs/api/ • Java Tutorial http://docs.oracle.com/javase/tutorial/index.html • Lots of other stuff http://www.oracle.com/technetwork/java/javase/overview/index.html

  3. What is a computer? processor memory disk data I/O devices instructions

  4. Programming Languages • assembled languages // X = (A+B) * (C+D) LR 1, A // load register 1 from A AR 1, B // add B to register 1 LR 2, C // load register 2 from C AR 2, D // add D to register 2 MP 2, #1 // multiply register 2 by register 1 SR 2, X // store register 2 in X • compiled languages (Fortran, Cobol) X = (A + B) * (C + D) • structured languages (C, Pascal)

  5. Programming Languages (cont.) • object-oriented languages (C++, Ada, Smalltalk, Java) • 4th generation languages: special purpose (RPG, DBASE, Delphi) • databases • proprietary products • visual programming environments /integrated development environments (Visual Basic, Visual C++, JBuilder, Eclipse)

  6. Compiled vs. Interpreted • Compiled Languages source code => compiler => relocatable object code => loader => absolute code • source code is portable (sort of) • object code is platform-specific • Interpreted Languages (Java) source code=> compiler => bytecode => interpreter => absolute code on the fly • bytecode is portable to any platform with an interpreter • interpreting is slower

  7. Java • an object oriented language • an interpreted language • developed by Sun MicroSystems • versions: • JDK v1.7.x • available free from Oracle: http://www.oracle.com/technetwork/java/javase/downloads/index.html

  8. Applications vs. Applets • A program which runs directly on the computer is called an application • programsmay also be downloaded from the web and run in a browser; these are called applets • applets are an outgrowth of Java’s platformindependence, which allows an applet to run in a browser on any machine (PC, MAC, UNIX, …) • applets are subject to security restrictions: • they cannot read or write the local hard drive • they cannot print • they can only talk to the computer that served them

  9. Java Structure • The basic programming element in Java is the class • every class has a name • all instructions and data in Java exist in a class • classes usually contain methods, which also have a name • all instructions in Java exist in a method inside a class (almost)

  10. Application Mechanics • write a class in a text editor; save it to a file with the same name as the class and a .java suffix • set the path: • In the MS-DOS Prompt window set path=%path%;c:\jdk1.4\bin • Windows98, etc.:in C:Autoexec.bat (save the original first) • WindowsXP: Control Panel > System > Advanced > Environment Variables > select Path under System Variables > Edit • compilethe file in an MS-DOS Prompt window: javacMyProgram.java • runthe class in an MS-DOS Prompt window: javaMyProgram

  11. Applet Mechanics • write a class that extends Applet in a text editor; save it to a file with the same name as the class and a .java suffix • compile in an MS-DOS Prompt window: javacMyApplet.java • write an html program to load the applet; save it to a file with .html suffix • load the html file in a browser, or via appletviewer in an MS-DOS Prompt window: appletviewer MyApplet.html • applets usually involve a graphical display, and/or some interaction with the user (GUI)

  12. Hello World Application // the HelloWorld class, in file HelloWorld.java publicclass HelloWorld { // the main method publicstaticvoid main (String[] args) { System.out.println (“Hello World!”); } } • class • method definition • method invocation • method parameters/Strings • comments • keywords (in blue) • curly braces/indentation

  13. Hello World Applet import java.applet.*; import java.awt.*; // the HelloWorldApplet class // (saved as HelloWorldApplet.java) public class HelloWorldApplet extendsApplet { // the paint method public void paint (Graphics g) { g.drawString (“Hello World!”, 20, 20); } }

  14. Hello World Applet (cont.) • the HTML, saved as HelloWorldApplet.html <HTML> <HEAD> <TITLE>First Applet</TITLE> </HEAD><BODY><APPLETcode=HelloWorldApplet.class width=200 height=100></APPLET></BODY> </HTML>

  15. Edit program Program Development Process Compile program yes Compiler errors? Run program Exceptions? Incorrect Results? yes

  16. Algorithms • A procedure which is • unambiguous • executable • terminating • Example: IRS Form 1040 • computer programs implement algorithms • you must understand the algorithm before it can be programmed

More Related