java technologies. introductionvaldo/jate2017/javatech.l00.pdf · java platform 1. java 2, standard...

30
Valdas Rapševičius Vilnius University Faculty of Mathematics and Informatics 2017.02.06 Java Technologies Lecture N 2017.02.06 Valdas Rapševičius. Java Technologies 1

Upload: others

Post on 21-May-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Valdas Rapševičius Vilnius University

Faculty of Mathematics and Informatics

2017.02.06

Java Technologies Lecture N

2017.02.06 Valdas Rapševičius. Java Technologies 1

Page 2: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Session Outline

• Meet Duke! – Java Platform – JCP, JSR

• Java versions – SE 7 – SE 8 – SE 9

• Course Overview – Lectures – Hands-on – Evaluation

• References • Hands-on setup and instructions

2017.02.06 Valdas Rapševičius. Java Technologies 2

Page 3: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

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/

2017.02.06 Valdas Rapševičius. Java Technologies 3

Page 4: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Quiz 01

You and Java: 1. Know Java exists… 2. + University course only 3. + Took part in at least one project 4. + First choice for any project 5. + Use it daily for studies/work

2017.02.06 Valdas Rapševičius. Java Technologies 4

Page 5: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

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.

2017.02.06 Valdas Rapševičius. Java Technologies 5

Page 6: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Java Platform

2017.02.06 Valdas Rapševičius. Java Technologies 6

Page 7: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Java SE

2017.02.06 Valdas Rapševičius. Java Technologies 7

Page 8: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Java Community Process (JCP)

• Specifications for J2SE, J2EE, and J2ME are developed under 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/

2017.02.06 Valdas Rapševičius. Java Technologies 8

Page 9: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

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 re-throwing 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

2017.02.06 Valdas Rapševičius. Java Technologies 9

Page 10: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

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

2017.02.06 Valdas Rapševičius. Java Technologies 10

Page 11: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

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 – Java Shell (Read-Eval-Print Loop) – …

• Schedule

– 2017/02/09 All Tests Run – 2017/02/16 Zero Bug Bounce – 2017/03/16 Rampdown Phase 2 – 2017/07/06 Final Release Candidate – 2017/07/27 General Availability

2017.02.06 Valdas Rapševičius. Java Technologies 11

Page 12: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Quiz 02

Which Java version are you familiar with? 1. Java 6 2. Java 7 3. Java 8 4. Java 9 5. Groovy 6. Scala 7. None or idek

2017.02.06 Valdas Rapševičius. Java Technologies 12

Page 13: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Course Contents / Primary

1. Language basics 2. Essential classes and methods 3. Functional programming 4. Design patterns 5. JVM 6. Persistence

2017.02.06 Valdas Rapševičius. Java Technologies 13

Page 14: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Course Contents / Secondary

1. Development and configuration tools (Ant, Maven, Gradle) 2. GUI (AWT, Swing) 3. XML (Parsing, XSL, XSD) 4. Enterprise Application Servers (Managed Beans) 5. Networking (Sockets, RMI) 6. Web (Servlet, JSP) 7. Component Web (JSF, others) 8. Web services (SOAP, REST) 9. Polyglot programming primer (Groovy, Scala, Clojure)

2017.02.06 Valdas Rapševičius. Java Technologies 14

Page 15: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Course organization

• Lecture + demos (PBL?) – Tuesdays, 16:00 17:30

• 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 – Evaluation

2017.02.06 Valdas Rapševičius. Java Technologies 15

Page 16: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

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)

2017.02.06 Valdas Rapševičius. Java Technologies 16

Page 17: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Evaluation

• Tasks – 1 task bundle = 2 points – Max 6 points from hands-on tasks – Exam allowed only if first 2 hands-on tasks completed! – Plagiarism check before exam!

• Score can be reduced or rejected!

• Exam – 1 exam task bundle – No instructions – 2 hours programming – Max 4 points

2017.02.06 Valdas Rapševičius. Java Technologies 17

Page 18: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Results for years 2014, 2015, 2016

2017.02.06 Valdas Rapševičius. Java Technologies 18

1 2 3 4 5 6 7 8 9 10

Page 19: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

#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/

2017.02.06 Valdas Rapševičius. Java Technologies 19

Page 20: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

#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

2017.02.06 Valdas Rapševičius. Java Technologies 20

Page 21: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Quiz 03

Are you familiar with? 1. Apache Ant 2. Apache Ivy 3. Apache Maven 4. Gradle

2017.02.06 Valdas Rapševičius. Java Technologies 21

From https://karussell.wordpress.com/2009/09/29/evolution-of-build-systems/

Page 22: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Hands-on: Setup

• Manual – Install Java SE 1.8 JDK – Git VCS – 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/

2017.02.06 Valdas Rapševičius. Java Technologies 22

Page 23: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Quiz 04

Which IDE will you use for the course (if any)? 1. Netbeans 2. Eclipse 3. IntelliJ 4. Vim (or other text editor) and CLI 5. Undecided

2017.02.06 Valdas Rapševičius. Java Technologies 23

Page 24: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Hands-on: Instructions

• Download package $ git co http://...

• 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 email

$ mvn package $ ls target/task01-1.0-sources.jar

2017.02.06 Valdas Rapševičius. Java Technologies 24

Compile tests

Run tests

Check code

Package

Checkout

Submit code

Page 25: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Maven project structure ./pom.xml // Project configuration ./src // Source code folder # Do not put your code here! ./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 # Put your code here! ./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 # This is temporary folder, removed by mvn clean ./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! 2017.02.06 Valdas Rapševičius. Java Technologies 25

Page 26: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Maven Project Lifecycle

2017.02.06 Valdas Rapševičius. Java Technologies 26

Page 27: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

Maven 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

2017.02.06 Valdas Rapševičius. Java Technologies 27

Page 28: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

JUnit

• Unit testing • Unit testing with JUnit • To write a test with JUnit

– @org.junit.Test – Method to check the expected result of the code execution versus the actual result – 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() { SomeClass c = new SomeClass(); String result = c.concatStrings("one", "two"); assertEquals("onetwo", result); } }

2012.12.31 Valdas Rapševičius. Java Technologies 28

Page 29: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

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 29

Page 30: Java Technologies. Introductionvaldo/jate2017/JavaTech.L00.pdf · Java Platform 1. Java 2, Standard Edition (J2SE) is designed for desktop computers. Most often it runs on top of

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

2017.02.06 Valdas Rapševičius. Java Technologies 30