Saturday 2 June 2018

Living is like Coding

Our Life is also just like our #codes.
1) You miss your base conditions(exercise and hygiene) , one day your code (life) will throw a null pointer exception or will show a very abrupt behavior (Medical Issues).

2) You run into an infinite loop (thinking about past) , your code will get stuck their forever and will surely show a StackOverFlow error ( you will go into depression)

3) You don't debug ( act without thinking or dont check your word) your code is going to fail and is not going to meet your client's expectation ( is going to hurt your near and dear one's).

4) If your code's complexity ( attitude) is bad or average , it will not be liked much. Less people will favor it.

5) And If you give up on your coding (life) , then ultimately you are going to lose your job (You will lose your happiness) .

So ,
while( (--LIFE) > 0) {
StayHappy();
SpreadHappiness();
CarryPositiveAttitude();
AlwaysHaveHope();
FightForYourDreams();
LoveLaughLive();
LoveEveryone();
ValueRelations();
NeverGiveUp();
ThinkThenAct();
GiveTimeToNearDearOnes();
MakeFriends();
ShareMemory();
CareForEachOther();
KnowImportanceOfFamily();
AndAlwayLoveYourSelf();
}

A very neat and clean code for living life.

Facade Design Pattern

Facade Design Pattern ??
Lets understand this in very layman language.

Suppose you are very lazy . You have to open lights of a room , television , ac , oven and etc. 
What you can do is that you can
1)First get up switch on the light.
2)Then switch on the tv , look for the remote open it.
3)Go to your kitchen switch on your oven.
4)Search for ac remote and then you have to press the button.

That means you have to do the task in 4 steps. But as I said you are lazy ,  you don't like these many steps . So you go out in a market and purchase a 'MAGICAL REMOTE'.

Now , the purpose of this remote is that , once you press on button of this remote , your ac , tv , lights , oven etc. is switched on automatically. 
You did not take above mentioned 4 steps . Just one click and your work is done.

This is basically how Facade pattern works.

Take example of goibibo or makemytrip.

You book a package and you just select a package and on the backend 
1) your flight
2) hotels rooms
3) cabs
4) tourist spots

All are booked by clicking on the package. This is facade pattern.

References :
http://techytuts.in/facade-design-pattern-with-real-world-example-booking-system/

Keep Learning , Keep Growing and Keep Reading.

Thanks alot.

-Anurag Srivastava

Sunday 1 April 2018

Testing is an Art

Introduction

Imagine one day there is a guest who is about to come at your home for dinner.

You cooked the dinner and you did not taste it or check it whether it is tasty or not and when your guest arrives at your home , you serve him the food.

The food taste was bad and salt was too much in the food , the guest was not able to finish the food and he felt bad about the food which you served him. And he went back to his home angrily.
Next time if you call him to your house he won't be pleased to come.

Same was goes the testing, if you provide your client with a product which developed properly but testing was not done nicely , your client will also become unhappy and will be angry with you or even can sue you for this.

So, comes the big question What is testing ,How it is done and How to approach a testing problem?

What is Testing?

To be very honest , Testing is an art and Tester is an artist or you can say finding bugs in an is a magic and Tester who finds it is a magician.

Testing is very important part of any kind of development of product be it software , hardware or anything.
eg. You need to test your app before uploading on playstore.
      You need to test the building walls when the construction is taking place and also when it is done.
      You need to test the medicines and injections before giving it to the patient.

All of the above mentioned things can fails and result to abnormality if the testing is not done properly.

How Testing is done?

There are multiple ways of doing testing  which ranges from manual to automated , black box to white box testing.


1)Manual Testing or Black Box testing : 

Just testing something for its functionality is called Manual testing where you don't check the logic or anything , you just check whether the functional behaviour or output of the testing product is correct or not.
Suppose you have to test a product in which when you give that product any image , it transforms it into black and white image.

The manual test case for such a product will be just you are giving it an image manually and checking whether obtained image is black and white  or not.

