Sunday, October 9, 2016

Class and Interface

Although I want to write full article for a topic in JAVA but today I felt, some times small tips are more important than a full page theory when you want to revise quickly like for an interview ;)

I’m writing here few notes which I have collected while reading Java Books and hope these would be helpful for you too.

Final Classes:
  • String Class can’t be sub classed.
  • Final class obliterates a key benefit of OOP – Extensibility.
  • Final class uses for safety and security.
Abstract Classes:
  • In abstract class, method marked abstract end in a semicolon(;) rather than curly braces.
  • If you change a method from abstract to non-abstract then you need to change the semicolon at the end of the method declaration into a curly braces pair.
Interface:
  • All the interface method must be implemented and must be public and abstract(implicitly it is already done).
  • An interface is an 100% abstract class.
  • But an abstract class can have abstract or non-abstract methods, while an interface can have only abstract methods (this is the difference).
  • All variable defined in an interface must be public , static and final it means interface can declare only constants, not instance variables.
  • Interface methods must not be static as interfaces defines instance methods.
  • You can’t change the value of constant or variable defined in interface from implementing class, it will give compiler error.
Methods of Class Object:
  • Boolean equals(object obj)
  • void finalize()
  • int hashcode()
  • final void notify()
  • final void notifyall()
  • final void wait()
  • String toString()
toString() method:
  • This method simply spit out object state(or in other words) get the current values of the important instance variable.
  • When you pass an object reference to System.out.println() method it will call object.toString() method implicitly.
Hope you liked the tips, I will give move tips in my next post so don’t forget to give your feedback/comments as it motivates me to write more.
C YA BUDDY!!!

Lambda Expression Java 8

After long time I again found my old craze to write on Technical things. So today’s topic is Lambda Expression Java 8 which is very much hyped now a days.
Here are some important points for Lambda Expression:

Lambda Expression Java 8

  • The target type of Lambda Expression is the type of the context in which the Lambda Expression appears.
    For Example: A local variable that it’s assigned to or a method parameter that it’s gets passed into.
  • Although you haven’t declare the variable as final you still can’t use them as non-final variable. If they are to be used in Lambda Expression. If you do use them as a non-final variables, then the compiler will show as error.
  • Lambda Expression capture values not variables.
  • Lambda Expression are statically typed, so lets investigate the types of Lambda Expressions themselves. These types are called Functional interfaces.
  • A functional interface is an interface with a single abstract method that is used as the type of a Lambda Expression.
Important Functional Interfaces in Java
Interface Arguments Return
Predicate T Boolean
Consumer T Void
Function T R
Supplier None T
Unary Operator T T
Binary Operator (T,T) T
  • In the same way that Java 7 allowed to leave out the generic types for a constructor. Java 8 allows to leave out the types for whole parameters of Lambda Expression.
Type Inference:
Javac looks for information close to your Lambda Expression and use this information to figure out what would be correct type. It still typed checked and provide all the safety that you are used to, but you don’t have to state or write the types explicitly. This is called Type Inference.
Okey, today I am trying to approach new fundamentals for technologies and delivering in the form of notes. Feel free to comments or ask questions it will motivate me to indulge more with you ;)


Hadoop Getting Started



Hadoop! Now a days very popular in handling Big data and its analytic implementation.
But before starting Hadoop we must know that why we need it.
  • Facebook generates peta byte of data per day.
  • An aircraft generates 10 tera bytes of data per second.
  • Electricity transmission also generates big data.
  • Trading data or stock exchange also produce large amount of data.
Now question arises…Previously too we had big data then How did we handle it ? Well it was handled by relational database.
But the drawback is, previously only particular set of data was analyzed which were available in the form of rows and columns.
We used Hydrogen Collider instrument which generated petabyte of data for every quantum of power.
As all data comes for example from facebook in log files which don’t have rows and columns that why we called unstructured data and here we need of some other tool like Hadoop.
If we talk data form then it would be divided in part:
  • Volume
  • Velocity
  • Variety
  • Value
That is-                Value = Volume + Velocity + Variety
Now for example if we want to read 1 TB of data by 1 machine which has 4 I/o channels and each channel speed is 100 MB/Second then it will take 45 min to read all data.
While 10 machine takes 4.5 min to read data.
Definition of Hadoop:
Apache Hadoop is a framework that allows for the distributed processing of large data set of across cluster (group) of commodity (normal PC) computers using a simple programming model.
Currently Adhaar Card implementation is bruning example of Hadoop uses in India.

Saturday, October 8, 2016

Quartz Scheduler with Spring 3


Quartz Scheduler with Spring 3:

For achieving scheduled task in spring 3 with the help of Quartz, we need following jars :

Spring 3.0
Quartz 1.8.6

Step 1:

First, add defines quartz details in context file of spring i.e. spring-context.xml as shown below:


<bean id="jobA" class="com.rockmesolid.jobs.JobA" />

<!-- Quartz Job -->
<bean name="JobA" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.rockmesolid.jobs.JobA" />
</bean>

<!-- Cron Trigger, run every 5 seconds -->
<bean id="cronTriggerJobA"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="JobA" />
<property name="cronExpression" value="0/5 * * * * ?" />
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTriggerJobA" />
</list>
</property>
</bean>


As you can see tag defines the bean class for the JobA.

