0% found this document useful (0 votes)
4 views

Session 01 Java 11, JUnit, Functional programming

The document provides an overview of Java 11, JUnit, and functional programming concepts introduced in Java 8, including features like lambdas, streams, and optionals. It covers the differences between JDK, JRE, and JVM, as well as various software testing methodologies and types, such as unit testing and integration testing. Additionally, it highlights new features in Java 11, including string and file methods, and introduces JUnit as a framework for unit testing in Java.

Uploaded by

spaguitte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Session 01 Java 11, JUnit, Functional programming

The document provides an overview of Java 11, JUnit, and functional programming concepts introduced in Java 8, including features like lambdas, streams, and optionals. It covers the differences between JDK, JRE, and JVM, as well as various software testing methodologies and types, such as unit testing and integration testing. Additionally, it highlights new features in Java 11, including string and file methods, and introduces JUnit as a framework for unit testing in Java.

Uploaded by

spaguitte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 69

Session 01

ANTEA TRAINING
Java 11, JUnit, Functional programming
Session 01
• Summary

1. Java Runtime class


2. Functional programming in Java 8
• Lambdas, Stream, Optional, etc.
3. New features in Java 11
4. Software Testing
Introduction to Java
• Java is a programming language and a platform. Java is a high
level, robust, object-oriented and secure programming
language.
• Application of Java:

Desktop, Web, Enterprise Application, Mobile, Embedded …


• Types of Java Applications

1) Standalone Application
2) Web Application
3) Enterprise Application
4) Mobile Application
Introduction to Java
Introduction to Java
• Java vs C++ Application
Introduction to Java
Difference between JDK, JRE, and JVM
• The JVM Loads, Verifies and Executes the code (Provides runtime
environment).
• The JRE is the implementation of JVM.
• Oracle JDK, OpenJDK , GraalVM, Android Runtime (ART)
• The JDK is a software development environment which is used to
develop Java applications.
• Javac, Jar, Javadoc, Jconsole, Jvisualvm
Introduction to Java
Classloader is a subsystem of JVM used to load class files.
1. Bootstrap ClassLoader
2. Extension ClassLoader
3. Application ClassLoader
Introduction to Java
Garbage collector : process of reclaiming the runtime unused
memory automatically.
Introduction to Java
Java Runtime: a java class is used to interact with JRE.

No. Method Description

1) public static Runtime getRuntime() returns the instance of Runtime class.

2) public void exit(int status) terminates the current virtual machine.

3) public void addShutdownHook(Thread hook) registers new hook thread.

4) public Process exec(String command)throws executes given command in a separate


IOException process.

5) public int availableProcessors() returns no. of available processors.

6) public long freeMemory() returns amount of free memory in JVM.

7) public long totalMemory() returns amount of total memory in JVM.


Session 01

Functional programming in Java 8


Functional programming in Java 8
What is functional programming?
• Declarative style of programming rather than imperative.
• The objective is to make code more concise, less complex,
more predictable, and easier to test.

• In functional programming you can do :


• We can pass objects to a function.
• We can create objects within function.
• We can return objects from a function.
Functional programming in Java 8
What is functional programming?

• Pure functions: A function is called pure function if it always


returns the same result for same argument values.

• Lambda expressions: A Lambda expression is an anonymous


method that has mutability at very minimum and it has only a
parameter list and a body.
• Thereturn type is always inferred based on the context. Also,
make a note, Lambda expressions work in parallel with the
functional interface.
Functional programming in Java 8
How to Implement Functional Programming in Java?
Functional programming in Java 8
How to Implement Functional Programming in Java?
Functional programming in Java 8
What is functional programming?
Functional programming in Java 8
How to Implement Functional Programming in Java?
Wherever a single abstract method interface is expected, we can
pass lambda expression very easily:
Functional programming in Java 8
Imperative Vs Declarative Programming:

• Declarative programming is a programming paradigm … that


expresses the logic of a computation without describing its
control flow.
•  The functional style of programming is declarative programming.

• Imperative programming is a programming paradigm that


uses statements that change a program’s state.
Functional programming in Java 8
Imperative Vs Declarative Programming:
Functional programming in Java 8
Imperative Vs Declarative Programming:
Functional programming in Java 8
Understanding Optional in Java 8:
• The main issue this class is intended to tackle is the
infamous NullPointerException that every Java programmer
knows only too well.
• Essentially, this is a wrapper class that contains an optional
value, meaning it can either contain an object or it can simply
be empty.
• Optional comes along with a strong move towards functional
programming in Java 8 and is meant to help in that paradigm,
but definitely also outside of that.
Functional programming in Java 8
Understanding Optional in Java 8:
• The main issue this class is intended to tackle is the
infamous NullPointerException that every Java programmer
knows only too well.
• Essentially, this is a wrapper class that contains an optional
value, meaning it can either contain an object or it can simply
be empty.
• Optional comes along with a strong move towards functional
programming in Java 8 and is meant to help in that paradigm,
but definitely also outside of that.
Functional programming in Java 8
Understanding Optional in Java 8:
Functional programming in Java 8
Understanding Optional in Java 8:
Functional programming in Java 8
Introduction to Streams in Java 8:
• Simply, streams are wrappers around a data source, allowing us
to operate with that data source and making bulk processing
convenient and fast.
• A stream does not store data and, in that sense, is not a data
structure. It also never modifies the underlying data source.

