Posts

Showing posts from May, 2017

Context Reuse : Pass the executable code as Parameter to methods : JAVA 8

Context Reuse  Context reuse is a special kind of code reusability. Context reuse is the reuse of Set of Instructions while various different actions take place in between. Following are the steps to understand context reuse: Before Block  ( Fixed set of Instruction) Your action or code you want to execute After Block  (fixed set of instruction) Consider the Scenario: Two different methods want to use inputStream :  Method 1: write the InputStream to stdout Method 2: read the input stream to String and return the Object. See the implementation public void printStream(InputStream inputStream) throws IOException { if(inputStream == null) return; IOException exception = null; try{ int character = inputStream.read(); while(character != -1){ System.out.print((char) character); character = inputStream.read(); } } finally { try{ inputStr...