160 likes | 290 Views
COP-3330: Object Oriented Programming. Course Introduction May 14, 2012 Eng. Hector M Lugo-Cordero, MS. 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. The Programming World.
E N D
COP-3330: Object Oriented Programming Course Introduction May 14, 2012 Eng. Hector M Lugo-Cordero, MS
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
The Programming World • Couple of programming paradigms exists • Imperative: • Structural: C, FORTRAN • Functional: Scheme, Nodejs • Object Oriented: Objective-C, C++, C#, Java
What is this course about? • Developing programs using the object oriented paradigm • Allows abstraction of low level details giving more powerful tools to concentrate 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
Problem Solving • Understand the problem • Dissect the problem into manageable pieces. • Design a solution. • Consider alternatives to the solution to refine it. • Implement the solution. • Test the 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.java 2. // Arup Guha 3. // 1/9/07 4. // 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. }
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 convention of /* anything between this is a comment */, as shown on lines 6 – 8
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
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
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 C’s intargc, char** argv • We shall go more into detail on this
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
Variable Names • Are case sensitive • Can contain letters, underscores, and numbers • Should not start with numbers • Should 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 it • Java is an interpreted language, the Java Virtual Machine (JVM) runs a .class code
Creating .class files • The command javac may be used as gcc with C to “compile” or create .class files which can be run by 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?)