If it is then this test case is passed else this test case will fail,

2)Automation testing : 

Just automating the test cases where manual effort required is very less , where you can write some test scripts  which will run and perform the test cases.
Now for the above mentioned product , you write some scripts which by itself takes the image from a folder and uploads and somehow check for the grey-scale content will be automation script for it.

Tools/Technologies for doing automation testing : 
a)Appium
b)UI Automator
c)Selenium and etc.

3)Unit Testing or White Box testing : 

Testing something on code level is called White box testing where you  check the logic.
The tester has the knowledge of the internals of a system and knows how the system is implemented. The tester uses this knowledge to develop test cases that will examine the control flow, information flow, data flow, exception and error handling as well as coding practices of the system.
The unit test case for the above product can be , checking for the functions at the code level whether it is returning correct value or not.

eg. For doing calculator unit testing you will send 2+2 to function and check whether the function is returning 4 or not.

How to approach a testing problem?

Many a times in interview or in general discussion you could be ask how will you test Product X then how will you tell or how you should proceed.

It is quite simple go step by step.
Like if I say you have to give a feedback or you have to test a food , then what will you do ?
I guess you will do following ?
1)Check for the look.
2)Check for the smell.
3)Check for the oil quantity.
4)Check for taste.
5)Check whether it is hot or cold etc.

Same way you can approach a testing question of any product.

Every Product comprises of following properties :
1)U.I. or look
2)Functionality
3)Reliability
4)Performance(stress , boundary value analysis)

You have to classify your product on the basis of above mentioned 5 points and you can write test cases.

Below I am providing you one example .

Test cases for Bluetooth speaker (eg. JBL)

1)UI or look
a)Check whether JBL is printed on it or not and there should be no spelling mistake.
b)Check whether the name on scratching does not go away.
c)Check whether the color lets say black if proper or not.
d)There should be no stain on the speaker
e)Check for the shape whether it is of black color or not.

2)Functionality
a)Check whether is getting easily connected with device or laptop or not.
b)Check whether the song is played nicely or not
c)Check whether there is no sync issue.
d)Check whether it is easily getting disconnected or not.
e)Check whether on clicking next button pause button play button all are working or not.
f)Check whether you can receive call and whether the call is successful not.
g)Check whether it can get connected to multiple devices or not.

3)Reliability
a)Check whether the material used in it is harmful or not.
b)Check whether it does not have sharp edges.
c)Check whether it does not get short circuit.

4)Performance
a)Stress/Negative test case
i)Keep on changing the tracks or continuous click on next and check whether song displayed on phone and played on the speaker is same or not.
ii)Keep on connecting and disconnecting and check whether it is behaving properly or not.
iii)Take it to a very hot temperature  and check whether it does not melt.
iv)Make it fall from small height and check whether it does not fail.

b)Boundary value
i)Check for the range in which it is played , take to the edge and check whether it is working or not or it is not working in within range also.
ii)Check for the mentioned duration that whether on full charging speaker if working for that many time or not.
iii)Check whether on keeping idle in how many time it turns off.



Above is just few testing steps for Bluetooth speaker , it can be many more as Testing is a never ending process.

You can think of your own.

But one thing I can guarantee you that if you classify your products properly then you can write its test cases very well and this can help you in any discussion or interview just go step by step.

NOTE :

As I told you Testing is a never ending process so you can classify your product in many more parts , not only in above mentioned parts.

The above mentioned parts were just for your understanding.

That's it for today guys . Hope you liked it.
Please let me know if anything is wrong , missing or not clear.

Next time I will be covering types of testing and few more test cases for few more products that can help you.

Keep reading.
Keep learning.

Thanks a lot for reading.
Stay Connected.

-Anurag Srivastava

Monday 5 March 2018

Java can be mischievous

Umm all JAVA lover would have come to a point where they would have found some crazy stuffs in JAVA.

