Saturday, August 30, 2008

System.out.println

Q Explain System.out.println ?

A:->

System:-It is the final class and its constructor is
private.so we can not create new object of System.
out. it is the static member of the System class of type
java.io.PrintStrem.
println:-it is the overload function of PrintStream.

Java's way of decompiling a class file

Hi Friends,

I finsished up with my project work early today. So, i thought of writing to this blog. I found an inbuilt way of decompiling the java class file that contains the binary data. Yes, jdk provides an inbuilt command that is javap.

Using javap you can decompile the java file. Folks, many of us might be using 3rd party tools like cavaj to decompile the class file, but java has its own way of doing this. Below is the example on how to do this.

c:\> javap Ujjwal.class

Cheers!

Ujjwal Soni

Friday, August 29, 2008

Eclipse Shortcuts

I was free as my code with CR is done. i was thinking wht to write and it just sparked in my mind that this can be a good thing though many of us has explored this.But then also it can help some newbies.
Maximize/minimize the selected window - Ctrl +M
Generate getters/setter - Alt+Shift+s + r
Override/implement methods - Alt+Shift+s + v
Show type implementation - Ctrl+T on selected type in java file
quick class member browser - Ctrl+o
search usage of selected member - Ctrl+Alt+H
comment/uncomment selected lines - ctrl+/
Open declaration - F3
This is what most used ones. You also can submit if i missed important ones in commnets.

Cheers!

Ujjwal B Soni

Tuesday, August 19, 2008

Trick to make netbeans fast

Hi,

There is a file named 'netbeans.conf' which can be found in \etc\ which you can edit to increase the amount of memory that NetBeans runs with. Edit the property named 'netbeans_default_options'. Increasing the -Xms and -Xmx options will increase the amount of RAM avialable to the JVM that NetBeans will be running inside of.
Example:
netbeans_default_options="-J-Xms384m -J-Xmx512m -J-XX:PermSize=32m -J-XX:MaxPermSize=96m -J-Xverify:none"

This example will allow NetBeans to run with a minimum of 384 megabytes of RAM and a maximum of 512 megabytes of RAM.


Cheers!


Ujjwal B Soni

Use your pen drive as a temporary ram in vista

Till this date, Microsoft’s windows had Page File (A virtual memory file, stored on hard disk) options for the memory requirement of the computer, so that the computing can be done at cheaper rates and that too without installing the physical memory (RAM).

The page file is used by the Windows OS to cater the needs of various applications when the physical memory is fully used up. The reason for that is, that Virtual memory is slower as compared to the physical memory and thus Phyical memory takes the first priority.

However, with the release of Windows Vista, Microsoft has introduced a new technology called ReadyBoost. With the help of this technology one can use any Flash drive, SD Cards, CF Cards as the third memory option for the computer.

Now, the benefits of Flash Drive or Cards as a source of Memory :

1. It is faster than the virtual memory which is accessed through the hard disk drive.
2. It is cheaper as compared to the actually Physical Memory.


How can it be activated ?

In order to activate the ReadyBoost technology on your FlashDrive or Memory Cards, you have to follow these steps…

1. Open My Computer.
2. Right Click on the Removable Disk Drive and select Properties.
3. Click on ReadyBoost Tab.
4. Enable the feature by selecting the option and allocate the amount of space you want to use as memory.

Things to be noted….
1. Regardless of the fact that you use Readyboost or not, you need at least 512 Mb of memory to run Windows Vista decently.
2. If your device is not giving the option of ReadyBoost then it means that it doesn’t clear up the minimum data trasfer rate required by ReadBoost technology.

Hope this is useful..

Cheers!

Ujjwal B Soni

Thursday, August 14, 2008

Make your own customized GMAIL mobile Alert!

Well, not long ago a lot of services were free online ranging from Free Magazines,email accounts,hosting services and even domain names !! . Every online user just like US i.e YOU and ME wants to have a lil bit more .. after all whats harm in lil competition .Well! one such service is www.Gmail.comwww.Google.com has a long history of satisfying customers and hey! free service has no competitors ,right!! . Not to forget one more such service which is called www.160by2.com it allows people to send free 80 chars msgs anywhere in India.(rest 80 chars reserved for advt.)

 I have been a loyal user of www.Gmail.com from past few months , apart from latest developments & added features the one and only one eagerly awaited feature which is yet to launched is Gmail Mobile Alerts for India . Google has made no such official anouncement , but fortunately they will be going to offer this service soon.

Hence,My attempt here in this article is to combine two services i.e Gmail and 160by2 , so that what we have is a khichdi which ,guess wat, serves us and gives us a Customized Gtalk Mobile Alert Xclusive for India .. that too absolutely GRATIS!!

Disclaimer:Following code are not written by me from scratch . Following code belong to their respective authors which are taken from various sources such as PHP.net or other Forum(s). I do to intend to take the credit for the following code nor propose some one else ,for whom this code may be usefull, to do the same. I have just made few modification so that it serves the purpose . It does not intends to exploit the service offered by either Gmail or 160by2.

