Download presentation
Presentation is loading. Please wait.
Published byDana Maloney Modified over 10 years ago
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
13
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
14
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”
15
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
16
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
17
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.
18
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.
19
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.
20
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();
21
But Why Not Just… This is legal, but just makes a “reference variable” named lt This variable can refer to any Light object, but currently refers to nothing The operator new actually causes an object to be created, so we tell it what kind we want Light lt;
22
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”.
23
Object Oriented Languages Smalltalk The first successful object-oriented language One of the languages upon which Java is based Java C++ C##
24
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.
25
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++.
26
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
27
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
28
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++
29
High-Level Languages
30
Java Virtual Machine
31
Compile and Execution Stages Compare to C++ and Assembly .NET Framework Sharif University of Technology
32
Java is Popular Some reports on programming languages popularity According to Job advertisements Book sales Finding code on the web …
33
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
34
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.
35
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
36
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
37
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#
38
The End.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.