This article covers few of them. Let's start point by point.

1)Ever heard 2+2=5 ??

  Well Java can defy simple mathematics. What we have been taught at school can be easily faked by     java.
   Yes with the help of  Java you can indeed prove 2+2=5.
   But how ?
   Well the ans is simple with the help of Reflection (most of the mischievous things in Java are             basically done by Reflection).

   Let's look up the code for it .?

  import java.lang.reflect.Field;


  public class ByteEg {

public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub

  Class cache = Integer.class.getDeclaredClasses()[0];
        Field c = cache.getDeclaredField("cache");
        c.setAccessible(true);
        Integer[] array = (Integer[]) c.get(cache);
        array[132] = array[133];

        System.out.printf("%d",2 + 2);

}

  }

   What happened actually?
  "array[132] = array[133]" , this is the most important line. This is where magic happens.
   First understand cache concept in java . In java for int , a cache array is created from value -128 to    127.

  This means cache[0]=-128 ,  cache[1]=-127 ... ... ......cache[128]=0

  Thus , cache[132] is actually int 4. And what we are doing here cache[132]=cache[133].
  This means the value 4 which is at 132 is replaced by value which is at  index 133 (i.e. 5).

  Thus if we wanted to prove 3+3 = 8;
  We have to change cache value of 6 and set it to 8.
   cache index for 6 is 134.
   array[134] = array[136]
 
   This will give result as 8.

   A generic code will be something like this.
   int sum=num1+num2;
   array[132+sum]=array[132+sum+shift]

  eg, 2+2=6 , here sum is 4 and shift is (6-4)=2
*******************************************************************************

2)Does X/0 in java always give Divide by zero exception??

   Well if your answer is Yes for this question , then my dear friend you got it wrong .
 
   Try something like this in java
   System.out.println(5/0.0)
   
   For the above case there will be no runtime exception . You will get a proper output.

    And the output is "Infinity" printed on console.
    
    In case of double value java has a predefined value as Infinity.

  Also you can try ,
   System.out.println(0/0.0)

  The output will be "NaN"  
*********************************************************************************

3)Comments that can actually execute :


   This can be shocking as many will be thinking how on Earth this can happen that comment can           execute.

  For those people I have an example here ?
  
  public class Testing {
    public static void main(String[] args)
     {
         // the line below this gives an output
         // \u000d System.out.println("comment executed");
      }
  }

 Output for the above example 
  comment executed.

 Actually what happen here is that, the above code got changed into 
 public class Testing {
    public static void main(String[] args)
    {
        // the line below this gives an output
        // \u000d
        System.out.println("comment executed");
    }
}

The reason for this is that the Java compiler parses the unicode character \u000d as a new line and gets transformed into above code.

*************************************************************************************************************

Hope you would have learn new things. In future I will share more on Java interesting facts.

Till then you can try to solve the following questions?

1) int a=5;
     if(a<10||a/0==0)
     {
     System.out.println("Hi");
    }
    else
    {
    System.out.println("Hello");
    }

a)Hi
b)Hello
c)Runtime Exception
d)None of these

*********************************************************************************

2)  if(a>10&&a/0==0)
     {
     System.out.println("Hi");
    }
    else
    {
    System.out.println("Hello");
    }

a)Hi
b)Hello
c)Runtime Exception
d)None of these

*****************************************************************************

3) class A
     {
    private void function()
    {
   System.out.println("Inside A");
    }
   }

  class B extends A
{
protected void function()
{
System.out.println("Inside B");
}
}

class C
{
public static void main(String args[])
{
A ob = new B();
ob.function();
}
}

Predict what will happen on running the above code and why ?

*******************************************************************************

Thanks a lot for reading.
Stay Connected.



Monday 20 June 2016

