Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "The Joy of Programming (also known as) Introduction to Object-Oriented Programming."— 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.h tml (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? memoryprocessordisk I/O devices data 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 programs may also be downloaded from the web and run in a browser; these are called applets applets are an outgrowth of Java’s platform independence, 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 compile the file in an MS-DOS Prompt window: javac MyProgram.java run the class in an MS-DOS Prompt window: java MyProgram

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: javac MyApplet.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 public class HelloWorld { // the main method public static void 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 extends Applet { // 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 First Applet <APPLET code=HelloWorldApplet.class width=200 height=100>

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

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


Download ppt "The Joy of Programming (also known as) Introduction to Object-Oriented Programming."

Similar presentations


Ads by Google