<bean name=”JobA” class=”org.springframework.scheduling.quartz.JobDetailBean”>


It says Quartz bean class which will work with JobA class of property name=”jobClass”.
Next step is to set CronTriggerBean which has property of cronExpression


<property name=”cronExpression” value=”0/5 * * * * ?” />


Here “0/5 * * * * ?” defines CronTrigger will hit JobA class at every 5 Second.
If you want to hit it at a particular time on everyday like 10:13 pm everyday then cronExpression would be like “*10 13 * ? *”


<bean class=”org.springframework.scheduling.quartz.SchedulerFactoryBean”>

 

This set a reference bean name as cronTriggerJobA for Quartz SchedulerFactory.

Step 2:
Now definition of JobA is:


package com.rockmesolid.jobs;

import org.quartz.JobExecutionContext;

import org.quartz.JobExecutionException;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.scheduling.quartz.QuartzJobBean;

import org.springframework.web.context.support.SpringBeanAutowiringSupport;

public class JobA extends QuartzJobBean {

@Override

protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {

SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); // for calling or inject bean of current context of application

System.out.println("Job A is runing");

try {

// to perform some actions

} catch (Exception e) {

e.printStackTrace();

}

}

}


Here as we can see JobA extends QuartzJobBean for calling executeInternal method which passes JobExecutionContext as an argument.
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); is the most important line to call or inject bean of current context of application into the JobA class. After this line you can use any of your application bean class into JobA class and perform any action like business logic, db connection etc.
Hope it will help. Really it’s easy.

Why We don’t turn Entrepreneurs !!!

This article is nicely written by one of my buddy Arun Sharma , who has very energetic and dynamic personality.  He shared his wondering thoughts with me for making me known of life’s purpose and obstacles coming.
Although this article is for middle class family background guy/gal but after reading it I realized every person faces these kinds of problems somewhere in Life. So thought to share with our Rockers, and get some precious feedback/comments/advise on it:
I have been a part of a regular middle class family and have even thought of starting something of your own, am sure you’d associate with the headline itself!
I don’t intend to hurt anyone here, still if you did, sorry about it! Getting to the points, straightaway!

Marriage:
About a year back one of my very close friends told me about a product idea. I liked the idea and told him I could work with him on that if he’s willing to seriously build it. His answer was – “yaar abhi job nahi chhod sakta, 6 mahine mein shaadi hai” [Dude, I can’t quit job right now, getting married in 6 months]. Okay, get married but why do you want give up on an idea you believe in? Your girl will understand, won’t she?
Guess what? Obviously, he never build it and few months back I saw someone roll exactly that product out and is quite close to getting funded too! Yeah, my friend’s “happily married”, barely at 26!

Oh! And that concept of getting your kids married at the right age => guys before 28 and gals by 24-25 max! I’ve always stressed, there’s nothing called such as a “right age” – why not just get married when you are ready – 25 or 32 – how does it matter? I hope you’re not thinking about that old shit about retiring and then marrying your kids before that <- actually="" i="" is="" problem="" root="" that="" the="">
Family:
Sorry to say, but the uncles and the aunts in our (normal middle class) families are the worst. They will keep asking your salary, some of them every single month. These relatives are probably the ones whose kids would have done “nothing” in their lives, graduated from some (worthless) A league institution in India and landed a fat paying job. And believe me these are absolutely good for nothing folks. If you are a startup guy, you already know that, don’t you... They would join a company through campus placement and would be too scared that they would spend their entire life within that single organization – without even doing something innovative! These uncles would be happy to show the entire family that the ad in TOI today was done by their kid while all that ad would have is a bollywood diva holding a soap bar in her hand. THAT’S IT!?! That’s all you learnt in your fancy Tech/B School?

To share another case, one such highly respected family member told me to look for a career in animation, back in 2006-07. Recently, I met him at another family gathering a few months back and he said “tum animation me kuch kyu nahi try karte?” [Why don’t you try something in animation?] I was like…dude? You are still the same! Your thoughts are still stuck where they were 4-5 years back! By the way, this member is probably the highest respected person in my family and heads delivery at a multimillion business and travels abroad every month. Yeah, (sadly) that’s what puts the stamp on his authority!
Am quite sure even Steve Jobs or Bill Gates would have spent more time with their families at his age (and still earned much more if that’s what you want to hear).
Flat:
The other fantasy about middle class family people owns a flat! I never get this point. I, really don’t! Why do they want your kid to buy a flat and then spend the rest of his life paying back the loan? Coming from middle class, we’ve never had loads of money to spend. So the way out always is to pay probably a 10% or even less initially and then take a loan for 60% for the next 15-20 years.
And is duly supported by our financial system! Go and try to raise money for your startup and the same money for a home, you’ll know what I mean!

Once you have a loan on your head, that too a home loan, for not less than 40-50 Lacs, am sure you wouldn’t be willing to take a risk, would you? And that tension of repaying that loan! Anyways, there is very little probability that our kids would stay in that house for long. They’d go places, do stuff in life and make it big themselves!
I realized most people, even though agreed to this, say it’s inconclusive.
I must add this: The point is that people, who can bear all these pressures and can still achieve one goal of their heart, are the ones whom we call SUCCESSFUL!

Thanks… “
Where are your going , not finished yet …please share your thoughts/comments after all IT’S OUR LIFE & LIFE HAS NO CTRL+Z.