Loading...

CS407: Network Applications Development

Unit 2: Object-Oriented Programming in Java   In this unit, you will review the basics of Object-Oriented Programming in Java, discussing the fundamentals of classes and objects, function creations and calls, and encapsulation and data hiding.  If you have not yet created multi-threaded Java applications, the second part of this unit will introduce Java threads.

Unit 2 Time Advisory
This unit should take you approximately 14 hours to complete.

☐    Subunit 2.1: 2 hours

☐    Subunit 2.2: 2 hours

☐    Subunit 2.3: 2 hours

☐    Subunit 2.4: 2 hours

☐    Subunit 2.5: 2 hours

☐    Subunit 2.6: 2 hours

☐    Subunit 2.7: 2 hours

Unit2 Learning Outcomes
Upon successful completion of this unit, the student will be able to:
- Code problems using the fundamental concepts of object-oriented programming in Java. - Explain the usage of threads in Java. - Compare and contrast objects and classes. - Compare and contrast encapsulation and relationships. - Compare and contrast multitasking and multi-threading. - Complete programming tasks utilizing object-oriented features.

2.1 Object-Oriented Programming in Java   - Reading: Hobart and William Smith Colleges: David J. Eck's Introduction to Programming Using Java: “Section 5.1: Objects, Instance Methods, and Instance Variables” Link: Hobart and William Smith Colleges: David J. Eck's Introduction to Programming Using Java: “Section 5.1: Objects, Instance Methods, and Instance Variables” (PDF)
 
Instructions: Please read all of Section 5.1.  This is an introduction to object-oriented thinking for programming in Java.  Compile and run the code provided.  Compare and contrast a “getter” method with a “setter” method.   
 
Terms of Use: The article above is released under a Creative Commons Attribution-Non-Commercial-Share-Alike License 3.0.  It is attributed to David Eck and the original version can be found here.

2.2 Classes and Objects   - Reading: Oracle's “Object-Oriented Programming Concepts” Link: Oracle's “Object-Oriented Programming Concepts” (HTML)

 Instructions: Please read this page very carefully for an overview
of the six concepts to object-oriented programming.  These concepts
apply to the topics outlined in sub-subunits 2.2.1 through 2.2.6. 
For these sub-subunits, you will be reviewing each concept in more
detail.  
    
 Terms of Use: Please respect the copyright and terms of use
displayed on the webpage above.

2.2.1 What Is an Object?   - Reading: Oracle's “What Is an Object” Link: Oracle's “What Is an Object?” (HTML)

 Instructions: Please read this entire webpage.  Compile and run the
sample code.  What is the advantage of bundling code to create
objects?  
    
 Terms of Use: Please respect the copyright and terms of use
displayed on the webpage above.

2.2.2 What Is a Class?   - Reading: Oracle's “What Is a Class?” Link: Oracle's “What Is a Class?” (HTML)

 Instructions: Please read this entire webpage.  Compile and run the
sample code.  Does Java allow you to run code that does not include
a *“main”*  method?  
    
 Terms of Use: Please respect the copyright and terms of use
displayed on the webpage above.

2.2.3 What Is Inheritance?   - Reading: Oracle's “What Is Inheritance?” Link: Oracle's “What Is Inheritance?” (HTML)

 Instructions: Please read this entire webpage.  Compile and run the
sample code.  What is a “superclass,” and what is its role in coding
in Java?  
    
 Terms of Use: Please respect the copyright and terms of use
displayed on the webpage above.

2.2.4 What Is an Interface?   - Reading: Oracle's “What Is an Interface?” Link: Oracle's “What Is an Interface?” (HTML)

 Instructions: Please read this entire webpage.  Compile and run the
sample code.  What is an interface, and what is its role in coding
in Java?   
    
 Terms of Use: Please respect the copyright and terms of use
displayed on the webpage above.

2.2.5 What Is a Package?   - Reading: Oracle's “What Is a Package?” Link: Oracle's “What Is a Package?” (HTML)

 Instructions: Please read this entire webpage, and consider the
following questions.  What is a Java API?  What can you do with an
API in Java?  What is the importance of the Java platform API
specification?   
    
 Terms of Use: Please respect the copyright and terms of use
displayed on the webpage above.

2.2.6 Checkpoint   - Assessment: Oracle's “Questions and Exercises: Object-Oriented Programming Concepts” Link: Oracle's “Questions and Exercises: Object-Oriented Programming Concepts” (HTML)

 Instructions: Please complete the questions and exercises on this
page.  Then, click the link provided on the page to check your
work.  
    
 Terms of Use: Please respect the copyright and terms of use
displayed on the webpage above.

2.3 Creating Classes   - Reading: Oracle's “Classes and Objects” Link: Oracle's “Classes and Objects” (HTML)

 Instructions: Please read this tutorial very carefully.  This
tutorial walks you through creating classes and using them to create
and use objects to program in Java.  There are multiple links to
material covering six topics with sample code to compile and run. 
In addition, five self-check links to questions and exercises are
provided throughout the material.  The outline in the left-hand
frame at each link will help you check that you do not skip any
relevant information.  Once you have completed a link, click the
“next” button at the bottom of that screen to access the next
topic.  The six topics are: classes, objects, more on classes,
nested classes, enum types, and annotations.  The material increases
in difficulty as you progress through the topics.  Note that the
last three topics are revisited in more detail as you proceed
through this course, so do not burn yourself out trying to master
them this early in your study of Java programming.  
    
 Terms of Use: Please respect the copyright and terms of use