Is Rape Only Physical..?

                  "No one dies virgin.. Life will fuck you one day for sure.!"
               
                 I read this quotation for the first time, when I was in class 10 but I was not able to understand the depth of this quote.. I was like "how can life fuck somebody.?"..But as I started growing up , I understood the vivid meaning of those words.
               

                So my question for all of you is simple.. "Did you get fuck by life..? or Have you ever been raped irrespective of your gender.? ".. I say "yes" you must be.
     
            You would have got confused that what shit I am writing and who am I to tell whether you are raped or not.  But for me each and every person here on this earth has been raped. So, the big question is "Is rape only physical..??" ..Cant you be raped mentally or psychologically..

                   According to wiki "Rape is a type of sexual assault against a person without his/her consent". The what does mental rape means?. "It must be mental assault  against a person by force or by torture"

                 I used to have a friend name Vicky Saxena whose father is a well known doctor at my home place. Vicky was a smart programmer and good at maths. We both used to compete each other in coding. His father always wanted  him to be a doctor so that he could take over his place and his clinic. (Selfish father i guess or was he right??). In class 10 vicky score 96 in cse and 75 in science with a 'C' grade in Biology. When he was to select his subjects for class 11 he was excited to take computer and maths. But soon his excitement went in vain as his dad asked him forcefully to take biology by scolding and the poor fella couldn't argue..
                 There we go in class 12 same boy score 63% with and being the son of richie rich dad, he got admission in a medical college through a whopping donation of 35 lacs.(I would have got an audi a4 car with those bucks).  And there I see  my old competitor Vicky ,  a boy who got an year back in 2 year, and struggling in the third year. A bright coder who has become a DRUG, SMOKE,ALCOHOL and S** addict . I know choosing this path screwing his career was his complete fault,, but "was it really only his fault??" What if currently he had been a great coder or placed in a reputed company."
But this could only be possible  in DAYS OF FUTURE PAST. He got screwed , he screwed and got fu***d by life and he was the victim of MENTAL RAPE..

              I have also heard about a girl name Neha Agarwal ,  a promising bright student. She used to be topper of her class , three years senior to me. She belonged to a very orthodox family where son is all and daughter is a SCAR. Being the topper of class she  was not send away from her hometown for her medical studies  , she was send for  bsc in a local college at her native place. She kept begging his dad and family to allow her to give exams or to fill various forms but here also ll went in vain.
              As her dad said , "You going to part of some other family so what is the need of studying these subjects and we have to spend a lot in your marriage so we don't have that much money".
           All she could do was cry. At the age of 21 she started teaching and started enjoying it as well earning 12000. But , she was unaware of the NIGHTMARE which was about to come. For her family she seemed to be of 41 years not 21 years so at the age of 22 she had to marry forcefully a boy eight years older than her , a govt. employee .
                                                            She could not fight again because "when your family is against you , people lose all the courage they have , they are bound to be in tears only." That bright girl became mother at the age of 23 (same age on which might be you are reading this post and thinking , I wont marry before 28 or 30 etc) . The age at which she should have earn or studied or played games with her friends , she had to play different kind of games with her husband.
                                                            So what was it ?? Again a mental rape , a torture , rope of dreams and career . Can you feel the pain the girl would have felt knowing that his father wasted lacs of money in her marriage or in his sons revelry.  How many times she would have thought about committing a suicide . She must have become dead from inside till now , a tragic end for a beautiful soul.

                          You will see cases of mental rape everywhere. At schools when teacher discriminating between the weak and topper students . When the weak student would have got an impression that he is good for nothing and one day he does become good for nothing. The reason was that though which was forcefully inserted in his brain while he was scolded by his mom/dad or teacher that he is good for nothing.

                           A lover using the love of his life or I should rather say time pass of his life after getting the job done , breaking all his promises . A girl leaving a boy for another richie rich boy and this cycle continues . What is all this ? You always feeling inferior about yourself , complaining about yourself , taking yourself as a zero loser ..What is all this? This is only MENTAL RAPE my friend , this is only.  I hope you must have understood what it is.

                           Now a days rarely people are seen supporting the dream of other even if it is a vague one. Rarely a teacher talks politely to a weak student that "yes my dear you can also do it, you can also become topper" rather punishing him. Rarely a family is seen who is supporting his daughter against the society . Rarely  a family allows his son/daughter to be what he wants not what they or the society wants. .!!
                     
                         What should a person do actually if he is about to be mentally raped..??? REBEL , FIGHT BACK, NEVER GIVE UP .. even if he/she  has to argue with the one's whom he/she love he should be ready to do that. Because , few dreams are ours , few wishes are ours which requires only our permission , nobodies else.
                        And one day by achieving what he/she desired he proves to everyone that he/she was right. He was not wrong in this fight. You will become hopeless shattered if your family is not with you but don't end yourself , don't end your fight.. keep fighting until YOU BECOME THAT VERY YOU WHOM YOU SEE WHEN YOU CLOSE YOUR EYES AND YOU SMILE..AND YOU GET GOOSEBUMPS..

                         Ek bachcha kya chahta hai..
                         Ek bachcha toh gharwalo ka sath chahta hai..
                         Bheed me wo unka hath maangta hai..
                         Wo hath na mile to wo haar jata hai.
                         par,
                         Usey haarna nahi hai, use to ladna hai..
                         Apne sapno ke liye.
                         Use to udna hai, ek pankchi k jaise..
                         Apne sapno ko paane k lie use kuch kar jana hai..
                         Apne pas apni khushiyan use toh le kar aana hai..
                         Toh usey to ladna hoga..
                         Chahe kisi ka hath mile na mile..
                         Usey toh chalna hoga.
                         Usey toh ladna hoga.

