7/31/2019 01 Introduction Object Oriented Programming
1/16
COP-3330: Object Oriented
Programming
Course Introduction
May 14, 2012
Eng. Hector M Lugo-Cordero, MS
7/31/2019 01 Introduction Object Oriented Programming
2/16
Syllabus
Link to syllabus
As of now my webpage will have all material
for the course
http://www.eecs.ucf.edu/~hlugo I will try to get a WebCT session
7/31/2019 01 Introduction Object Oriented Programming
3/16
The Programming World
Couple of programming paradigms exists
Imperative:
Structural: C, FORTRAN
Functional: Scheme, Nodejs
Object Oriented: Objective-C, C++, C#, Java
7/31/2019 01 Introduction Object Oriented Programming
4/16
What is this course about? Developing programs using the object oriented paradigm
Allows abstraction of low level details giving more powerful tools toconcentrate on the higher level tasks
Sentences are composed of Subject, Verb, Predicate or Object
Mary eats the apple Subject: Mary
Verb (action): eats Object: the apple
Object oriented programming is composed of sentences
var.addTo(temp);
Subject (an object): var
Action (method): addTo Object (another object): temp
7/31/2019 01 Introduction Object Oriented Programming
5/16
Problem Solving
1. Understand the problem
2. Dissect the problem into manageable pieces.
3. Design a solution.
4. Consider alternatives to the solution to refineit.
5. Implement the solution.
6. Test the solution and fix any problems thatexist.
7/31/2019 01 Introduction Object Oriented Programming
6/16
History of Java Java was developed in 1995 be James Gosling who works
at Sun Microsystems. Java's ability to execute programs onthe WWW caused an initial buzz.
However, the language has continued to gain in popularitybecause of its object-oriented design. This design is verywell-suited for very large programming projects.
Many academics even feel that Java is an excellent firstprogramming language to learn. Java teaches the conceptof objects very well. Other languages, such as C++, do notreinforce the concept quite as well. Although C++ is good
for learning memory management. Recently Sun was bought by Oracle.
7/31/2019 01 Introduction Object Oriented Programming
7/16
A Java Program1. // Knights.java
2. // Arup Guha
3. // 1/9/074. // A very simple Java program that prints to the screen.
5. public class Knights {
6. /*
7. This is the main function of the program
8. */
9. public static void main(String[] args) {
10. System.out.println("GO KNIGHTS!!!!!!!");11. }
12. }
7/31/2019 01 Introduction Object Oriented Programming
8/16
Understanding the code (comments)
Single line comments are written as shown on
lines 1 4, that is //with some text It is good practice to keep your code clean and
commented such that you may go back to
understand it after some time Lines 1 4 contain the author and some info
about the code, e.g. logs, known bugs, etc.
Multi line comments follow the C conventionof /* anything between this is a comment */,as shown on lines 6 8
7/31/2019 01 Introduction Object Oriented Programming
9/16
Class Definition
Line 5 presents the definition of a class
All java code resides within classes, and each
class must have a name.
In main class the name should be the same filename
We shall go more into classes as the course moves
on
7/31/2019 01 Introduction Object Oriented Programming
10/16
The Main Function
Line 9 presents the main function of a Java
program
It is not necessary to have a main function in
order to have a complete Java Class
For now all classes shall have one
As in C, this is the first function that is called
7/31/2019 01 Introduction Object Oriented Programming
11/16
Understanding Main
There are several keywords on the definition
of main 1) public: access from everywhere
2) static: the method is the same for all instances
of the class 3) void: return type, in this case none
4) String[] args: parameters to main. Equivalent
to Cs int argc, char** argv We shall go more into detail on this
7/31/2019 01 Introduction Object Oriented Programming
12/16
System.out.println
On line 10 we our first line to write something to
the stdout or console in this case
System.out.println works as printf in C, however
it is much simpler to use since it does not require
format specifiers (i.e. %c, %s, %d, %f, etc.)
System.out.printf does exits as well and it is used
just liked in C
Other standard streams include System.in and
System.err
7/31/2019 01 Introduction Object Oriented Programming
13/16
Primitive Data TypesData Type Wrapper Class
byte Byte
short Short
int Integer
long Long
float Float
double Double
boolean Boolean
char Character
void Void
7/31/2019 01 Introduction Object Oriented Programming
14/16
Variable Names
Are case sensitive
Can contain letters, underscores, and numbers
Should not start with numbers
Should be descriptive of the task, they canhave any number of characters
7/31/2019 01 Introduction Object Oriented Programming
15/16
Compilers and Interpreters
Compilers translate code into machine code to
generate a binary file (e.g. .exe)
Interpreters run the code as it reads it
Java is an interpreted language, the JavaVirtual Machine (JVM) runs a .class code
7/31/2019 01 Introduction Object Oriented Programming
16/16
Creating .class files
The command javac may be used as gcc with C to
compile or create .class files which can be runby the JVM
Consider the code Knights.java, to compile it
javac Knights.java The above creates a .class file which may be run
using
java Knights Notice no .class is used (why?)