Nitin Agrawal
Contact -
  • Home
  • Interviews
    • InterviewFacts
    • Resume Thoughts
    • Companies >
      • InvestmentBanks >
        • ECS
        • Bank Of America
        • WesternUnion
        • WellsFargo
      • ProductBasedCompanies >
        • CA Technologies
        • Model N India
        • Verizon Media
        • Oracle & GoJek
        • IVY Computec
        • Samsung
        • ClearWaterAnalytics
        • ADP
        • ServiceNow
        • Pubmatic
        • Expedia
        • Amphora
        • CDK Global
        • Delphix
        • Fractal Enterprises LLP
        • CDK Global
        • Tide-Banking
        • Epic
        • Sincro-Pune
      • ServiceBasedCompanies >
        • Altimetrik
        • ASG World Wide Pvt Ltd
        • Paraxel International & Pramati Technologies Pvt Ltd
        • MitraTech
        • Intelizest Coding Round
        • ZeMoSo
    • Interviews Theory
  • Programming Languages
    • Java Script >
      • Tutorials
      • Code Snippets
    • Reactive Programming >
      • Code Snippets
    • R
    • DataStructures >
      • LeetCode Problems
      • AnagramsSet
    • Core Java >
      • Codility
      • Java14
      • Threading >
        • ThreadsOrder
        • ProducerConsumer
        • Finalizer
        • RaceCondition
        • Executors
      • Important Points
      • Immutability
      • Dictionary
      • Sample Code Part 1 >
        • PatternLength
        • Serialization >
          • Kryo2
          • JAXB/XSD
          • XStream
        • MongoDB
        • New methods in Collections
        • MethodReferences
        • Complex Objects Comparator >
          • Performance
        • NIO >
          • NIO 2nd Sample
        • Date Converter
        • Minimum cost path
        • Find File
      • URL Validator
    • Julia
    • Python >
      • Decorators
      • String Formatting
      • Generators_Threads
      • JustLikeThat
    • Go >
      • Tutorial
      • CodeSnippet
      • Go Routine_Channel
      • Suggestions
    • Methodologies & Design Patterns >
      • Design Principles
      • Design Patterns >
        • Decorator
        • Proxy
        • Lazy Initialization
        • CombinatorPattern
        • RequestChaining
        • Singleton >
          • Singletons
  • Frameworks
    • AngularJS
    • Apache Velocity
    • Spring >
      • Spring Boot >
        • Issues
      • Quick View
    • Rest WebServices >
      • Interviews
      • Swagger
    • Cloudera BigData >
      • Ques_Ans
      • Hive
      • Apache Spark >
        • ApacheSpark Installation
        • SparkCode
        • Sample1
        • DataFrames
        • RDDs
        • SparkStreaming
        • SparkFiles
    • Integration >
      • Apache Camel
    • Testing Frameworks >
      • JUnit >
        • JUnit Runners
      • EasyMock
      • Mockito >
        • Page 2
      • TestNG
    • Blockchain >
      • Ethereum Smart Contract
      • Blockchain Java Example
    • Microservices >
      • Design Patterns
    • AWS >
      • Honeycode
  • Databases
    • Oracle >
      • Interview1
      • SQL Queries
    • Elastic Search >
      • StudySources
  • Random issues
    • TOAD issue
    • Architect's suggestions
  • Your Views

Java9 hacks, tips & tricks

Here I will be sharing any useful information I get around Java9.
Java9 is not new one anymore but still we are yet pending to change our mindsets to think in functional way since Java8.
People/recruiters are still not ready to accept that their 90% work force is still living in OOP world. And believe it or not, this thought process change is required at the organisation level & if you don't set your priorities correct & don't understand your requirements properly then in next few months you will be sitting on the pile of mess of yours only.

https://www.baeldung.com/java-9-modularity

Well, during checking reactive APIs/streams, I was trying to use reactivex API, a 3rd party API to check one example.
But since Java9 being a modular one, I was not getting the way to use the 3rd party API.
So I searched on Google & I got the below answer on - stackoverflow
And the same solution can be used to include other 3rd party APIs.
Use the command on command prompt for the library you want to include & like shown in below images also -
jar --file reactive-streams-1.0.2.jar --describe-module
Picture
Now you need to include the name in the like having 'automatic' in above output for any library you want to use. like shown below. Include this in '​module-info.java' of your Java9 project, to make this library available to your code.
Picture
If you have watched above video or knows about the new features in Java9, then you know that you can create you own lightweight JRE to execute your code rather carrying the whole default JRE.
For this jlink is provide from java9, but for this you need to follow some steps first like show below.
I have project which requires another module, so either assume it or you can create such project.
Now -
First we need to compile module-info.java & copy the jar file of the required module at one place & refer that path via -p & I have put this jar at the same place so using '.' -
                                                         javac -p . -d e:\out module-info.java
Second, we need to compile the java files so that required modules are available like in above step -
                                                         javac -p . -d e:\out test\Testing.java
Third & final step, we need to generate the custom JRE required to execute our application, so we need to make sure all the required modules are available in our custom JRE. Use command like as shown below -
              
                     jlink --module-path "%JAVA_HOME%\jmods\java.base.jmod";e:\out;. --add-modules check --output e:\out\customJRE

Note : I have used j.base.jmod only from java as I will need only that module only to run my class, you can just mention a list of modules separated by ';' like I did above to include my module from e:\out
   --add-modules give the name of the module for your application, like I have 'check'
   --output, using this give the path where you want to generate your JRE, like I did for customJRE
So your JRE will be generated at the given path which will be having all the required dependencies to execute your application. Though it reduces the size of JRE but still I didn't see the excpected size reduction, as JRE is still bulky.
But anyhow you can try try this way. In case of issues follow online docs or let me know the issue.

Be cautious about using 'Transitive' dependency in Java modules, as you can be on some slippery slope towards many modules.
98 modules are made from that single rt.jar

Powered by Create your own unique website with customizable templates.