DOC PREVIEW
TRINITY CSCI 1321 - Lecture Notes

This preview shows page 1-2-3-4-5-6-41-42-43-44-45-46-84-85-86-87-88-89 out of 89 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 89 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

From C to JavaSome basic information to help you make the switchbyDr. Mark C. Lewis1. PrefaceOne of the standard problems that we have run into since changing our curriculum so we teach C in the first semester and Java in the second is in the choice of textbooks. If we pick a CS1 text for the course it does a good job of introducing Java, but is too basic in general and doesn't cover the data structures or other advanced concepts that we want to get into. This is because it assumes you know nothing about programming, but in reality you already know how to structure the logic of a program. Instead we can pick a CS2 text and it covers all of the concepts that we will want to discuss, but such texts have virtually no information on the basics of Java programming. They all assume that you have already been programming in the language for a semester.This pamphlet is intended to give you the basic information on Java that you need to get up to speed while growing off the knowledge you already have of C. You should read this during the first few weeks of the semester to help you understand the material when it is presented and the code that we will write. You should also keep it around to use as a reference through the rest of the semester.2. Introduction to Object-OrientationThis course focuses on object-oriented programming and design. We just happen to teach in it Java because of the numerous benefits of that language. Up front though you should understand what object-orientation is and how we use it to produce better programs.Object-oriented programming languages have their roots in SIMULA67, a programming language that was developed to do simulations of physical systems. Theidea in SIMULA was that physical objects are more than just data, they also “encapsulate” what you can do with them. This idea of grouping data together with the functions that are allowed to work on that data is what is known as encapsulation and it is the primary aspect that joins all object oriented languages. Any entity in a program that has this binding of data and functions is typically called an object and these objects are the fundamental building blocks of object-oriented programs.Perhaps the most pure object-oriented language is Smalltalk. Smalltalk takes the idea that you should work with objects to the absolute extreme. In Smalltalk, everything is an object, including simple numbers or boolean values. In Smalltalk, when you call a function that is associated with an object, you are said to be sending a message to the object and everything that you do in Smalltalk is done through the sending of messages, including operations as simple as adding two numbers.Java is not as purely object-oriented as Smalltalk for a number of reasons and when people talk about Java and C++ they typically use terms that are a bit different from that used with Smalltalk. The main way in which Java is not purely object-oriented is that primitives in Java are not objects. That is to say that Java has types for numbers, characters, and booleans that are not objects, they have no functions directly associated with them. The primitive types in Java are used much like the primitive types that you worked with in C, though there are a few differences that will be discussed in the next section. The reason for doing this was speed. Primitives are simple and typically their operations are build straight into the hardware of the machine and it is much more efficient to not add the extra overhead of making those types objects. The functions that are grouped with objects in Java are typically called methods and instead of saying that we pass a message to an object, we use the terminology of calling a method. The data elements that are stored in an object in Java are typically referred to as members or member data.Java, as well as SIMULA, Smalltalk, C++, and most other object-oriented languages that you are likely to interact with, is a class based object oriented language. This means that objects are constructed from classes. One way of thinking about this is that object-oriented programs are like factories that construct various objects and have them interact as needed before throwing them away. In a class based object-orientedlanguage, the structure of an object is specified by its class. In the factory analogy, the class is like a blueprint, it tells the factory what parts go inside the object and how they work. The class itself does not do anything normally, it is just a layout for the objects that will do things. When we code in Java, we actually write classes. We lay out the blue prints for objects and describe how those objects interact. Some of that description can include statements that produce new objects for us to use. One we have the objects we can call methods on them and pass them as arguments to other methods.The grouping of functions and data together into objects doesn't sound all that significant and hardly worth a whole class on the topic. However, it is actually sufficient to teach multiple classes on because of some of the extra abilities that come naturally when data and functions are grouped together. In fact, these other abilities are so commonly used that their use is largely folded into the term encapsulation. Encapsulation takes on new abilities and greatly enhances what we can do in programming when we provide different levels of visibility to the members of a class and the objects created from that class and when we provide a mechanism for subtyping of classes. We will talk about these topics in great depth this semester and in reasonable depth later in this document. For now I would like to present to you a high level description of what these things mean and what they mean to our programming.The idea of allowing the programmer to set visibility on the members and methods of a class is quite simple. At the simplest level, you get to tell what things can be seen and used outside of the class and what things can't be seen or used outside of the class. A more detailed description will be given later that is specific to Java. The advantage of doing this is that code outside of a class can only depend on the things that they can see. This is referred to as information and implementation hiding and it leads to another valuable ability called separation of interface and implementation. We will see many times over the course of the semester how important these things are.


View Full Document

TRINITY CSCI 1321 - Lecture Notes

Documents in this Course
Recursion

Recursion

11 pages

Iterators

Iterators

10 pages

Actors

Actors

9 pages

Recursion

Recursion

15 pages

Recursion

Recursion

10 pages

Threads

Threads

7 pages

Trees

Trees

11 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?