Training - Day 1 - PowerPoint PPT Presentation

training day 1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Training - Day 1 PowerPoint Presentation
Download Presentation
Training - Day 1

play fullscreen
1 / 85
Training - Day 1
116 Views
Download Presentation
ori-rowland
Download Presentation

Training - Day 1

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Training - Day 1 Nate Johnson Indiana University Davis, CA : Sept 18-21, 2006

  2. Principal Systems Analyst Indiana University in Bloomington, IN SIT (Systems Integration Team) Portal Workflow Integration Production debugging & troubleshooting Training About me

  3. Very informal… feel free to ask questions at any time Start each day at 9:00 am and try to finish near 5:00 pm Lunch? This week

  4. Eclipse MyEclipse Web environment Ant & log4j Java 5.0 Monday Sept 18

  5. Struts Framework Struts tag libraries JSP JSTL Custom JSTL tags DisplayTag tag library Tuesday Sept 19

  6. OJB Might begin the Spring Framework Wednesday Sept 20

  7. Spring Framework Testing jUnit jMeter Thursday Sept 21

  8. Lots of exercises and sample code Feel free to work in pairs and talk out the exercises Will also be building a small sample application that uses all of the frameworks we are learning this week This week continued…

  9. Most of this section will be covered via a demo/walkthrough Section 1: Eclipse & MyEclipse

  10. The workbench Perspectives Views Editors Toolbars and menus Exploring our project Navigating Eclipse

  11. The term Workbench refers to a desktop development environment. It strives to seamlessly integrate perspectives (editors, views, menus, etc.) into a useful environment. The Welcome project (Help > Welcome) The Workbench

  12. A workbench may contain multiple perspectives (Java, Debug, CVS, etc.) A perspective is a group of related editors, views, and menu actions Switch (or add / remove) perspectives using the perspective shortcut bar Perspectives

  13. Editors are typically used to edit a resource (a Java or XML file) Multiple instances of an editor may be open at the same time - editing multiple Java and XML files Editors follow a open > save > close lifecycle (* denotes an unsaved editor) External editors can be used (MS Word) Editors

  14. Used to navigate a hierarchy of information Resources Outlines Display properties Can be moved and re-docked to fit you Modifications are saved immediately Most likely only one instance of a view will exist at one time Fast Views save space on small screens Views

  15. The main, or workbench, toolbar Changes based on active perspective Active view may enable/disable features Sections can be rearranged View toolbars Appear in title bar of the view May also have a triangle button menu dropdown Perspective switcher Fast view bar Toolbars and Menus

  16. Create a brand new Java project File > New > Project Select Java Project Follow the wizard Create new files File > New > Class | Interface | etc. Be sure to give it a package and legal name Creating a new things

  17. Check out a project from CVS Most likely method used in UIS Use CVS Repository Perspective Get the project: Right-click > Check Out Using Source Control

  18. Do you have any red X’s in your Package Explorer? If so, we need to figure them out before continuing Views: Overview most common… add Ant View if not currently available Editors: Overview the Java Source Editor and the MyEclipse XML Editor Exploring the project

  19. Project properties The deployment script: build.xml MyEclipse Window > Preferences… > MyEclipse MyEclipse toolbar icons Build (automatically) and run the project Still Exploring…

  20. Eclipse Platform http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.user/tips/platform_tips.html Java Specific http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.jdt.doc.user/tips/jdt_tips.html Let’s take a look at some! Tips and tricks

  21. http://help.eclipse.org/help32/index.jsp References

  22. The HTTP Request / Response cycle Properties Files and Resource Bundles Java Servlets Servlets and threads Servlet Context Servlet Request Servlet Response Filtering Sessions Web Applications Web application deployment descriptor (web.xml) Java Server Pages and JSP Tag Libraries Section 2: Web Environment

  23. User makes a request (for a webpage in a browser). Web server gets request, and formulates a response to send to user. Stateless! Frameworks, like Struts, make this easier than the old CGI, or even Servlets, programming models. HTTP Request / Response Cycle

  24. Common way to configure web applications. ResourceBundles use one or more files to provide i18n based on Locales. Properties Files & ResourceBundles

  25. Java’s OO HTTP A servlet container maps requests to servlets as well as maintains the servlet lifecycle. public void init( ServletConfig config); public void doGet( HttpServletRequest request, HttpServletResponse response); public void doPost( HttpServletRequest request, HttpServletResponse response); public void destroy(); org.apache.struts.action.ActionServlet Java Servlets

  26. Web container can boost performance by multi-threading servlets (the default way a servlet is deployed and coded). One instance of a servlet is created and all requests go through it. doGet() and doPost() need to be thread safe. Servlets and threads

  27. Servlet’s view of the web application which is running the servlet. Servlet.getServletConfig() and JSP application variable. Provides access to webapp resources and servlet context attributes. Servlet Context

  28. javax.servlet.http.HttpServletRequest Cookies - the cookies included with this request Headers - HTTP headers that were included with the request Parameters - Request parameters from the query string or post data Request URI Information – items such as contextPath, servletPath, and pathInfo And more… Request attributes are very useful in relaying information to Views – you will see this when we start looking at the Actions and JSPs. Servlet Request

  29. javax.servlet.http.HttpServletResponse Set Headers - set response headers, such as Content-Type. Set Cookies - add cookies to the current response. Send Error Responses - send an HTTP error status (instead of a usual page of content). Redirect To Another Resource - use the sendRedirect() method to redirect the client to some other URL that you specify. Any of the above MUST be done before the first buffer is flushed the user will see an error. Most of the time you will not directly manipulate the response object… the framework, Struts, will do it for you. Servlet Response

  30. javax.servlet.Filter Process requests/responses and can be chained. Good place to do common processing for all requests. Ex: The CAS filter, which can help in providing SSO and an IU User to each request. Filtering

  31. HTTP is stateless, which means every request is brand new. javax.servlet.http.HttpSession The servlet container can provide the concept of a session in two ways Cookies URL Rewriting Have a timeout Session attributes need to be Serializable. Think carefully about how much you store in Session: this uses memory (session/per user) on the server. Sessions

  32. A servlet container can run many web application at one time. Each web application has its own namespace. A web application is bundled into a Web Application Archive file (WAR). Web Applications

  33. <webapp>/WEB-INF/web.xml Configuration of a web application, and the web application lifecycle In UIS, we configure CAS, log4j, various tag libraries, and datasources in web.xml Let’s check it out Web application deployment descriptor (web.xml)

  34. A JSP is an xml document, that looks similar to HTML, which can contain Java logic or use special tags, and creates a dynamic web page. JSP is compiled into a servlet by the servlet container. Tag libraries are sets of JSP tags, that can be used for a number of tasks, from logic to formatting to querying a database. Java Server Pages & JSP Tag Libs

  35. Let’s take a look at our webapp Walkthrough

  36. Ant http://ant.apache.org/manual/index.html log4j Let me know if there are others you would like to know about and we might be able to work them in at the end of the week. Section 3: Useful Libraries

  37. Generics Enhanced for loop Auto-boxing and auto-unboxing Typesafe enumerated types Variable arguments Static imports Section 4: Java 1.5 (aka 5.0)

  38. Networking Security Formatter Scanner Concurrency Utilities Monitoring More changes…

  39. Compare and contrast generic and non-generic collections Use the generic version of the Collections API Use generics with wildcards Integrate legacy (non-generic) code with generic code Generics

  40. Common examples are container types such as the Collections: Set, List, and Map List myIntList = new LinkedList(); myIntList.add(new Integer(47)); Integer x=(Integer) myIntList.get(0); Line 3 introduces clutter but is essential to guarantee type safety Intro

  41. With generics, you can: Specify element type of collection Enforce specification at compile time No more runtime errors Provide stronger typing with less clutter What does generics give you

  42. The core idea behind generics is that programmers can mark a list as being restricted to a certain type List<Integer> myIntList = new LinkedList<Integer>(); myIntList.add(new Integer(47)); Integer x = myIntList.get(0); You say that List is a generic interface that takes a type parameter – in this case, Integer Notice, also, that the cast is gone on line 3 Same example, with Generics

  43. Example of List and Iterator using generics: public interface List<E> { void add(E x); Iterator<E> iterator(); } public interface Iterator<E> { E next(); boolean hasNext(); } Elements in the angle brackets ( <E> in this example) represent formal type parameters Defining your own Generics

  44. During invocation, formal type parameters are replaced by actual type parameters Imagine that List<Integer> stands for a version of List where E has been formally replaced by Integer: List<Integer> myInteger; Is like: IntegerList myList; Where: public interface IntegerList { void add(Integer x); Iterator<Integer> iterator(); } Defining continued…

  45. Consider the following example: List<String> ls = new ArrayList<String>(); List<Object> lo = ls; Is this legal? Line 2 suggests that a List of String is a List of Objects. Subtyping Generics

  46. What if you had this: lo.add(new Object()); String s = ls.get(0); The generics would fail The compiler will prevent you from doing the assignment in the first place Actually, it’s not

  47. You may think that a wildcard would be Collection<Object> since Object is the base class of all objects – but its not. For generics, it’s Collection<?> where ? is to be read as “unknown” For subclassing something like Shape (Circle and Rectangle) you can not just use List<Shape> You have to do it this way: List<? extends Shape> Wildcards and Subtyping

  48. From the previous slide’s classes. This would only draw Shape objects. public void drawAll(List<Shape> shapes) Whereas this would draw anything. public void drawAll(List<?> objects) And this would draw anything that extends Shape. public void drawAll(List<? Extends Shape> shapes) General v. Bounded Wildcards

  49. Write a method that takes an array of objects and a collection and dumps all of the objects into the collection: void arrayToCollection(Object[] a, Collection<?> c) { for (Object o : a) { c.add(o); // compile time error } } Will not work? Why? Generic Methods

  50. As with type declarations, method declarations can also be generic: <T> void arrayToCollection(T [] a, Collection<T> c) { for (T o : a) { c.add(o); // NO compile time error } } T is the return type, collection type, and array type We need generic methods