cis 280 intro
TRANSCRIPT
Instructor: Dr. R. Zavodnik
T.A.: Aren Zomorodian
CIS 280: Advanced OOP Design and Development
Lab Session #1:
Introduction and Concepts
I• Introduction to OOP Concepts
II• Writing Code Outside IDE’s
III• Java Enumerations
IV• Java Packages
V• Exceptions
VI• Compiling Packages and Creating JARs
VII• Software Project Management / Scrum
VIII
• Project Grouping Structure
Outline
Introduction ( S l i d e 1 / 2 )
• Object An object is a software bundle of related state (fields/variables)
and behavior (methods)
• Class A class is a blueprint or prototype from which objects are created.
• Inheritance Inheritance provides a powerful and natural mechanism for
organizing and structuring your software. It makes possible to inherit commonly used state and behavior from other classes.
Modularity Information Hiding
Code Re-Use Pluggability and Debugging Ease
Introduction ( S l i d e 2 / 2 )
• Interface An interface is a contract between a class and the outside world.
When a class implements an interface, it promises to provide the behavior published by that interface.
• Package A package is a namespace for organizing classes and interfaces in a
logical manner. Placing your code into packages makes large software projects easier to manage. Typically it is similar to folders on the HDD.
Writing Code Outside IDE• IDE’s makes the compilation of code faster and easier but:
They hide the background details of compilation process.
Does not require complete understanding of a class structure.
Sometimes we spend so much time on debugging our code while the real reason of inappropriate behavior of our code is actually a bug in IDE itself.
• Instead: Design the concept on a piece of paper or whiteboard
Write code in simple text editors (notepad, notepad ++, etc.).
Compile using command prompt (using batch files makes the repetitive writing of complex long commands easier).
Debug by throwing exceptions and printing the stack trace.
Enumerations• Enumeration is used primarily to handle a collection of
logically grouped constants: Days of a week, months of a year, compass directions, planets in
solar system, choices on a menu, etc.
What will happen if we write:int today = Day.Sunday; Int anotherDay = Sunday + Day.FRIDAY;
public class Day{
public static final int SUNDAY = 1
public static final int MONDAY = 2
public static final int TUESDAY = 3
public static final int WEDNESDAY = 4
public static final int THURSDAY = 5
public static final int FRIDAY = 6
public static final int SATURDAY}
= 7
Compiler cannot check run-time errors
Enumerations• Java’s solution for enumerations type safety is the enum
data type.
• In general a simple solution for type safety can be the use of an interface which will define what operations should be permitted for the class object instance.
All classes that implement Java’s standard enumeration interface should define the following methods:
hasMoreElements() nextElement()
Packages ( S l i d e 1 / 2 )
• A Java package is simply like defining a namespace for a part of code.
• By default classes in java are not included in any package.
• The compiler of Java will understand the packages if we write the following line at the beginning of the class:
package [package-name];
• Class with identical package-names will be included in the same package (namespace).
Packages ( S l i d e 2 / 2 )
• Advantages of using packages include:
Avoiding conflicts in integration of independently developed codes.
Provide greater control over source code by grouping related classes together. (related in functionality)
Provides easy access control over certain code sections.
Exceptions• Exceptions are the way in Java to indicate to a calling
method that an abnormal, unexpected event or extraordinary condition has occurred at runtime.
• Those extraordinary conditions can either be handled or ignored.
Any exceptions not specifically handled within a Java program are caught by the Java run time environment
int sillyDivision = 100/0; Output: java.lang.ArithmeticException: / by zero
• It is also possible to state customized exception handling classes and define any desired behavior for handling any specific exception.
Exceptions – Checked & Unchecked• Unchecked Exceptions:
Unchecked runtime exceptions represent conditions that, generally speaking, reflect errors in your program's logic and cannot be reasonably recovered from at run time –(IllegalArgumentException, NullPointerException)
Are subclasses of “RuntimeException”
• Checked Exceptions:
Represent invalid conditions in areas outside the immediate control of the program - (invalid user input, database problems, network outages, absent files)
Are subclasses of “Exception”
o Note: RuntimeException is itself a subclass of Exception
Exceptions – Throwing and Catching• The throw-catch block:
try { <code>
} catch (<exception type1> <parameter1>) { <statements> } } finally { <statements> }
Try block: Part of the code which has potential risk of generating an exception
should be placed in this block.
Catch block: Exceptions thrown in try block can be caught and handled by catch
block.
Finally: The finally block is executed regardless of the results in try-catch block Generally used for freeing resources, cleaning up, closing connections
etc.
Advantages of Exceptions• Separating Error-Handling Code from "Regular" Code
• Propagating Errors Up the Call Stack
• Grouping and Differentiating Error Types
method1 { try { call method2; } catch (exception e) { doErrorProcessing; }}
method2 throws exception { call method3;}
Compiling Java Packages in CMD• Checklist:
The Java SE Development Kit 6 (JDK 6)
A text editor
Set the path variable for JDK Right click on “Computer” (Win 7) Click on “Advanced System Settings” On the new window opened click on “Environment
Variables” In the “User Variables” section, the upper part of the
window, click on “New…” Set the name to: path Find where you have installed JDK and add the path in the
“variable value” box (following is the path of JDK on my PC)
(C:\Program Files\Java\jdk1.6.0_21\bin\)
Compiling Java Packages in CMD• Compile the packages:
"C:\Program Files\Java\jdk1.6.0_17\bin\javac" <Package Name>\*.java -d .\
• If external (outside the current working directory) classes and libraries are used, we will need to explicitly define the CLASSPATH to list all the directories which contain used classes and libraries
set CLASSPATH=C:\lib\jars\classifier.jar ;C:\UserProfiling\jars\profiles.jar
• Creating JAR file (after all source files are compiled):
First a manifest file should be created which will contain a line defining the main class:
Main-Class: MyClass
Then for creating the JAR file use the following command line:
jar cvfm MyJarName.jar manifest.txt *.class
Some Useful Javac Options• -d (directory)
Set the destination directory for class files. The destination directory must already exist.
If a class is part of a package, javac puts the class file in a subdirectory reflecting the package name, creating directories as needed.
• -classpath Set the user class path, overriding the user class path in the
CLASSPATH environment variable. If neither CLASSPATH or -classpath is specified, the user class path
consists of the current directoryjava -classpath C:\java\MyClasses utility.myapp.Cool
Click Here For Description of More Options
SPM – Agile Methodology / Scrum• Agile methodology is based on iterative and incremental
software development.
• Scrum is the process framework: An effective tool for monitoring and managing the
development process flow
Promotes dynamic and fast decision making process
Makes it easy to identify project’s flow, and current state, enhances the focus on upcoming milestones
A scrum master should be chosen to undertake the process (the project manager)
Scrum – Daily Meetings• Daily Scrum
Should start on time
Should not take more than 15 minutes
During the daily meetings following questions should be addressed:― What have you done since yesterday?― What is the plan for today?― Is there any problems that would prevent you by any
means to accomplish your goal?
Scrum – Sprint Planning Meetings• Sprint Planning Meeting
Should take place each week (once per 7-days)
Should take 30 minutes to 1 hour (not more than 1 hour)
Plan for next week’s work
Prepare the Spring Backlog with entire team
Try to identify how much of the planned work is most likely to be completed during the current sprint
Advance to Sprint Review Meeting
Scrum – Sprint Review Meetings• Sprint Review Meeting
The past sprint should be discussed
All the work that is completed and not completed should be discussed
Should take 30 minutes to 1 hour (not more than 1 hour)
Following questions should be answered:― What went wrong and what went well during the last
sprint?― What prevented the team to accomplish all the
milestones set for the last sprint? What can be done to prevent such difficulties?
― What can be improved for next sprint?
Identifying Project Groups• Each group can have 3 members maximum
• Groups of single individuals are also possible
• Scrum master should be selected
• Scrum master should hand in the reports during each Friday
• Any disagreements and problems that prevents the team to functions properly and any conflictions should be reported to the course instructor ASAP
AUA – College of EngineeringApr.16, Spring 2011
CIS-280: Advance OOPIntro
END---
CIS 280 – Advanced Object Oriented Software Design and Development
Lab Session #1