Pages

Thursday, 17 October 2013

Giving respect is based on AGE or STATUS ??

From the topic itself you can suggest what I am going to discuss here.Very frequently this question is coming up to my mind .

I am not a story teller so dont worry I will not start with the sentence of One fine morning :p. I am living in a IT city. Like others I also came here for my job. Usually people will come here with a lot of dreams and passion. I came here just because of my fate. My impressions on this city is very hot , people are not good here, and you cant survive here for a long time.

I started to hate this city on my first day itself. I stepped down at this city A at 5 am. Luckily I have relatives here and they came to pick up me. I have to change two bus to reach my office from my relative place. I got into share auto to get down at bus stop. I was really shocked to see that share auto. Its just an auto which has the capacity of 4 people. But its carrying 8 people.3 girls were already sitting inside an auto including me. One old man OM1, actually he looks little descent. From his appearance you can judge him that he is not poor but he is respectable. He came to our auto where we were sitting and wanted to get in. Suddenly one girl who was sitting inside told him to go and sit nearer to the driver . He had no other option and he sat on that place which was nearer to driver. Next stop came. Another old man OM2 came with professional look. The girl one who rejected OM1 now allows OM2 to sit next to her. I was wondering that both of OM1 and OM2 are more or less in same age. May be the status are different. But giving respect is based on age isn’t ? . The way she looks OM1 and OM2 was totally different.

I got down from an auto, got down from bus1 and I got into bus 2.One old lady got into bus2 with fruits basket. From her appearance we can judge her that she is a fruit selling woman. Yeah, she waas not good loooking. she wore very poor quality sarree.She looked very innnocent. On the way to my office I suppose to cross one toll gate. Next to toll gate there was a bus stop. That old lady is waiting for the bus stop to get down which is next to toll gate. Toll gate came and driver was getting ticket in the lane from the passengers. Conductor started shouting at that old lady to get down there in the lane itself. She was not understanding anything. She told that no, no I have to get down at stop. Conductor started yelling at her that this bus wouldn't stop there. Due to conductor the old lady got down there itself with the basket. Bus moved and next bus came in to that lane. She suffered a lot to move out from that lane.But actually bus stopped there in the next stop. What is the reason for this? . Is it necessary to yell at her in this situation. Conductor should have to give respect to that old lady isn’t ? . If that old lady is there with descent look, if she wore good dress , then what would be the conductor response at this situation ? I am damn sure conductor might have given respect. So , now-a-days giving respect is based on status not an age. Is it good for our future generation ? Seriously our society is in bad shape.

This is all my perception. There are some good people here in the same city. I don't blame them. It is for the people who are doing like this.


Thursday, 10 October 2013

Java HEAP in Deep and dont Sleep!!


When I started java programming I didnt know what is Heap? I started learning Java concepts without knowing where its all getting saved in memory.
Its happens with most of programmer because learning language is easy but learning basics is difficult since there is no formal process which can teach you every basics of programming its experience and work which reveals the secret of programming.This post is mainly for beginners who are learning java. One thing I would suggest is first learn java concepts after that dig deeply about where its getting saved. If you started with heap you will get so many doubts about concepts. For Example, you should know about objects concept before learning "objects will be saved in heap memory" else you wont understand exact essence of object in heap.

Here are the some important things of heap that I have shared with you. Please refer other refference also.

When Java program started JVM (Hope, you know what is JVM)gets some memory from Operating system and part of that memory is called HEAP.JVM will allocate heap memory by Xms command which will tell the size required for heap. Default size of heap memory will be changed based on the bit and OS.

If heap size is not sufficient then JVM will set maximum heap memory by -xmx command.

Eg : -xmx512m. Be careful in giving "M"or "G". Single alphabet can change anything :p

When your application is ready for executing, Analyse how much heap memory is needed by your application. Then, execute the command -xms/xmx before JVM starts. Once JVM is started you cant reallocate your application heap memory.

All your objects will be saved inside heap memory. Memory is divided into 3 parts.
1) Old generated (Heap Memory)
2) New generated(Heap Memory)
3) Perm Space(Non Heap Memory)

Old Generated: Many objects will be created and saved inside the heap. Many objects might have been killed by Garbage collector. Remaining objects which are all not killed by garbage collector will be accumlated in old generated heap memory.

New Generated: Newly created object will be saved in new generated heap memory.

Perm space: Meta data about classess, method, string constant pool etc other than objects will be saved in perm space.

outofMemoryError: If your application tries to create an object and finds that there is no enough heap memory to accomadate. So, Garbage collector will run and it will free the memory of objects which are all not referenced to any memory. Objects will be created in the new generated heap memory. Though garbage collector tries to free memory , it couldnt find non referenced object. In such cases, application will throw an error called outofmemory error. Application needs some heap memory and heap memory is not enough to accomdate all those objects.

outofmemoryerror:permspace : The classloader is responsible for loading all classes in perm space. Classes will be unloaded when classloader is attacked by garbage collector. Suppose an object retain its reference the classloader which is attacked by garbage collector then it will lead to MEMEORY LEAK and shows outofmemoryerror:permspace error.

You can analyse your java heap by using some tools which is availble inside JDK. You can take snapshot of java heap at particular time called java heap dump and you can analyse it.Java heap dump will be created by using the command "jmap"."jhat: Java heap analyser tool" is available to anlayse the java heap and make use of it :)

You can also find the information of your application regarding memory during runtime by using following commands.
Runtime.totalmemory() : tells the totalmemory occupied by your application
Runtime.freememory(): tells how much free memory is availble
Runtime.MaxMemory(): tells maximum available for your application.

Use Profiler and Heap dump Analyzer tool to understand Java Heap space and how much memory is allocated to each object.

I hope the above information will be useful atleast for some extent :) Happy coding :)