displayed on the webpage above.

2.4 Object Messages and Messages Categories   - Reading: Hobart and William Smith Colleges: David J. Eck's Introduction to Programming Using Java: “Section 5.2: Constructors and Object Initialization” Link: Hobart and William Smith Colleges: David J. Eck's Introduction to Programming Using Java: “Section 5.2: Constructors and Object Initialization” (PDF)
 
Instructions: Please read all of Section 5.2, which covers three unique aspects of programming with Java.  Note that this reading material has been divided into the three parts covered below as subunits 2.4.1 Initializing Instance Variables, 2.4.2 Constructors, and 2.4.3 Garbage Collection. 
 
Terms of Use: The article above is released under a Creative Commons Attribution-Non-Commercial-Share-Alike License 3.0.  It is attributed to David Eck and the original version can be found here.

2.4.1 Initializing Instance Variables   Note: This subunit is the first segment of the reading assigned beneath subunit 2.4.  Please focus on the paragraphs below the first heading until you reach the Constructors heading.  What is an instance?  What is its purpose?

2.4.2 Constructors   Note: This subunit is covered by the second segment of the reading below subunit 2.4.  Please focus on the paragraphs below the Constructor heading until you reach the Garbage Collection heading.  What is a constructor?  Describe how a constructor is used.

2.4.3 Garbage Collection   Note: This subunit is covered by the reading below subunit 2.4.  Please focus on the paragraphs below the Garbage Collection heading.  What is garbage?  Why do the current versions of Java manage garbage?

2.5 Encapsulation and Visibility   - Reading: Hobart and William Smith Colleges: David J. Eck's Introduction to Programming Using Java: “Section 5.3: Programming with Objects” Link: Hobart and William Smith Colleges: David J. Eck's Introduction to Programming Using Java: “Section 5.3: Programming with Objects” (PDF)
 
Instructions: Please read  all of Section 5.3 through the end of Section 5.7.  Note how modifiers are used to control access to the class members.
 
Terms of Use: The article above is released under a Creative Commons Attribution-Non-Commercial-Share-Alike License 3.0.  It is attributed to David Eck and the original version can be found here.

2.5.1 Encapsulation Checkpoint   - Assessment: Hobart and William Smith Colleges: David J. Eck's Introduction to Programming Using Java: “Programming Exercises for Chapter 5” Link: Hobart and William Smith Colleges: David J. Eck's Introduction to Programming Using Java: “Programming Exercises for Chapter 5” (PDF)
 
Instructions: Please complete the exercises for subsections 5.1 through 5.7.  Each exercise identifies the subsection it is based on.  Review that subsection if you need more information before completing that exercise.  When you have finished, solutions are found at the link to the right of the question.
 
Terms of Use: The article above is released under a Creative Commons Attribution-Non-Commercial-Share-Alike License 3.0.  It is attributed to David Eck and the original version can be found here.

2.6 Interfaces   - Reading: Oracle's “Interfaces” Link: Oracle's “Interfaces” (HTML)
 
Instructions: Please complete the entire Interfaces tutorial.  Compile and run the samples provided on each page.  This first page is a review of interfaces introduced in a prior subunit.  Click next at the bottom of the page to see how to create an interface.  Compile and run the sample code provided to create an interface before moving to the next page.  There you will see how to implement the interface you created.  The next page shows you how to use an interface to create a new reference data type.  What are the restrictions in using an interface as a type?
 
The last page shows you how to create a new interface to modify an existing interface.  Once you compile and run the samples on this page, the next link will take you to a summary of the interface tutorial.  Then click the next button to access  the self-check exercises and problems.  Complete all of the items before using the link provided to check your work. 
 
Terms of Use: Please respect the copyright and terms of use displayed on the webpage above.

2.6.1 Checkpoint   - Assessment: Oracle's “Questions and Exercises: Interfaces” Link: Oracle's “Questions and Exercises: Interfaces” (HTML)

 Instructions: Please complete the questions and exercises on this
page.  Then, click the link provided on the page to check your
work.  
    
 Terms of Use: Please respect the copyright and terms of use
displayed on the webpage above.

2.7 Abstract Classes   - Reading: Oracle's “Inheritance” Link: Oracle's “Inheritance” (HTML)
 
Instructions: Please complete all nine of the Inheritance subtopics included in this resource.  You will look at overriding and hiding methods, polymorphism, hiding fields, using the keyword super, object case as superclass, writing final classes and methods, abstract methods and classes, summary of inheritance, and questions and exercises.  The menu on the left-hand window can be used to check that you complete all of the material in this tutorial. 
 
As you work through each subtopic, you will need to compile and run the examples provided.  Then, review the summary before attempting the self-check.  Once you have completed all of the questions and exercises, use the link provided on the page to check your work.  Note that an interface is not an abstraction.  Why not?
 
Terms of Use: Please respect the copyright and terms of use displayed on the webpage above.

2.7.1 Checkpoint   - Assessment: Oracle's “Questions and Exercises: Inheritance” Link: Oracle's “Questions and Exercises: Inheritance” (HTML)

 Instructions: Please complete the questions and exercises on this
page.  Then,click the link provided on the page to check your
work.  
    
 Terms of Use: Please respect the copyright and terms of use
displayed on the webpage above.