Publications: 120 | Followers: 1

COP-3330_ Object Oriented Programming

Publish on Category: Birds 0

COP-3330: Object Oriented Programming
Course IntroductionMay 14, 2012Eng. Hector M Lugo-Cordero, MS
Link to syllabusAs of now my webpage will have all material for the course will try to get a WebCT session
The Programming World
Couple of programming paradigms existsImperative:Structural: C, FORTRANFunctional: Scheme,NodejsObject Oriented: Objective-C, C++, C#, Java
What is this course about?
Developing programs using the object oriented paradigmAllows abstraction of low level details giving more powerful tools to concentrate on the higher level tasksSentences are composed of Subject, Verb, Predicate orObjectMary eats the appleSubject: MaryVerb (action): eatsObject: the appleObject oriented programming is composed of “sentences”var.addTo(temp);Subject (an object):varAction(method):addToObject (another object): temp
Problem Solving
Understand the problemDissectthe problem into manageable pieces.Designa solution.Consideralternatives to the solution to refine it.Implementthe solution.Testthe solution and fix any problems that exist.
History of Java
Java was developed in 1995 be James Gosling who works at Sun Microsystems. Java's ability to execute programs on the WWW caused an initial buzz.However, the language has continued to gain in popularity because of its object-oriented design. This design is very well-suited for very large programming projects.Many academics even feel that Java is an excellent first programming language to learn. Java teaches the concept of objects very well. Other languages, such as C++, do not reinforce the concept quite as well. Although C++ is good for learning memory management.Recently Sun was bought by Oracle.
A Java Program
1. //Knights.java2. //ArupGuha3. //1/9/074. //A very simple Java program that prints to the screen.5. publicclass Knights {6./*7.This is the main function of the program8.*/9.public static void main(String[]args) {10.System.out.println("GO KNIGHTS!!!!!!!");11.}12. }
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 timeLines 1 – 4 contain the author and some info about the code, e.g. logs, known bugs, etc.Multi line comments follow the C convention of /* anything between this is a comment */, as shown on lines 6 – 8
Class Definition
Line 5 presents the definition of a classAll java code resides within classes, and each class must have a name.In main class the name should be the same filenameWe shall go more into classes as the course moves on
The Main Function
Line 9 presents the main function of a Java programIt is not necessary to have a main function in order to have a complete Java ClassFor now all classes shall have oneAs in C, this is the first function that is called
Understanding Main
There are several keywords on the definition of main1)public: access from everywhere2)static: the method is the same for all instances of the class3)void: return type, in this case none4) String[]args: parameters to main. Equivalent to C’sintargc, char**argvWe shall go more into detail on this
On line 10 we our first line to write something to thestdoutor console in this caseSystem.out.printlnworks asprintfin C, however it is much simpler to use since it does not require formatspecifiers(i.e. %c, %s, %d, %f, etc.)System.out.printfdoes exits as well and it is used just liked in COther standard streams include andSystem.err
Primitive Data Types
Variable Names
Are case sensitiveCan contain letters, underscores, and numbersShould not start with numbersShould be descriptive of the task, they can have any number of characters
Compilers and Interpreters
Compilers translate code into machine code to generate a binary file (e.g. .exe)Interpreters run the code as it reads itJava is an interpreted language, the Java Virtual Machine (JVM) runs a .class code
Creating .class files
The commandjavacmay be used asgccwith C to “compile” or create .class files which can be run by the JVMConsider the code, to compile itjavacKnights.javaThe above creates a .class file which may be run usingjava KnightsNotice no .class is used (why?)





Make amazing presentation for free
COP-3330_ Object Oriented Programming