Upload
others
View
20
Download
0
Embed Size (px)
Citation preview
Preparation of the material was supported by the project „Increasing Internationality in Study Programs of the Department of Computer Science II“, project number VP1–2.2–ŠMM-07-K-02-070, funded by The European Social Fund Agency and the Government of Lithuania.
Valdas Rapševičius Vilnius University
Faculty of Mathematics and Informatics
2014.02.06
Java Technologies Lecture N
2014.02.06 Valdas Rapševičius. Java Technologies 1
Session Outline
• Meet Duke! • Short introduction into the Java Platform • Intro to JCP and JSR • What is “new” in Java SE 7? • The future of Java • Course Overview
– Lectures – Hands-on – Evaluation
• References • Hands-on setup and instructions
2014.02.06 Valdas Rapševičius. Java Technologies 2
Java, JDK
• Java is generic, imperative, object-oriented, reflective programming language
• Java Technology refers to a set of several computer software products and specifications from Sun Microsystems (which has since merged with Oracle Corporation, 2010), that together provide a system for developing application software and deploying it in a cross-platform computing environment.
• Always changing … history – http://en.wikipedia.org/wiki/Java_version_history – JDK J2SE (since 1.2, JSR since 1.4) Java SE (since 6)
• Open Source?
– Sun announced in JavaOne 2006 that Java would become free and open source software – Sun released the Java HotSpot virtual machine and compiler as free software under the
GNU General Public License on November 13, 2006, with a promise that the rest of the JDK – Sun released the source code of the Class library under GPL on May 8, 2007, except some
limited parts that were licensed by Sun from 3rd parties who did not want their code to be released under a free software and open-source license.
– Sun's goal is to replace the parts that remain proprietary and closed-source with alternative implementations and make the class library completely free and open source.
– See http://openjdk.java.net/
2014.02.06 Valdas Rapševičius. Java Technologies 3
Java Platform
1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of OS X, Linux, Solaris, or Microsoft Windows
2. Java 2, Enterprise Edition (J2EE) is a comprehensive platform for multi-user, enterprise-wide applications. It is based on J2SE and adds APIs for server-side computing.
3. Java 2, Micro Edition (J2ME) is a set of technologies and specifications developed for small devices like pagers, mobile phones, and set-top boxes. J2ME uses subsets of J2SE components, such as smaller virtual machines and leaner APIs.
2014.02.06 Valdas Rapševičius. Java Technologies 4
Java Platform
2014.02.06 Valdas Rapševičius. Java Technologies 5
Java SE
2014.02.06 Valdas Rapševičius. Java Technologies 6
Java Community Process (JCP)
• Specifications for J2SE, J2EE, and J2ME are developed under the aegis of the Java Community Process (JCP).
• A specification begins with a Java Specification Request (JSR). An expert group consisting of representatives from interested companies is formed to create the specification.
• The JSR then passes through various stages in the JCP before it is finished. Every JSR is assigned a number.
• See http://jcp.org/en/home/index for everything • Sandbox: http://openjdk.java.net/
2014.02.06 Valdas Rapševičius. Java Technologies 7
Java SE 7 (since 2011): “New” Features
• JVM support for dynamic languages • Compressed 64-bit pointers • Project Coin:
– Strings in switch – Automatic resource management in try-statement – Improved type inference for generic instance creation – Simplified varargs method declaration – Binary integer literals – Allowing underscores in numeric literals – Catching multiple exception types and rethrowing exceptions with improved type
checking • Concurrency utilities under JSR-166 • New I/O • Library-level support for Elliptic curve cryptography algorithms • XRender pipeline for Java 2D (for modern GPUs) • New platform APIs for the graphics features • Enhanced libraries for new network protocols (SCTP and SDP) • Upstream updates to XML and Unicode
2014.02.06 Valdas Rapševičius. Java Technologies 8
Java SE 8: What to expect?
• Target release date is 2014/03/18 • EA release from:
https://jdk8.java.net/download.html • Features
– Language-level support for lambda expressions Lambda expressions enable you to treat functionality as a method argument, or code as data. They also let you express instances of single-method classes more compactly.
– Parallel Array Sorting The Fork/Join framework is used to provide a standard implementation of parallel sorting for arrays.
– Annotations API Updates – Base64 Encoding Schemes – Nashorn JavaScript Engine – Internationalization, Security, Platform, Tools Enhancements
2014.02.06 Valdas Rapševičius. Java Technologies 9
Course Contents
• Language basics • Essential classes and methods • Design patterns • Persistence • XML • Networking • Web • Web services • Backup:
– JVM – Development and configuration tools – GUI – Enterprise Application Servers – Polyglot programming in JVM – Component Web
2014.02.06 Valdas Rapševičius. Java Technologies 10
Course organization
• Lecture + demos – Thursdays, 16:00 18:00 – Material: http://mif.vu.lt/~valdo
• Hands-on consultation – Thursdays, 14:00 15:00
• Other consultation, questions – [email protected] – Baltupiai, room 325 (weekdays 9am to 3pm)
• VMA – Announcements (+email) – Tasks, Instructions – Submit Tasks? – Evaluation
2014.02.06 Valdas Rapševičius. Java Technologies 11
Hands-on Tasks
• Task packages: – Feb W1: initial project – Mar W1: essential classes and methods – Apr W1: persistence API and XML – May W1: web and webservices
• All tasks must be submitted before the next one
received (1 package = 1 month) • Instructions (see next slides, demo)
2014.02.06 Valdas Rapševičius. Java Technologies 12
Evaluation
• Exam allowed only if ALL hands-on tasks completed!
• Exam – 1 exam task bundle – No instructions (not decided yet…) – 2 hours programming – Plus for the complete, inventive and clean solution
2014.02.06 Valdas Rapševičius. Java Technologies 13
#1 Online
• Java SE Downloads http://www.oracle.com/technetwork/java/javase/downloads/index.html
• Java SE Tutorial
http://docs.oracle.com/javase/tutorial/index.html
• Java EE Tutorial http://docs.oracle.com/javaee/6/tutorial/doc/
• Java SE API documentation
http://docs.oracle.com/javase/7/docs/api/index.html
• Java EE API documentation http://docs.oracle.com/javaee/6/api/
• The Java™ Virtual Machine Specification http://docs.oracle.com/javase/specs/jvms/se7/html/index.html
• OpenJDK
http://openjdk.java.net/
2014.02.06 Valdas Rapševičius. Java Technologies 14
#1 Books
• Joshua Bloch. Effective Java (2nd Edition) http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683
• Madhusudhan Konda. What's New in Java 7?
http://www.amazon.com/Whats-New-Java-7-ebook/dp/B005XSS8VC
• Benjamin J Evans, Martijn Verburg. The Well-Grounded Java Developer: Vital techniques of Java 7 and polyglot programming
http://www.amazon.com/Well-Grounded-Java-Developer-techniques-programming/dp/1617290068
• Charlie Hunt, Binu John. Java Performance
http://www.amazon.com/Java-Performance-Charlie-Hunt/dp/0137142528
• Erich Gamma, et al. Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley Professional Computing Series)
www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612
• Mark Cade, Simon Roberts. Sun Certified Enterprise Architecture for J2EE Technology Study Guide
http://www.amazon.com/Certified-Enterprise-Architecture-Technology-Study/dp/0130449164
2014.02.06 Valdas Rapševičius. Java Technologies 15
#2 Online
• Ergonomics in the 5.0 Java TM Virtual Machine http://www.oracle.com/technetwork/java/ergo5-140223.html
• Java SE 6 HotSpot™ Virtual Machine Garbage Collection Tuning
http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html
• PrintAssembler instructions https://wikis.oracle.com/display/HotSpotInternals/PrintAssembly
• HSDIS plugin for HotSpot
http://kenai.com/projects/base-hsdis/downloads
• Whats new in JSF 2.0 http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/
• Apache Maven
https://tech.lds.org/wiki/Introduction_to_Maven
• Apache Ant Manual http://ant.apache.org/manual/index.html
• Martin Fowler “Inversion of Control Containers and the Dependency Injection pattern”
http://martinfowler.com/articles/injection.html
2014.02.06 Valdas Rapševičius. Java Technologies 16
Hands-on: Setup
• Install Java SE 1.7 JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html
• Command line – Apache Maven (http://maven.apache.org/) – Any editor, i.e. vim
• IDE – Eclipse (http://www.eclipse.org/downloads/)
• Install m2e plugin
– Netbeans (https://netbeans.org/downloads/) – …
2014.02.06 Valdas Rapševičius. Java Technologies 17
Hands-on: Instructions
• Download package $ wget http:// … /javatech_tasks01.zip
• Unpack it $ unzip javatech_tasks01.zip
• Options – Console
• Change to unpacked dir $ cd tasks01
• Build and test $ mvn test
• Create/edit code at $ vim src/main/java $ vim src/main/resources (optional)
• Test again until you get SUCCESS! – IDE
• Open project in IDE, create/edit code, test project • Once done – pack code files and submit to VMA
$ mvn package $ ls target/task01-1.0-sources.jar
2014.02.06 Valdas Rapševičius. Java Technologies 18
Compile tests
Run tests
Check code
Package
Receive bundle
Submit code
Maven project structure
./pom.xml // Project configuration ./src // Source code folder ./src/test // Test files ./src/test/java // Test Java files ./src/test/java/lt/mif/… // Test Java packages, files ./src/test/resources // Other test files ./src/main // Source code files ./src/main/java // Source code Java files ./src/main/java/lt/mif/… // Source Java packages, files ./src/main/resources // Other source files ./target // Build products ./target/test-classes // Compiled test class files ./target/classes // Compiled source class files ./target/{project}-{version}-sources.jar // Source bundle to submit!
2014.02.06 Valdas Rapševičius. Java Technologies 19
Maven Project Lifecycle
2014.02.06 Valdas Rapševičius. Java Technologies 20
Cheat list
Compile, run tests and checks $ mvn clean test Compile, run tests, checks and package $ mvn clean package Compile code only $ mvn compile Compile tests only $ mvn test-compile Compile, run checks only $ mvn -DskipTests test Package, skip checks and tests $ mvn -DskipTests -Dcheckstyle.skip=true package Compile, run single test file $mvn -Dtest=lt.vu.mif.jate.tasks.task01.StringUtilityTest test Remove all build products $ mvn clean
2014.02.06 Valdas Rapševičius. Java Technologies 21
JUnit
• Unit testing A unit test is a piece of code written by a developer that executes a specific functionality in the code under test. Unit tests ensure that code is working as intended and validate that this is still the case after code changes.
• Unit testing with JUnit JUnit is a test framework which uses annotations to identify methods that are test methods. JUnit assumes that all test methods can be executed in an arbitrary order. Therefore tests should not depend on other tests.
• To write a test with JUnit – Annotate a method with @org.junit.Test – Use a method provided by JUnit to check the expected result of the code execution versus the actual
result – You can use Eclipse, Netbeans or the org.junit.runner.JUnitCore class to run the test.
• Example: import org.junit.Test; import static org.junit.Assert.*; public class MyUnitTest { @Test public void testConcatenate() { MyUnit myUnit = new MyUnit(); String result = myUnit.concatenate("one", "two"); assertEquals("onetwo", result); } }
2012.12.31 Valdas Rapševičius. Java Technologies 22
JUnit: org.junit.Assert static void assertArrayEquals(byte[] expecteds, byte[] actuals)
Asserts that two byte arrays are equal. static void assertEquals(java.lang.Object expected, java.lang.Object actual)
Asserts that two objects are equal. static void assertFalse(boolean condition)
Asserts that a condition is false. static void assertNotNull(java.lang.Object object)
Asserts that an object isn't null. static void assertNotSame(java.lang.Object unexpected, java.lang.Object actual)
Asserts that two objects do not refer to the same object. static void assertNull(java.lang.Object object)
Asserts that an object is null. static void assertSame(java.lang.Object expected, java.lang.Object actual)
Asserts that two objects refer to the same object. static <T> void
assertThat(java.lang.String reason, T actual, org.hamcrest.Matcher<T> matcher) Asserts that actual satisfies the condition specified by matcher.
static void assertTrue(boolean condition) Asserts that a condition is true.
static void fail() Fails a test with no message.
static void fail(java.lang.String message) Fails a test with the given message.
2012.12.31 Valdas Rapševičius. Java Technologies 23
Session Conclusions
• Java language and technologies are a hype! • Course content and pace depends on you • Exam is tough – get well prepared
– Do the tasks by yourself – Use techniques from lecture – Use practise hours for questions, excersizes
2014.02.06 Valdas Rapševičius. Java Technologies 24