So here we go!

Requirement : Two hands (to Programm :p) , A php hosting (I use www.Freehost.ag) , knowledge of CronJob and some <?php?>

1. Attempt: To fetch the number of unread mails from Gmail account . After repeating attempt I am not able to access gmail using Imap enabled in Setting section. Hence the only alternative is to have access thru gmail atom feed which serves us well .

Class gmailCount{

function msgCount(){
$username = "Username";
$password = "Password";

// Initialise cURL
$c = curl_init('https://gmail.google.com/gmail/feed/atom');

$headers = array(
    "Host: gmail.google.com",
    "Authorization: Basic ".base64_encode($username.':'.$password),
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4″,
    "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5″,
    "Accept-Language: en-gb,en;q=0.5″,
    "Accept-Encoding: text",
    "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7″,
    "Date: ".date(DATE_RFC822)
);

curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($c, CURLOPT_COOKIESESSION, true);
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($c, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 1);

$str = curl_exec($c);

preg_match('#<fullcount>(.*)</fullcount>#', $str, $array); // Use a regex to get what's between <fullcount>(.*)</fullcount>

return strip_tags($array[0]); //stripts all HTML Tag from the given string

curl_close($c);
}
}

Above Code uses Curl , I believe it is one of the most over-used functionality in PHP. So! basically Class gmailCount{} fetches the number of new mails from username@gmail.com and returns the number when msgCount() function is invoked from its object .

 2. Attempt : Following Code tried to establish connection with www.160by2.com

Class sendSms{

   function sendMsg($nuOfMsg){
  $username = "Username";
  $password = "Password";

  // INIT CURL
  $ch = curl_init();

  // SET URL FOR THE POST FORM LOGIN
  curl_setopt($ch, CURLOPT_URL, 'http://www.160by2.com/LoginCheck.aspx');

  // ENABLE HTTP POST
  curl_setopt ($ch, CURLOPT_POST, 1);

  // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
  curl_setopt ($ch, CURLOPT_POSTFIELDS, 'htxt_UserName=' . $username . '&txt_Passwd=' . $password);

  // IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
  curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

  # Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
  # not to print out the results of its query.
  # Instead, it will return the results as a string return value
  # from curl_exec() instead of the usual true/false.
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  
  // EXECUTE 1st REQUEST (FORM LOGIN)
  $store = curl_exec ($ch);
  
  // SET PAGE TO SMS COMPOSE
  curl_setopt($ch, CURLOPT_URL, 'http://www.160by2.com/postview.aspx');
  

  // EXECUTE 2nd REQUEST
  $store = curl_exec ($ch);
  
  /* SET POST PARAMETERS : FORM VALUES FOR EACH FIELD. Replace 'MobileNumber. with your number with no preceding zeroes or 91.It shud be strictly 10 digit number . The Second 'MobileNumber' should also follow the same i.e write only 10 digit mobile number. */
  curl_setopt ($ch, CURLOPT_POSTFIELDS, 'txt_mobileno=MobileNumber&txt_msg=Total NEW Mails in Username@gmail is:' . $nuOfMsg . '&act_mnos=91MobileNumber');
  
  // EXECUTE 2nd REQUEST
    curl_exec ($ch);
 
  // CLOSE CURL
  curl_close ($ch);

}
}

Logs into www.160by2.com , stores the cookie so that it gives an illusion of a real browser and function sendMsg() receives the number of New mails as an argument and broadcasts it as content of the SMS . Remember , if u change the content it should NOT be more then 80 Chars as rest will be truncated.

3.Attempt : Objects are created from both the classes and a Text file is created to store the number of new mail which was fetched from the last request , the next subsequent requests deducts this number from the data stored in this file and passes this to sendMsg()

//CREATE THE NECESSARY OBJECT(S) FROM THE CLASSES
$obj=new gmailCount();
$obj2=new sendSms();

$myFile = "msgCount.txt";
$stringData = $obj->msgCount();
if(!file_exists($myFile)){
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $stringData);
$obj2->sendMsg($stringData - $stringData);
}
else {
$fh = fopen($myFile, 'r') or die("can't open file");
$theData = fread($fh, filesize($myFile));
fclose($fh);

$fh = fopen($myFile, 'w+') or die("can't open file");
fwrite($fh, $stringData);
if (($stringData - $theData) != 0) $obj2->sendMsg($stringData - $theData);
fclose($fh);

Voila! There you have it , your own customized Gmail Mobile Alert!

4. Attempt : Setup a CronJob so that this script runs after specified minutes/hours/days/weekdays/months.

If you have suggestions or Questions , feel free to drop your comments.

Friday, August 1, 2008

Simple OOPS Defination

HIDING DETAILS IS ABSTRACTION
BINDING OF DATAS IS ENCAPSULATION
DERIVATION OF BASE CLASS FROM DERIVED CLASS IS INHERITANCE