intro to java week 7
play

Intro to Java Week 7 Tuesday, December 9, 14 Homeworks 5 6 - PowerPoint PPT Presentation

Intro to Java Week 7 Tuesday, December 9, 14 Homeworks 5 6 Tuesday, December 9, 14 JUnit Hugely popular unit test framework Simple, easy to use Eclipse integration Right click on source file, click on JUnit Test Case next,


  1. Intro to Java Week 7 Tuesday, December 9, 14

  2. Homeworks 5 6 Tuesday, December 9, 14

  3. JUnit Hugely popular unit test framework Simple, easy to use Eclipse integration Right click on source file, click on “JUnit Test Case” “next”, select methods you want to test, “finish” may ask to put JUnit on build path, do so replace the “fail” calls with your test Right click on JUnit file, “run as JUnit test” Junit window will show the status of your tests Tuesday, December 9, 14

  4. Singleton Used to be “instantiate and set a static variable if it was null” class Foo { private Single single; Single getSingle() if(single == null) single = new Single; return single;} Proper way now is to use an Enum enum Single ... Tuesday, December 9, 14

  5. MVC(Model View Controller) Important design pattern Tuesday, December 9, 14

  6. Weka Machine Learning package written in Java Very easy to use, well documented. Excellent associated book Can use interactive app to explore techniques, then program against API Tuesday, December 9, 14

  7. Computing on Clusters Some jobs too big for single machines Difficult to parallelize across multiple machine How to divy up and recombine the work? How to start, stop, coordinate different machines? Servers used to be big, expensive, highly reliable Servers now are cheap and expected to fail Facebook OpenHardware How to deal with machine failures? Tuesday, December 9, 14

  8. MPI(Message Passing Interface) Complex, low level, do-it-yourself Somewhat like Actors Popular in science and engineering Tuesday, December 9, 14

  9. Centralized Storage Network Servers connect to a centralized storage system over a network Network can saturate Tuesday, December 9, 14

  10. Hadoop Focuses on streaming data, instead of random access Disk seeks are much slower than disk transfers Relational data often normalized web logs not normalized Tuesday, December 9, 14

  11. HDFS Write-once, read-many Data redundancy, to compensate for failures, and place data near CPUs, ideally disk on CPU, or in same rack HDFS, by default, saves three copies of data Newer file systems (Reed-Solomon Erasure Codes) save 1.5X copies High latency, high thruput Likes big files - size multiples of 64M Lots of small files not optimal, keeps file map in memory Tuesday, December 9, 14

  12. Hadoop - Pig Scriptable Interpreter PigPen - Eclipse plugin Not SQL - more “imperative” Tuesday, December 9, 14

  13. Hadoop - Hive Interpreter Scriptble SQL dialect Developed by Facebook Tuesday, December 9, 14

  14. Hadoop - HBase Simple table model that can be written and read in real time Good match for web crawlers Tuesday, December 9, 14

  15. Hadoop - Zookeeper Coordinates cluster of machines Handles failures, new leader election Used by Haddop, but generally useful Tuesday, December 9, 14

  16. Hadoop is Great, but... Long latency - people want real time Lots of disk IO Machines turning up with large memory AWS has 350gig main memory instances Hadoop poor fit for tasks like machine learning that want to run in memory for a long time Tuesday, December 9, 14

  17. Spark Written in Scala Supports apps in Scala, Python, and Java Graph processing, SQL Orx - real time machine learning Tuesday, December 9, 14

  18. Scala - Java++ ? Multi-Paradigm, primarily functional and object oriented Huge language Runs on JVM Interoperates with Java Can use all Java APIs Currently small market share compared to Java, but turns up in interesting places Twitter and some other startups Academia If you know Java, you’re 3/ 4 to Scala Tuesday, December 9, 14

  19. Scala Features scriptable type inference EVERYTHING is an object - no primitives like Java 234.toString() Garbage Collection All statements return a value(sometimes Unit(void)) Mutable and Immutable versions of everything traits are very similar to java 1.8 interfaces Tuesday, December 9, 14

  20. Scala Features no “statics” - use singleton Concurrency Futures(like Java) Actor Framework(AKKA) - like BikeCo Pattern Matching Tuesday, December 9, 14

  21. J2EE Multi-tier framework for web/ enterprise applications APIs for each tier Annotations have mostly replace XML for configuration I know Chase uses it... Tuesday, December 9, 14

  22. Tuesday, December 9, 14

  23. J2EE EJBs Beans live in a EJB container, which manages them and provides a variety of services. Beans are recycled by the container Session beans Stateful - maintain state across calls shopping cart Stateless - just do computation, send JMS messages Singleton Message beans Consume messages from JMS Tuesday, December 9, 14

  24. J2EE Tier Functionality Web servlets, websockets, web page generation Web Services soap, rest Enterprise concurrency, annotations, Beans, JCA, dependency injection, object persistence, message service, enterprise java beans, transactions, email Other management, connector architecture, security, batch, JSON support Tuesday, December 9, 14

  25. J2EE - Enterprise Java Beans Beans live in a EJB container Beans are resource managed and recycled by the container Container provides many services to the beans, so bean developer can focus on business logic and not worry about infrastructure issues Transactions Concurrency Persistence Timers Tuesday, December 9, 14

  26. J2EE - Context and Dependency Injection Why do CDI? @Inject annotation can be placed on a field, method or constructor Sometimes referred as “inversion of control” @Stateless public class DeliveryService { @Inject Truck truck; or @Inject setTruck(Truck truck) { this.truck = truck;} or @Inject DeliveryService(Truck truck) { this.truck = truck; } Tuesday, December 9, 14

  27. J2EE - Bean Constraints Set of annotations that restrict values bean fields can hold @min(10) - field cannot be smaller than 10 @size(5, 10) - a collection must have size btw 5 & 10 @Past - date must be in the past @Future - date must be in the future Can define custom constraints Tuesday, December 9, 14

  28. J2EE - Transactions Container manages transactions, aborts, rollbacks Different types of transactions supported: REQUIRED - must run inside a transaction. start a new one if needed REQUIRED_NEW - start a new transaction, even if one already exists NEVER - must run outside a transaction @Transactional(TxType.REQUIRES_NEW) Can annotate method or class Tuesday, December 9, 14

  29. J2EE - Persistence Can persist a POJO by just adding a few annotations Use entityManager to create “managed POJOs”, save changes Change MPOJO fields as desired, then flush entityManager, and all changes are written to DB @Entity public class Student implements Serializable { / / the primary key @Id int id; String first, last, uni; Picture picture; Transcript transcript; } Tuesday, December 9, 14

  30. J2EE - Eager/Lazy Loading Can define “load groups”. for example first, last, uni can be eager - loaded in the query response picture and transcript can be in separate lazy groups - only loaded when the reference is touched Tuesday, December 9, 14

  31. J2EE - Security Enforces various kinds of security, based on the “role” of the user - admin, customer, etc Tuesday, December 9, 14

  32. J2EE - Implementations Various vendors implement the spec Compete on performance and extra features Using extra features can lead to vendor lockin Tuesday, December 9, 14

  33. Spring Also focused on “enterprise computing” Very nice use of annotations for configuration Even larger scope than J2EE Seems good ideas appear in Spring first, then turn up in J2EE 2 years later High level interface to servlets Modular - see Spring Modules Fantastic support - why so good? Tuesday, December 9, 14

  34. Spring - Aspect Oriented Programming Address “cross-cutting” issues without duplicating lots of code profiling, logging, etc Identify multiple method by pattern matching Install “advice” on each method. Four types Before After Around After Throwing Tuesday, December 9, 14

  35. Another “Container” - Docker Docker provides “services” to docker jobs, which run in a “sandboxed” linux process Avoids the overhead of virtual machines Tuesday, December 9, 14

  36. Android Uses Dalvik VM, not a JVM Dalvik supposed to better with limited resources Java version roughly comparable to JDK 6 Subset of SE libraries Development systems based on Eclipse and Intellj For development, recommend using an Android device instead of the emulator Easy to setup Tuesday, December 9, 14

  37. Large Frameworks Downside Usually steep learning curve, really helps to have a friendly guru around, or a support contract. Configuration can be difficult Upside Can do amazing things with limited resources Tuesday, December 9, 14

  38. In Conclusion Java is a BIG language Mostly clean and well designed Illustrates many important concepts Very influential Huge mindshare in the “real world” Lots of things we didn’ t cover, but we hit the major points Tuesday, December 9, 14

  39. That’ s all, folks Thanks Tuesday, December 9, 14

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend