1 / 38

Advanced Programming in Java

Advanced Programming in Java. Peyman Dodangeh Sharif University of Technology Fall 2013 Lecture 1: Introduction to OOP. Slides adapted from Steven Roehrig. Expected Background. “A one-semester college course in programming.”

mfarrow
Download Presentation

Advanced Programming in Java

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. Advanced Programming in Java Peyman Dodangeh Sharif University of Technology Fall 2013 Lecture 1: Introduction to OOP Slides adapted from Steven Roehrig

  2. Expected Background • “A one-semester college course in programming.” • I assume you can write a program in some language, understand variables, control structures, functions/subroutines. • If in doubt, let’s talk.

  3. Course Outline • Week 1: Background, basics of O-O, first Java program, programming environments • Week 2: Raw materials: types, variables, operators, program control • Week 3: Classes: declarations, constructors, cleanup & garbage collection • Week 4: Packages, access specifiers, finals, class loading

  4. Course Outline (cont.) • Week 5: Polymorphism, abstract classes, design patterns • Week 6: Interfaces & extends, inner classes, callbacks via inner classes • Week 7: Applets, Applications, Swing • Week 8: Graphics and Multimedia • Week 9: Arrays, container classes, iterators

  5. Course Outline (cont.) • Week 10: Exception handling, threads • Week 11: Java I/O, networking • Week 12: JDBC and object persistency

  6. Administrative Details (cont.) • Midterm and final exams • Homework + Quiz + Projects: 50% • Midterm exam: 20% • Final exam: 30% • I will give one A+.

  7. Administrative Details (cont.) • Everything is attached to the syllabus. Don’t look for assignments, etc. on Blackboard. Look at the syllabus! • Homework usually weekly. • Submission instructions with each assignment, usually printed listings and a zip file. • Printing slides? Three to a page, at least. Save a tree! Remove the PowerPoint background before printing. Save toner!

  8. Administrative Details (cont.) • Attendance is not required, but… • …you are responsible for everything said in class. • I encourage you to ask questions in class. Don’t guess, ask a question!

  9. My Policy on Cheating • Cheating means “submitting, without proper attribution, any computer code that is directly traceable to the computer code written by another person.” • I give students a failing course grade for any cheating. • This doesn’t help your job prospects.

  10. My Policy on Cheating • You may discuss homework problems with classmates, after you have made a serious effort in trying the homework on your own. • You can use ideas from the literature (with proper citation). • You can use anything from the textbook/notes. • The code you submit must be written completely by you.

  11. Course Etiquette • Etiquette is “conduct in polite society” • No cell phones • No random comings and goings • If you are sleepy, go home • If you want to read email or surf the Web, please do it elsewhere

  12. Object Oriented Programming • Problem Space • the place where the problem exists • such as a business • Solution Space • the place where you’re implementing that solution • such as a computer • The effort required to perform this mapping. • E.g. think about a library, or a phonebook program

  13. Object Oriented Approach • OOP lets the programmer represent problem space elements • The elements in the problem space and their representations in the solution space are referred to as “objects”

  14. OOP • The program is allowed to adapt itself to the lingo of the problem • by adding new types of objects • when you read the code, you’re reading words that also express the problem.

  15. OOP (2) • OOP allows you to describe the problem in terms of the problem • Rather than in terms of the computer • Objects in your code are similar to real objects • Recall the sample programs: phonebook and library

  16. O-O Languages (Alan Kay) • Everything is an object. • A program is a bunch of objects telling each other what to do, by sending messages. • Each object has its own memory, and is made up of other objects. • Every object has a type (class). • All objects of the same type can receive the same messages.

  17. Objects • An object has an interface, determined by its class. • A class is an abstract data type, or user-defined type. • Designing a class means defining its interface.

  18. Built-In Types • Think of an int… • What is its interface? • How do you “send it messages”? • How do you make one? • Where does it go when you’re done with it? • In solving a computational problem, the goal is to • Dream up useful classes, and • Endow them with appropriate characteristics.

  19. Example • Suppose I’ve defined this class in Java: • To make one, I type Light lt = new Light(); • If I want switch on My Lamp, I say lt.on();

  20. But Why Not Just… Light lt; • This is legal, but just makes a “reference variable” named lt • This variable can refer to anyLight object, but currently refers to nothing • The operator new actually causes an object to be created, so we tell it what kind we want

  21. Designers Design, Users Use • The interface is the critical part, but the details (implementation) are important too. • Users use the interface (the “public part”); the implementation is hidden by “access control”.

  22. Object Oriented Languages • Smalltalk • The first successful object-oriented language • One of the languages upon which Java is based • Java • C++ • C##

  23. Why So Many Languages? • Bring the language “closer” to the problem. • But 4GLs are typically focused on specialized domains (e.g., relational databases). • We want a language that is general purpose, yet can easily be “tailored” to any domain.

  24. Java History • Java was created in 1991 • by James Gosling in Sun Microsystems • Initially called Oak • in honor of the tree outside Gosling's window • Its name was changed to Java • because there was already a language called Oak. • Sun Microsystems released the first public implementation as Java 1.0 in 1995 • Java syntax is similar to C and C++.

  25. Java Motivation • The need for platform independent language • To be embedded in various consumer electronic products • like toasters and refrigerators • Platform independent?! • Hardware • Operating System

  26. Java Motivation (2) • At the same time, the World Wide Web and the Internet were gaining popularity. • Java could be used for internet programming. • Why? • Platform independence • Creation of Applets

  27. The Java technology is: • A programming language • Java can create all kinds of applications • A development environment • A compiler (javac) • An interpreter (java) • A documentation generator (javadoc) • … • Compare it to C++

  28. High-Level Languages

  29. Java Virtual Machine

  30. Compile and Execution Stages • Compare to C++ and Assembly • .NET Framework Sharif University of Technology

  31. Java is Popular • Some reports on programming languages popularity • According to • Job advertisements • Book sales • Finding code on the web • …

  32. Characteristics of Java • Java is simple • Java is object-oriented • Java is architecture-neutral • Java is portable • Java is interpreted • Java is multithreaded • Java is secure • Java is robust

  33. First Example • Create a file named First.java • Java class files have .java extension • Note to naming convention • Copy this lines to the file • Note: File name and class name should be the same.

  34. The Major Issues • Editing • Use any text editor you like (not a word processor!); save as HelloDate.java • Compiling • From a DOS or UNIX command line, type > javac HelloDate.java • This should produce the file HelloDate.class • Running • Again from the command prompt, type > java HelloDate

  35. Assignment # 0 • Download and install JDK • http://www.oracle.com/technetwork/java/javase/downloads/index.html • JDK 7 • Write a program that prints your name on the console • Compile and run the program

  36. Further Reading • Read Java page on Wikipedia http://en.wikipedia.org/wiki/Java_(programming_language) • Google this terms and phrases: • Java • Java Mobile • JVM • Byte code • Java Sun • Java and C++ • Java and C#

  37. The End.

More Related