• This functionality – java.util.stream – supports functional-style


operations on streams of elements, such as map-reduce
transformations on collections.
Functional programming in Java 8
Introduction to Streams in Java 8:
• The basic concept behind streams is simple: We got a data
source, perform zero or more intermediate operations, and get
a result.

• Obtaining the stream (source)


• Doing the work (intermediate operations)
• Getting a result (terminal operation)
Functional programming in Java 8
Introduction to Streams in Java 8:
• Java Stream Creation:
Functional programming in Java 8
Introduction to Streams in Java 8:
• Java Stream Operations:
• forEach() loops over the stream elements, calling the
supplied function on each element.
Functional programming in Java 8
Introduction to Streams in Java 8:
• Java Stream Operations:
• map() produces a new stream after applying a function to
each element of the original stream.
Functional programming in Java 8
Introduction to Streams in Java 8:
• Java Stream Operations:
• collect() performs repackaging elements to some data
structures on data elements of the Stream instance.
Functional programming in Java 8
Introduction to Streams in Java 8:
• Java Stream Operations:
• filter() produces a new stream that contains elements of
the original stream that pass a given condition.
Functional programming in Java 8
Introduction to Streams in Java 8:
• Java Stream Operations:
• sorted() this sorts the stream elements based on the
comparator passed we pass into it.
Functional programming in Java 8
Introduction to Streams in Java 8:
• Java Stream Operations:
• min() and max() return the minimum and maximum
element in the stream respectively, based on a comparator.
Functional programming in Java 8
Introduction to Streams in Java 8:
• Java Stream Operations:
• distinct() does not take any argument and returns the
distinct elements in the stream, eliminating duplicates.
Functional programming in Java 8
Introduction to Streams in Java 8:
• Java Stream Operations:
• reduce() takes a sequence of input elements and combines
them into a single summary result by repeated application
of a combining operation.
Functional programming in Java 8
Introduction to Streams in Java 8:
• Java Stream Operations:
• reduce() takes a sequence of input elements and combines
them into a single summary result by repeated application
of a combining operation.
Session 01

New Features in Java 11


New Features in Java 11
New Commercial Features :
• Oracle stopped supporting Java 8 in January 2019.
• Oracle released Java 11 in September 2018
• Oracle JDK 11 release needs commercial license.
• Oracle continues to provide Open JDK releases freely.
Functional programming in Java 8
Some Major Changes in Java 11:
• The deployment stack required for running applets has been removed.
• Auto-update has been removed from JRE in Windows and MacOS.
• JavaFX and Java Mission Control is now available as a separate
download.
• Java language translation for French, German, Italian, Korean,
Portuguese (Brazilian), Spanish, and Swedish is no longer provided.
• Updated packaging format for Windows has changed from tar.gz to .zip
and for macOS has changed from .app to .dmg
• And many other changes …
Functional programming in Java 8
Development Features in Java 11:
1- New String methods:
• isBlank(): Thisis a boolean method. It just returns true when
a string is empty and vice-versa.
• lines(): This
method is to return a collection of strings which
are divided by line terminators.
• repeat(n): Result
is the concatenated string of original string
repeated the number of times in the argument.
• strip(): It
is used to remove the white-spaces which are in-
front and back of the string
Functional programming in Java 8
Development Features in Java 11 :
2- New File Methods:
• writeString():- This is to write some content in a file.

• readString():- This is used to read the contents of a file.

• isSameFile():-This method is used to know whether two paths locate


the same file or not.
Functional programming in Java 8
Development Features in Java 11:
3- TimeUnit Conversion: This method is used to convert the
given time to a unit like DAY, MONTH, YEAR and for time too.
Functional programming in Java 8
Development Features in Java 11:
4- Optional.isEmpty() This method returns true if the value of
any object is null and else returns false.
Functional programming in Java 8
Development Features in Java 11:
5- Local-Variable Syntax for Lambda Parameters: JDK 11
allows ‘var’ to be used in lambda expressions.
Session 01

Unit Testing / Software Testing


