Java Technologies. Introductionvaldo/jate2016/JavaTech.L00.pdf · Java Community Process (JCP) •...
Transcript of Java Technologies. Introductionvaldo/jate2016/JavaTech.L00.pdf · Java Community Process (JCP) •...
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
2016.02.09
Java Technologies Lecture N
2016.02.09 Valdas Rapševičius. Java Technologies 1
Session Outline
• Meet Duke! • Short introduction into the Java Platform • Intro to JCP and JSR • Java SE 7 • Java SE 8 • Java SE 9 • Course Overview
– Lectures – Hands-on – Evaluation
• References • Hands-on setup and instructions
2016.02.09 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/
2016.02.09 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.
2016.02.09 Valdas Rapševičius. Java Technologies 4
Java Platform
2016.02.09 Valdas Rapševičius. Java Technologies 5
Java SE
2016.02.09 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/
2016.02.09 Valdas Rapševičius. Java Technologies 7
Java SE 7 (since 2011)
• 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
2016.02.09 Valdas Rapševičius. Java Technologies 8
Java SE 8 (since 2014)
• 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
2016.02.09 Valdas Rapševičius. Java Technologies 9
Java SE 9: What to expect?
• EA release from: https://jdk9.java.net/download/
• Features – Modular source code (Project Jigsaw) – Lightweight JSON API – HTTP 2 Client – Process API updates – Improved Lock Contention – …
• Schedule
– 2016/05/26 Feature Complete – 2016/08/11 All Tests Run – 2016/10/20 Zero Bug Bounce – 2017/01/26 Final Release Candidate – 2017/03/23 General Availability
2016.02.09 Valdas Rapševičius. Java Technologies 10
Course Contents
• Themes – Language basics – Essential classes and
methods – Functional
programming – Design patterns – JVM – Persistence – Polyglot programming
primer
• Backup: – Development and
configuration tools – GUI – XML – Enterprise Application
Servers – Networking – Component Web – Web – Web services
2016.02.09 Valdas Rapševičius. Java Technologies 11
Course organization
• Lecture + demos – Tuesdays, 16:00 17:30
• Hands-on consultation – Tuesdays, 18:00 19:30
• Other consultation, questions – [email protected] – skype: valdasraps – Baltupiai, room 325 (weekdays 10am to 3pm)
• VMA – Announcements (+email) – Tasks, Instructions – Submit Tasks? – Evaluation
2016.02.09 Valdas Rapševičius. Java Technologies 12
Hands-on Tasks
• Task packages: – Feb - Mar: environment setup, first hands-on 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)
2016.02.09 Valdas Rapševičius. Java Technologies 13
Evaluation
• Tasks – 1 task bundle = 2 points – Max 6 points from hands-on tasks – Exam allowed only if at least 1 hands-on task completed! – Plagiarism check before exam!
• Score can be reduced or rejected!
• Exam – 1 exam task bundle – No instructions – 2 hours programming – Max 4 points
2016.02.09 Valdas Rapševičius. Java Technologies 14
Results for years 2014 and 2015
2016.02.09 Valdas Rapševičius. Java Technologies 15
#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/
2016.02.09 Valdas Rapševičius. Java Technologies 16
#1 Books
• Joshua Bloch. Effective Java (2nd Edition) http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683
• Java 8 in Action. Lambdas, streams, and functional-style programming
https://www.manning.com/books/java-8-in-action
• 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
2016.02.09 Valdas Rapševičius. Java Technologies 17
Hands-on: Setup
• Manual – Install Java SE 1.8 JDK – Apache Maven – Any editor, i.e. notepad, vim, …
• Recommended
– Eclipse
• http://www.eclipse.org/downloads/ • Install m2e plugin
– Netbeans • https://netbeans.org/downloads/
– IntelliJ • https://www.jetbrains.com/idea/download/
2016.02.09 Valdas Rapševičius. Java Technologies 18
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
2016.02.09 Valdas Rapševičius. Java Technologies 19
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!
2016.02.09 Valdas Rapševičius. Java Technologies 20
Maven Project Lifecycle
2016.02.09 Valdas Rapševičius. Java Technologies 21
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
2016.02.09 Valdas Rapševičius. Java Technologies 22
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
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
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
2016.02.09 Valdas Rapševičius. Java Technologies 25