What is the Size of ” null ” Operator in Java?

[ This Blog Was Moved To : http://www.diknows.com ]

Today, in the Java Developers Group in LinkedIn; I found this question posted by Sneha Kesri. She asked “What is the size of ” null ” Operator in Java ?”.

Actually, I never thought of it that way, but I continued reading.

Ramesh Babu Kotehal replied with the following :

from the heap memory perspective it will be 0, as it wont allocate any memory from heap. But from stack memory perspective the object has reference which is set to null. and the reference variable size depends your system.
for 32 bit system it will be 4 byte and for 64 bit system it will be 8 byte.

but as such null is not referring to any data from heap, so heap memory will be same.

And that was the only reply by then, which was correct, but Sneha Kesri asked another question:

Thanks Ramesh, I am having one more doubt… when we say..

String str1 = null;
String str2 ="";

Since str1& str2 are not equal.Does Str2 allocates memory in heap?
Does it take any value i.e garbage value for str2;

And is there any way to check memory size in Java?

So, I replied her with the following :

When you write

String st1 = null;

You create a reference “str1” to an object that still does not exist in the heap, but when you type :

String st2 = "" ;

You create a reference “str2” to a string object that is already allocated in the heap which preserves the string object size.

if you do that expression

str1 == str2 ;

It should evaluate to false, because you are comparing reference values, which will not be equal.

if you do that expression

if(str1.equals(str2) ){ }

It should throw a NullPointerException because you are trying to access the method equals on a null object ( str1 )

but if you try that expression

if(str2.equals(str1) ) {}

It should return false, because the value of ( str2 ) is an empty string not null object.

I wish It was helpful.



How To Change Nagios Password

[ This Blog Was Moved To : http://www.diknows.com ]

Later this afternoon, a colleague asked my help to change the Nagios Password.

As I am not a Nagios user, I searched google for it and found this link about Nagios Installation.

So, lets cut to the chase, here are the steps I used:

root# touch /usr/local/nagios/sbin/.htaccess

root# vi /usr/local/nagios/share/.htaccess

And I wrote the follwing text in the .htaccess file

AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user

Then, I did the following:

root# touch /usr/local/nagios/share/.htaccess

root# vi /usr/local/nagios/sbin/.htaccess

And I wrote the same text in that file too. Then, I did the following
(Which is the command for changing the password ):

root# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

New password:
Re-type new password:
Adding password for user nagiosadmin

root#  ls -l /usr/local/nagios/etc/htpasswd.users
-rwxrwxr--  1 nagios nagios 26 Dec 21 15:54 /usr/local/nagios/etc/htpasswd.usersroot#

root# chmod o+r /usr/local/nagios/etc/htpasswd.users

root# service httpd restart

Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

And, This is it for now.