Professional Documents
Culture Documents
Course Pre-requisite: NHTI CP235 Algorithms with OOP Intermediate Java or C# skills. (Intermediate C++ with OOP with permission ) Instructor: M. Saleem Yusuf Phone: Home (603) 424-8147
Email:
MSaleemYusuf@Yahoo.com , mohammad.yusuf@uhh.edu
Website: http://www.corlyn.com Classes meet: On Mondays, 8/30/2010 to 12/13/2010. No class on Labor day 9/6
UNH-M / NHTI - Professor Yusuf
Text Books
Required Textbook Data Structures
Data Structures and Algorithms in Java Second Edition by Robert Lafore. ISBN: 0-672-32453-9. Publisher: Sams Suggested Reference Texts For Database, I recommend, although I will not be using it in the class Mastering SQL Server 2008 , Sybex, 2009. OR
Mastering SQL Server 2005, Gunderloy, Jorden, Tschanz. ISBN 07821-4380-6. Publisher Sybex/Wiley.
It will make a big difference if you have you a C# and a Java programming textbook from the classes you have taken before. I prefer the Deitel textbooks for teaching.
Pre-requisite
Pre-requisite
NHTI CP235 Algorithms with OOP CP235 at NHTI in Concord covers first 250 pages of the current text (Data Structures & Algorithms in Java by Robert Lafore) Intermediate Java or C# skills. (Intermediate C++ with OOP experience acceptable as there will be sample model programs for transition to Java.)
Syllabus
Read the following. It is in the syllabus document
School Policies Grading Policy Late work Absences Academic honesty Disruptive behavior Disabilities Class Cancellation
Class Schedule
Subject to change. On my website (http://www.corlyn.com).
Agenda
In this course
We will use both Java and C# programming languages in this class Review fundamental container classes; stacks, queues and link lists Learn more advanced data structures and concepts Use of sorting and searching algorithms, iterators and efficiency indicators Use the built-in data structures provided by .NET Framework Class Library and Java libraries Design, Development and use of relational databases
5
Set the CLASSPATH variable to include classes and JAR files you will be using. Example:
CLASSPATH=.;E:\Program Files\Java\jdk1.6.0_03\LIB;C:\mysqlconnector-java-5.0.8\mysql-connector-java-5.0.8-bin.jar
TextPad (Not required) Not free, but allows you to use it for a while. Excellent editor and you can compile and run your program from the TextPad. If you plan to use it for long term, I recommend that you buy it. http://www.textpad.com/ Notepad++ An awesome editor and it is free (Not required). Highlights the code, but I dont think you can compile or run Java code from it. Highly recommended.
http://sourceforge.net/projects/notepad-plus/
UNH-M / NHTI - Professor Yusuf
C# Development Environment
NHTI Students
For Software Development with C#, Download the following software. Contact Professor Sterling Hough. All NHTI Students can get a student copy of
Windows XP Professional Visual Studio 2010 SQL Server 2008 Developer Edition
All Students
For Software Development with C#, Download
Visual Studio 2010, C# Express version SQL Server 2008, Express version Find tutorial or learning videos on Microsofts site. They are great. Download MySql if you plan to use it. Works very well with Java If you plan to use MySql, download Toad for MySQL. It is excellent and free http://www.quest.com/toad-for-mysql/
10
11
12
double
boolean
13
switch (Expression) { case label_1 : statements; break; case label_n: statements; break; default: statements break; }
?: (ternary operator)
max = (n1 > n2) ? n1 : n2;
14
15
16
Methods - Examples
Example
double root = Math.sqrt (4.0) New method 'printf' in J2SE 5.0, Displays formatted data System.out.printf( "%s\n%s\n", "Welcome to", "Java Programming!" );
17
// Sphere.java - Java How To Program in, Deitel & Deitel public class Sphere { static float PI = 3.14159F; // static field int radius; // Non-static field public static void main(String[] args) { Sphere s = new Sphere(); s.radius = 6; float circum, volume; // Local vars of function main // can access static fields only circum = s.getCircum(); volume = s.getVolume(); System.out.printf("%s%d", "A sphere of radius ", s.radius); System.out.printf("%s%f", " has a circumference of ", circum); System.out.printf("%s%f%s\n", " and a volume of ", volume, "."); } // end of main float getCircum() { // can access static and non-static fields return radius * 2 * PI; } float getVolume() { float vol = (4.0F/3.0F) * PI * (float)Math.pow(radius, 3.0); return vol; } } // end of class Sphere
UNH-M / NHTI - Professor Yusuf
18
19
The scope of a class member (a method or a data member) can be specified as public, protected, private or left unspecified
Public - can be used by anyone, all have access Private - can only be accessed by the member of that class. Not even the objects created from this class have access to it. Protected - Methods of subclasses and of any class in the same package have access. A member with unspecified scope is visible to any class in the same package. It has default scope (is protected, directory)
20
21
22
23
24
-------public boolean equals(Object obj) { if (this == obj) // comparing same object, will be true return true; if ((obj != null) && (obj instanceof Employee)) { Employee e = (Employee)obj; return ( this.firstname.equals(e.firstname) && this.lastname.equals(e.lastname) && this.id == e.id ); } else { return false; }
} } Employee emp1 = new Employee("Bob", "Dobbs"); Employee emp2 = new Employee("Bob", "Dobbs"); if ( emp1.equals(emp2) ) { // will be true UNH-M / NHTI - Professor Yusuf
25
26
27
28
for (int number : arr ) sum += number; System.out.printf( "Sum is: %d\n", sum );
} // end main } // end class ArrayTest
29
30
// output each array element's value for (int i=0; i < SIZE; i++ ) System.out.printf( "%4d%6d%s", i, RandomArray[i], ((i+1)%10 == 0 ? "\n" : "") ); } // end main } // end class SimpleExample
32
33
34
class Point { private int x, y; public Point(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } // Overloaded or custom toString() Method public String toString() { return "X=" + x + ", " + "Y=" + y; } } public class TestAppPoint { public static void main(String args[]) { Point point = new Point(10, 10); String s = "Testing Point: " + point; System.out.println(s); System.out.println(point); } }
UNH-M / NHTI - Professor Yusuf
35
Links
http://www.javabeginner.com/getting-started-java.htm
http://www.textpad.com/
http://sourceforge.net/projects/notepad-plus/
36
Implements the JSP Model 2 Architecture Stores application routing information and request mapping in a single core file, struts-config.xml
The Struts Framework, itself, only fills in the View and Controller layers. The Model layer is left to the developer
http://exadel.com/tutorial/struts/5.2/guess/strutsintro.html
37
http://exadel.com/tutorial/struts/5.2/guess/strutsintro.html
38
The Struts framework is designed to help developers create web applications that utilize a MVC architecture. The framework provides three key components:
A "request" handler provided by the application developer that is mapped to a standard URI. A "response" handler that transfers control to another resource which completes the response. A tag library that helps developers create interactive form-based applications with server pages.
The framework's architecture and tags are buzzword compliant. Struts works well with conventional REST applications and with nouveau technologies like SOAP and AJAX.
UNH-M / NHTI - Professor Yusuf
http://exadel.com/tutorial/struts/5.2/guess/strutsintro.html, oracle.com 39
http://exadel.com/tutorial/struts/5.2/guess/strutsintro.html
40
http://exadel.com/tutorial/struts/5.2/guess/strutsintro.html
41
http://exadel.com/tutorial/struts/5.2/guess/strutsintro.html
42
Action Classes
It's the developer's responsibility to create these classes. They act as bridges between user-invoked URIs and business services. Actions process a request and return an ActionForward object that identifies the next component to invoke. They're part of the Controller layer, not the Model layer.
http://exadel.com/tutorial/struts/5.2/guess/strutsintro.html
43
ActionForms
These greatly simplify user form validation by capturing user data from the HTTP request. They act as a "firewall" between forms (Web pages) and the application (actions). These components allow the validation of user input before proceeding to an Action. If the input is invalid, a page with an error can be displayed.
Model Components
The Struts Framework has no built-in support for the Model layer. Struts supports any model components:
JavaBeans EJB CORBA JDO any other
http://exadel.com/tutorial/struts/5.2/guess/strutsintro.html
44
Spring Framework
The Spring Framework is an open source application framework for the Java platform and .NET Framework.[1] The core features of the Spring Framework can be used by any Java application, but there are extensions for building web applications on top of the Java Enterprise platform. Although the Spring Framework does not impose any specific programming model, it has become popular in the Java community as an alternative to, replacement for, or even addition to the Enterprise JavaBean (EJB) model. http://en.wikipedia.org/wiki/Spring_framework
45
Enterprise JavaBeans
Enterprise JavaBeans (EJB) is a managed, server-side component architecture for modular construction of enterprise applications. The EJB specification is one of several Java APIs in the Java Platform, Enterprise Edition. EJB is a server-side model that encapsulates the business logic of an application. The EJB specification intends to provide a standard way to implement the back-end 'business' code typically found in enterprise applications (as opposed to 'front-end' interface code). Such code was frequently found to address the same types of problems, and it was found that solutions to these problems are often repeatedly re-implemented by programmers. Enterprise JavaBeans were intended to handle such common concerns as persistence, transactional integrity, and security in a standard way, leaving programmers free to concentrate on the particular problem at hand.
UNH-M / NHTI - Professor Yusuf http://en.wikipedia.org/wiki/Enterprise_JavaBean
46
Enterprise JavaBeans
Accordingly, the EJB specification details how an application server provides:
Persistence via the Java Persistence API (JPA) Transaction processing Concurrency control Events using Java Message Service Naming and directory services (JNDI) Security ( Java Cryptography Extension (JCE) and JAAS ) Deployment of software components in an application server Remote procedure calls using RMI-IIOP. Exposing business methods as Web Services.
Additionally, the Enterprise JavaBean specification defines the roles played by the EJB container and the EJBs as well as how to deploy the EJBs in a container
http://en.wikipedia.org/wiki/Enterprise_JavaBean
47