Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java

Literals/Constants

Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

Jdk1.8 new Features
Previous Home Next

Java 8 was released on 18 March 2014. The code name culture is dropped with Java 8 and so no official code name going forward from Java 8.

  1. Lambda Expressions
  2. Pipelines and Streams
  3. Date and Time API
  4. Default Methods
  5. Type Annotations
  6. Nashhorn JavaScript Engine
  7. Concurrent Accumulators
  8. Parallel operations
  9. PermGen Error Removed
  10. TLS SNI

Lambdas: Lambdas bring anonymous function types in Java (JSR 335): (parameters) -> {body}

Example

(x,y) -> x + y

Lambdas: Lambdas bring anonymous function types in Java (parameters) -> {body}

Example

(x,y) -> x + y well Groovy (a superset of java) already provides this

Lambdas: Lambdas can be used in place of functional interfaces (interfaces with just one method such as Runnable)

Example

new Thread(new Runnable() { 
@Override public void run() {
System.out.println("It runs !");
}
} 
start(); 
new Thread(() -> { System.out.println("It runs !"); } ).start();

Lambdas:

Examples of such functional interfaces:

java.lang.Runnable -> run()
java.util.concurrent.Callable -> call()
java.security.PrivilegedAction -> run()
java.util.Comparator -> compare(T o1, T o2) 
java.awt.event.ActionListener ->
actionPerformed (ActionEvent e)
java.lang.Iterable -> forEach(Consumer<? super T> action)

Lambdas java.lang.Iterable -> forEach(Consumer<? super T> action) ?!? Isn't this breaking backward compatibility ?!?

Lambdas java.lang.Iterable -> forEach(Consumer<? super T> action) ?!? Isn't this breaking compatibility ?!? No - because forEach is an extension method.

Lambdas Extension methods provide a mechanism for extending an existing interface without breaking backward compatibility.

public interface Iterable<T> { 
	default void forEach(Consumer<? super T> action)
	{
		Objects.requireNonNull(action);
		for (T t : this) { action.accept(t); } } }

Lambdas: This essentially means that lambdas can be used to replace all functional interfaces used in a gazillion of libraries

Moreover lambdas increase performance when used instead of anonymous inner classes because they are implemented with the invokedynamic instruction

In this regard many of the standard JDK class are being refactored to use lambdas

Lambdas Additional functional interfaces are provided by the java.util.function package for use by lambdas such as: o Predicate<T> - one method with param of type T and boolean return type o Consumer<T> - one method with param T and no return type o Function<T, R> - one method with param T and return type R o Supplier<T> - one method with no params and return type T

Stream API: Databases and other programming languages allow us to specify aggregate operations explicitly

The streams API provides this mechanism in the Java platform

The notion of streams is derived from functional programming languages

Stream API : The stream API makes use of lambdas and extension methods

Streams can be applied on collections, arrays, IO streams and generator functions

Stream API: Streams can be finite or infinite

Streams can apply intermediate functions on the data that produce another stream (e.g. map, reduce)

Stream API:

java.util.stream.Stream<T>
collection.stream(); 
java.util.stream.Stream<T> 
collection.parallelStream(); 
Useful methods: o filter(Predicate), map(Function), 
reduce(BinaryOperator), collect() o sum()
, min(), max(), count() o anyMatch(), 
allMatch(), forEach(),

Stream internals int sum = widgets.stream() .filter(w -> w.getColor() == RED) .mapToInt(w -> w.getWeight()) .sum(); Stream operations are composed into a pipeline Streams are lazy: computation is performed when the terminal operation is invoked

Method references : Intended to be used in lambda expressions, preventing unnecessary boilerplate

Example: books.stream().map(b -> b.getTitle())  books.stream().map(Book::getTitle) Lambda parameter list and return type must match the signature of the method

Method references: static methods public class Printers

{ 
	public static void print(String s) {...} 
	} 
	Arrays.asList("a", "b", "c").forEach(Printers::print)

Method references :instance methods (1) public class Document

 {
	 public String getPageContent(int pageNumber) 
	 {
		 return this.pages.get(pageNumber).getContent();
} }
public static void printPages(Document doc, int[] pageNumbers)
{ 
	Arrays.stream(pageNumbers) .map(doc::getPageContent) .forEach(Printers::print);
	}

Method references : instance methods (2)

public class Document {
	public String getPageContent(int pageNumber) {
		return this.pages.get(pageNumber).getContent();
		} }
		public static void printDocuments(List<Page> pages) {
			pages.stream() .map(Page::getContent) .forEach(Printers::print);
			}

Method references: constructors public static Stream<Page> createPagesFrom(Stream<String> contents) { return contents.map(Page::new). }

Previous Home Next