Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing...
Transcript of Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing...
![Page 1: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/1.jpg)
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
2015.02.11
Java Technologies Lecture N
2015.02.11 Valdas Rapševičius. Java Technologies 1
![Page 2: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/2.jpg)
Session Outline
• Meet Duke! • Short introduction into the Java Platform • Intro to JCP and JSR • What is “new” in Java SE 7? • What is new in Java SE 8? • The future of Java • Course Overview
– Lectures – Hands-on – Evaluation
• References • Hands-on setup and instructions
2015.02.11 Valdas Rapševičius. Java Technologies 2
![Page 3: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/3.jpg)
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/
2015.02.11 Valdas Rapševičius. Java Technologies 3
![Page 4: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/4.jpg)
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.
2015.02.11 Valdas Rapševičius. Java Technologies 4
![Page 5: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/5.jpg)
Java Platform
2015.02.11 Valdas Rapševičius. Java Technologies 5
![Page 6: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/6.jpg)
Java SE
2015.02.11 Valdas Rapševičius. Java Technologies 6
![Page 7: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/7.jpg)
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/
2015.02.11 Valdas Rapševičius. Java Technologies 7
![Page 8: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/8.jpg)
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
2015.02.11 Valdas Rapševičius. Java Technologies 8
![Page 9: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/9.jpg)
Java SE 8 (since 2014): New Features
• New functionality – JSR 308: Annotations on types – JSR 310: Date and Time API – JSR 335: Lambda expressions
• Updated functionality – JSR 114: JDBC Rowsets – JSR 160: JMX Remote API – JSR 173: Streaming API for XML – JSR 199: Java Compiler API – JSR 206: Java API for XML Processing – JSR 221: JDBC 4.0 – JSR 269: Pluggable Annotation-Processing AP
2015.02.11 Valdas Rapševičius. Java Technologies 9
![Page 10: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/10.jpg)
Java SE 9: What to expect?
• To be released sometime in 2016 • EA release from:
https://jdk9.java.net/download/ • Features
– Modular source code (Project Jigsaw) – Lightweight JSON API – Process API updates – Improved Lock Contention – …
2015.02.11 Valdas Rapševičius. Java Technologies 10
![Page 11: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/11.jpg)
Course Contents
• Themes – Language basics – Essential classes and
methods – Functional programming – Design patterns – Persistence – Networking
• Backup: – JVM – Development and
configuration tools – GUI – XML – Enterprise Application
Servers – Polyglot programming in
JVM – Component Web – Web – Web services
2015.02.11 Valdas Rapševičius. Java Technologies 11
![Page 12: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/12.jpg)
Course organization
• Lecture + demos – Tuesdays, 16:30 18:00
• Hands-on consultation – Tuesdays, 18:00 19:30
• Other consultation, questions – [email protected] – Baltupiai, room 325 (weekdays 10am to 3pm)
• VMA – Announcements (+email) – Tasks, Instructions – Submit Tasks? – Evaluation
2015.02.11 Valdas Rapševičius. Java Technologies 12
![Page 13: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/13.jpg)
Hands-on Tasks
• Task packages: – Feb - Mar: simple project – Mar - Apr: essential classes and methods – Apr - May: persistence API, concurrency, networking
• All tasks must be submitted before the end of
second month (1 package = 2 months) • Instructions (see next slides, demo)
2015.02.11 Valdas Rapševičius. Java Technologies 13
![Page 14: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/14.jpg)
Evaluation
• Before exam – 1 task bundle = 2 points – Max 6 points from hands-on tasks – Exam allowed only if at least 1 hands-on task completed!
• Exam – 1 exam task bundle – No instructions – 2 hours programming – Plus for the complete, inventive and clean solution – Max 4 points
2015.02.11 Valdas Rapševičius. Java Technologies 14
![Page 15: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/15.jpg)
#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/
2015.02.11 Valdas Rapševičius. Java Technologies 15
![Page 16: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/16.jpg)
#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
2015.02.11 Valdas Rapševičius. Java Technologies 16
![Page 17: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/17.jpg)
#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
2015.02.11 Valdas Rapševičius. Java Technologies 17
![Page 18: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/18.jpg)
Hands-on: Setup
• Install Java SE 1.8 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/) – …
2015.02.11 Valdas Rapševičius. Java Technologies 18
![Page 19: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/19.jpg)
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
2015.02.11 Valdas Rapševičius. Java Technologies 19
Compile tests
Run tests
Check code
Package
Receive bundle
Submit code
![Page 20: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/20.jpg)
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!
2015.02.11 Valdas Rapševičius. Java Technologies 20
![Page 21: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/21.jpg)
Maven Project Lifecycle
2015.02.11 Valdas Rapševičius. Java Technologies 21
![Page 22: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/22.jpg)
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
2015.02.11 Valdas Rapševičius. Java Technologies 22
![Page 23: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/23.jpg)
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 23
![Page 24: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/24.jpg)
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 24
![Page 25: Java Technologies. Introductionuosis.mif.vu.lt/~valdo/jate2015/JavaTech.L00.pdf · • Unit testing . A unit test is a piece of code written by a developer that executes a specific](https://reader035.fdocuments.in/reader035/viewer/2022062505/5ec747fce76010184560b5a9/html5/thumbnails/25.jpg)
Session Conclusions
• Java language and technology is (still) 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, exercises
2015.02.11 Valdas Rapševičius. Java Technologies 25