Software Testing
Introduction:
Testing is the process of executing a program with the aim of
finding errors.
Principles of Testing:
i) All the test should meet the customer requirements
(ii) Software testing should be performed by a third party
(iii) Exhaustive testing is not possible.
(iv) All the test to be conducted should be planned before
implementing it.
(v) It follows the Pareto rule(80/20) which states that 80% of
errors come from 20% of program components.
(vi) Start testing with small parts and extend it to large parts.
Software Testing
Types of Testing:
• Unit Testing :It focuses on the smallest unit of software design.
In this, we test an individual unit or group of interrelated units.
• It
is often done by the programmer by using sample input and
observing its corresponding outputs.
Software Testing
Types of Testing:
• Integration Testing: is to take unit tested components and build
a program structure that has been dictated by design.
• Integration testing is testing in which a group of components is
combined to produce output.
• Regression Testing :
every time a new module is added leads to
changes in the program.
• Thistype of testing makes sure that the whole component
works properly even after adding components to the complete
program.
Software Testing
Types of Testing:
• Smoke Testing : is done to make sure that software under
testing is ready or stable for further testing.
• It is called a smoke test as the testing an initial pass is done to
check if it did not catch the fire or smoke in the initial switch
on.
Software Testing
Types of Testing:
• Alpha Testing : is a type of validation testing. It is a type
of acceptance testing which is done before the product is
released to customers. It is typically done by QA people.
• Beta Testing : is conducted at one or more customer sites by
the end-user of the software. This version is released for a
limited number of users for testing in a real-time environment.
• System Testing : is tested such that it works fine for the
different operating systems.
Software Testing
Types of Testing:
• Stress
Testing : we give unfavorable conditions to the system
and check how they perform in those conditions.
• Performance Testing: It is designed to test the run-time
performance of software within the context of an integrated
system.
• It
is used to test the speed and effectiveness of the program. It
is also called load testing. In it we check, what is the
performance of the system in the given load.
Software Testing
Types of Testing:
• Stress
Testing : we give unfavorable conditions to the system
and check how they perform in those conditions.
• Performance Testing: It is designed to test the run-time
performance of software within the context of an integrated
system.
• It
is used to test the speed and effectiveness of the program. It
is also called load testing. In it we check, what is the
performance of the system in the given load.
Software Testing
Classes of Testing:
• Manual Testing : Manual testing includes testing a software
manually, i.e., without using any automated tool or any script.
• Testers
use test plans, test cases, or test scenarios to test a
software to ensure the completeness of testing.
• Manual testing also includes exploratory testing, as testers
explore the software to identify errors in it.
Software Testing
Classes of Testing:
• Automation Testing: Automation testing, which is also known
as Test Automation, is when the tester writes scripts and uses
another software to test the product.
• Thisprocess involves automation of a manual process.
Automation Testing is used to re-run the test scenarios that
were performed manually, quickly, and repeatedly.
• Apart from regression testing, automation testing is also used
to test the application from load, performance, and stress point
of view.
Software Testing
Classes of Testing:
• Automation Testing: Automation testing, which is also known
as Test Automation, is when the tester writes scripts and uses
another software to test the product.
• Thisprocess involves automation of a manual process.
Automation Testing is used to re-run the test scenarios that
were performed manually, quickly, and repeatedly.
• Apart from regression testing, automation testing is also used
to test the application from load, performance, and stress point
of view.
Software Testing
JUnit introduction:
• JUnit
is a Regression Testing Framework used by developers to
implement unit testing in Java, and accelerate programming
speed and increase the quality of code.
• JUnit test framework provides the following features:
• Fixtures
• Test suites
• Test runners
• JUnit classes
Software Testing
JUnit introduction:
• Fixtures is a fixed state of a set of objects used as a baseline for
running tests.
• The purpose of a test fixture is to ensure that there is a well-
known and fixed environment in which tests are run so that
results are repeatable.
• setUp() method, which runs before every test invocation.
• tearDown() method, which runs after every test method.
Software Testing
JUnit introduction:
• Fixtures example:
Software Testing
JUnit introduction:
• Fixtures example:
Software Testing
JUnit introduction:
• Test Suites : A test suite bundles a few unit test cases and runs
them together.
• both @RunWith and @Suite annotation are used to run it.
Software Testing
JUnit introduction:
• Test Runners : Test runner is used for executing the test cases.
Software Testing
JUnit introduction:
• JUnit Classes : are important classes, used in writing and
testing JUnits.
• Assert − Contains a set of assert methods.
• TestCase −Contains a test case that defines the fixture to run
multiple tests.
• TestResult − Contains methods to collect the results of
executing a test case.
Software Testing
JUnit introduction:
• Assert methods :
• void assertEquals(boolean expected, boolean actual)
• void assertTrue(boolean condition)
• void assertNotNull(Object object)
• void assertSame(object1, object2)
• void assertArrayEquals(expectedArray, resultArray)
Software Testing
JUnit introduction:
Software Testing
JUnit introduction:
Software Testing
JUnit introduction:
• Annotationsare like meta-tags that you can add to your code,
and apply them to methods or in class.
• These annotations in JUnit provide the following information
about test methods :
• whichmethods are going to run before and after test
methods.
• which methods run before and after all the methods, and.
• which methods or classes will be ignored during the
execution.
Software Testing
JUnit introduction:
• @Test tells JUnit that the public void method to which it is
attached can be run as a test case.
• @Before causes that method to be run before each Test
method.
• @After causes that method to be run after the Test method.
• @Ignore to ignore the test and that test will not be executed.
• @BeforeClass causes it to be run once before any of the test
methods in the class.
• @AfterClass will perform the method after all tests have
finished.
Software Testing
JUnit introduction:
Responsible Name of the document manager
File name Session 01 Java 11, JUnit, Functional programming.pptx
Revisions
R01 Data rev. Farouk Korteby Creation of the document

This document is © 2021 Antea s.r.l.

You might also like