Thanks for reading it. Hope you liked it.

Keep Smiling,
Keep Living,
Keep Rocking

Be a Rebel.

Anurag Srivastava

                                       

Thursday 12 May 2016

Love , Family , Society and Sacrifice

                            
         
One of my friend asked me.. "Bro ! what's the toughest thing here in India..Do you have any clue about it.?" The question brought a smirky expression on my face and I was ready to answer him..
So my answer was "Yes bro..! I know the answer..There are only two things which are toughest here in India .. first one is getting your desired job(naukri) and the second one is marrying your love (chokri).".. Naukri mein company wale lete hain aur chokri me gharwale , dost, society sab lete hain ..

                       Let me tell you this with a real life story. The story is about a boy and girl focussing more on the girl. Basically I will make you understand the third problem also which lies here.. (the problem which the girl faces being a girl.)
                        The boy named Raghav and the girl named Suhani both belonged to the same college. Raghav was from a middle class family who was free minded and independent . Suhani belonged to above average family who was dependent and a bit scared of her family..
            "They say that we walk on different paths but one day our path do collide with someone, one day you do cross someone's path , that's the day you fall in love." Same thing happened with them their road crossed each other one day in mechanical lab being the part of same group, they  became friends and exchanged their contact.
                                                                     Suhani was good at study and was among the toppers of the class while Raghav was mediocre at study and was interested more in singing and was the best singer of college. Suhani , as we know girls are caring, cared a lot about Raghav. She used to teach him what was taught in class and always gave lectures to him on his carefree and careless approach  towards thing's. Raghav could not resist that care and affection from Suhani (That's the problem with the boys they can not resist the care and attention of girl whom he admires aur wo ladka clean bowled ho gaya).
                                 So, he fell in love with her.  And was scared abut the outcome that will she accept or not or does she love him , is he good for her... (All the shits started to come in his mind which actually comes in a one sided lover's mind, not his fault kyuki thoda fattu ho jate hai wo) . He decided to propose her with the best thing he has , i.e. , his singing. It was the college fest night when he sang a song on the stage with lines as .. "Shaam ka Aanchal odh k aayi.. dekho wo raat SUHAANI.. aa likh de hum dono mil ke apni yeh prem kahani.. " with a line saying " I love you Suhani at the end ".
                           There was the girl standing in crowd with her eyes full of tears and did not expected the one who she loves proposing her that too in front of everyone..  This is how their story started .
(A sweet one I guess, well love stories are sweet.) .
                          They both were too much serious on each other with all kinds of future plans staring from the day of their wedding to the name of their babies  and ending on dieing in each others arm. (Har ek laila majnu ki yahi kahani hai .. but inki thodi si alag thi. ) . They do talked about their career.  They both were full of energy and wanted to do something big for themselves and for each other.
The girl wanted to do mba from i.i.m and the boy wanted to get a job , earn some money and become a singer. They both were living their life full of love and happiness without caring about this world ( logo se anjaan ghar walo se anjaan , befikre wo bas chalte ja re the apni duniya mein..kya pata tha unhe ki kabhi rukna bhi padega ki kabhi bahar aana bhi padega ) .
                       And then they were about to see the reality. It was final year of college and the college placement started . The girl was placed in a good company being the topper but the boy could not make to that company and he got placed in a company which was not that much good.  And in which he could not fulfill his dreams . The boy was broken and sad . Seeing him the girl was sad too.. But this was just the start of the havoc which was about to come.
                           One day girl was called by her parents and was asked to come urgently . She tried to convince them for not coming as she wanted to be with Raghav in this tough phase , but they did not allow and she had to leave . She left  next day for her home hugging him  tightly and kissing him on cheeks.
           Then started the cruel journey of the girl about which she had no clue. As she went at home , she was asked by her family to wear good clothes and was just said "Tumhe dekhne log aa re hain.. " .. She could not understand what did it mean , so she asked her mom "what is this all about?" ..
Then her mom told her that she is getting 24  this year and that is the age she should get marry , else after this she won't get a good boy and the boy which will come to see is very rich and at very good post.
        The girl started crying telling her mom and dad that she is not ready for this marriage and she wants to do mba and also she loves a boy . Her parents were in shock as if she had commited a sin by loving . Her dad said "Beta tumse ye ummeed nahi thi , tumne naak kata dia..kya muh dikhayenge society mein " And I can not support you on this , and if I will let you do mba then how I will  be able to meet the expenses of your marriage, neither I can allow you to take loan nor I can support you on a boy who is less successful than you. " Either you choose us or him along with "yaad rakhna use chuna to humare lie tum and tumhare liye hum marr gaye" (The best emotional blackmail one can do) .
            As college ended she could not do anything except pretending in front of Raghav that she is not interested in him anymore and she cheated him so that he can move on . Raghav could not understand all this , he tried visited her home ,tried meeting hes family but all gone in vain . He was hurt , broken badly , as he lost the love of his life along with that lost respect and expectation of his family on him. He lost alot but the girl lost all.
                        She got married next year to a boy whom she just knew for one month , she tried to convince her family for her love and career but she could not as she could not fight them. She became helpless , seeing all the expenses in her marriage she was just shouting from inside ( kaash dad in paiso se mba karwa dete , kaash Raghav ko yahan la dete , kaash aisa kuch na hota , kaash sab pehle jaisa hota.. ) but that's the thing with "kaash "  ki wo kabhi nahi hota.

                        That's where the story ends my friend . They both lost each other ,   just in the name of society and pride , they lost all. The boy could not move on and the girl could not fight her family. They both are living but dead from inside with just one thing in mind "kaash aisa na hota.. !!"



PS- It's just a story, though it resembles the reality but it's not everyone's reality . If you are going through such kind of phase just face it properly with all the guts and strength . If you want to do something big ,achieve something great , don't give up on the namesake of marriage and "naak kat jaegi " or any such kind of things . Because one day if you are able to prove yourself ,  your parents will be happy for you and the statement will be changed into "naak unchi kar di beta.." and you will get your love in your life , once you are able to prove yourself.. :)

Stay happy,
Stay cool
Live your life freely 
Be a rebel.

Have a nice day..
- Anurag