provide-free-support Ujjwal's Blog: 2008

Thursday, December 11, 2008

Accessing Manifest file

The manifest file contains a description of package related data contained within a Jar archive. Strings stored in MANIFEST.MF can include version and company information, the name of the main method in executable jar files and secure-digest information. Here is a simple example that illustrates the technique for accessing the data contained in MANIFEST.MF
Given the following Manfiest.mf file in the META-INF directory of a jar file:Manifest-version: 1.0 Name: com/mycompany/ourstuff/Implementation-Title: com.mycompany.ourstuffImplementation-Version: 21Implementation-Vendor: My Company
You can access the information contained within the Manifest using the following:Package versionInfo = Package.getPackage("com.rkcole.mystuff");String revision = versionInfo.getImplementationVersion();String vendor = versionInfo.getImplementationVendor();String title = versionInfo.getImplementationTitle()

Capture screenshot using java

Hi Friends,


Today, i got free from my project quite early. Thought of writing something about capturing a screen shot using java AWT. Below is the code for that.




Cheers!!!
Ujjwal B Soni

Saturday, October 25, 2008

Procedure for custom paging in SQL Server 2005

Hi,

Today, i was getting data of more than 10 lakh records from mah database & filling up a grid of 10 records, but it was taking immense time so, i wrote a procedure that returns custom paging for a grid......Njoy the code....if ne queries, reply me :)

alter PROCEDURE sp_PagedItems
(
@Page int,
@RecsPerPage int
)
AS

-- We don't want to return the # of rows inserted
-- into our temporary table, so turn NOCOUNT ON
SET NOCOUNT ON


--Create a temporary table
CREATE TABLE #TempItems
(
ID INT IDENTITY,
CARID int,

title varchar(500)

)


-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempItems (carid, title)
SELECT carid, title FROM carregister

-- Find out the first and last record we want
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)

-- Now, return the set of paged records, plus, an indiciation of we
-- have more records or not!
SELECT *,
MoreRecords =
(
SELECT COUNT(*)
FROM #TempItems TI
WHERE TI.ID >= @LastRec
)
FROM #TempItems
WHERE ID > @FirstRec AND ID < @LastRec


-- Turn NOCOUNT back OFF
SET NOCOUNT OFF



Cheers!!!

Ujjwal B Soni

Tuesday, October 14, 2008

Simple Defination for EJB Session Facade

Instead of accessing the ENINTY Bean directly, Â You access the client through Session bean, i.e you call session bean first which in turn call entity bean, this is called session facade

difference b/w EJB2.1 and EJB3.0

EJB3.0
  1. No need of Home Interface (EJBHome),but it is needed in EJB2.0
  2. No more confusions to make an EJB remote or local,it's the client which would decide and cast to appropriate.
  3. Just write SINGLE simple Java class and annotate it to be Stateless/Stateful/Entity/MessageDriven.Container
  4. No Deployment Descriptors , MetaData Annotations are explored which is introduced in J2SE5.0
  5. Forget all EJB life cycles.For example Entity bean life cycle in 3.0 is new,managed,detached,removed.
  6. Ejb 3.0 siplifies the developement of the application

    Ready to develop complex query,inner/outer join with EJB3.0.
The main difference lies in the persistence In case of EJB 3.0 there is JPA Java persistence API which makes the mapping of EntityBeans with the database easy with the help of a service called as EntityManager.

Mapping is done with the help of annotations unlike in EJB2.0.
Home interfaces are eliminated.
Deployment descriptors are an option in EJB 3.0.
EJB3.0 also supports webservice client through SOAP and WSDl.

Finally, concluding this topic I think the main difference is that EJB 3.0 is moved towards annotations based programming model and dependency injection to make our life easy . 



For more information please visit http://javaknowledgestorm.blogspot.com/2009/04/differences-between-ejb20-and-ejb30.html

Difference between Encapsulation & Abstraction OOPS

Difference between Encapsulation & Abstraction OOPS

Abstraction is virtual class design.

Before actually defining class, developer will think about what all properties,methods and event will be there in my class.

Whereas,encapsulation is data hiding.

At the time of class defenation,developer will think about which should display to end user and which should not.

In Short Abstraction is "Collection of data" and Encapsulation is "Exposure (or grouping) of data in appropriate access specifier".

Display all tables in sql server

Hi,

We used the show tables command in mysql. But, here in Sql Server to display all tables we need to write select * from information_schema.tables command in order to display all tables.

Cheers!!!

Ujjwal B Soni

Execute .jsp from command line in java

Hi,

There is a little tool called JSPExecutor that allows you to do just that. The developers (Hendrik Schreiber & Peter Rossbach ) aim was not to write a full blown servlet engine, but to provide means to use JSP for generating source code or reports. Therefore most HTTP-specific features (headers, sessions, etc) are not implemented, i.e. no reponseline or header is generated. Nevertheless you can use it to precompile JSP for your website.

Cheers!!!

Ujjwal B Soni

Thursday, September 18, 2008

Accessing Gridview via Javascript

Objective


Now-a-days lot of new DotNet developers are coming into the field. Many of them have struggled on GridView control with Javascript. I came to know this by reading forums like dotnetspider, asp.net and etc., . So that I am planning to give a small article to access GridView control using Javascript.

Finding GridView ID


Find the gridview control's id using getElementById method.
var gv = document.getElementById(“GridView1”)
gv variable holds the GridView1 object. Using gv object we can access the grid view control.

Javascript Example


Following example demonstrates select all and de-select all checkboxs in the gridview control.

Click on it to open !!!



Description of the above example

The above example is used to select all and de-select all check boxes in
the gridview control. The javascript function SelectAll has a parameter
called SelBtn which will decide the checkboxs to be select or
de-select. The gvET is the variable which can extracts the properties
and methods of gridview control.

For selecting or de-selecting
check boxes we have to loop it from starting ordinal to the ending
ordinal of the gridview control. Starting ordinal can be 0 at any time.
Ending ordinal is calculated using length of the gridview control. So
length of the gridview control is stored into the rCount.

Find the page count of the gridview. If page cont is greater than 1 then
rowIdx starts with 2 else 1. Here we have to concentrate why we set
rowIdx position. Because the paging informations will be placed in
gridview. So it took one row to show the paging informations.

In for loop we have created row object called rowElement which is used to
access the rows of the gridview. We know already which column holds the
check box. Using check box position we create check box to select or
de-select as demonstrated in the above example. Finally we have changed


the select all and de-select all caption to the button control.

I hope this article will be helpful to one who dose not have the idea about gridview with javascript.

I would love to hear comments about this !!!

Cheers!!!

Ujjwal Soni



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

Wednesday, July 30, 2008

Email Verification using c#

One thing that's really common is to require email verification before letting a new user into the system. The CreateUserWizard by default doesn't work that way, basically after user registration is done you are logged in automatically (if LoginCreatedUser=true) or if false then the user just needs to login.

As we have decided email is the central point here - working as the username, let's implement email verification before newly created users can login.

It should work this way - after the user has registered he/she should be told something like "Thanks for registration. Now wait for an email and click the link for verification, after that you have access to our site".

First, inside the CreateUserWizard, create a CompleteWizardStep template:





Thanks for registering with us

Now wait for an email to be sent to the email address you specified with instructions to enable your account and login.



Now set LoginCreatedUser="False" and DisableCreatedUser="True" for the CreateUserWizard.

This will create the user as disabled and the idea is to send the user an email containing an unique verification url which when clicked sets the user account to approved (oUser.IsApproved = true;)

In CreatedUser event we are supposed to send an email:


protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
CreateUserWizard cuw = (CreateUserWizard)sender;
MembershipUser user = Membership.GetUser(cuw.UserName);
Guid userId = (Guid)user.ProviderUserKey;
string sHeader = "";
string sBody = "";
MailHelper.NewUserMail(userId.ToString(), ref sHeader, ref sBody);
MyContext.SendEmail(cuw.Email,
sHeader,sBody, true);
}



I am using some helper functions but the basic idea is that all users gets a unique id from the provider - and for SQL Server it's a guid, which is guaranteed to be unique and also to hard to guess for an outsider. So I retrieve that value for the newly created user through user.ProviderUserKey and use that to build up a registration url string in the email:

To give you the idea the string will be

http://www.aspcode.net/blabla/activate.aspx?id=

We send an email to the user containing that string and when they click on it they go to our page activate.aspx:

In Page_Load we simply retrieve the id and approve it:


Guid oGuid = new Guid(sKey);
MembershipUser oUser = Membership.GetUser(oGuid);
if (oUser != null && oUser.IsApproved == false )
{
oUser.IsApproved = true;
Membership.UpdateUser(oUser);
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(oUser.UserName,
false);
}



Last, the verification cheme is pretty lame I know, but it might be good enough. Some improvements would be to also require the email address, which would force the user to also enter the email adrress (mimimizes guid guessing risks), and of course the code to just use user.ProviderUserKey is not very smart - it works for SQL Server but there is a risk some other provider just implements it as a autonumber field - i.e just a sequencial number, very easy to guess. You could of course add your own guid generation, storing it somewhere else - tying it with the user.ProviderUserKey.


Regards,


Ujjwal B Soni

+919998971048

C# code to POST XML Data & Fetch Return data

Hi Friends,

We usually face trouble when we want to fetch the return data after post back, especially when it is an XML Post back. I've developed a code that posts XML data to a website & grabs the return values.Below is the code to POST XML data on a particular website & fetch the return data after form post back.

try
{

ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "";
postData += "

ShareThis

Feedjit

Which technology you consider best these days ?

Followers

Blog Archive

best-it-exam-    | for-our-work-    | hottst-on-sale-    | it-sale-    | tast-dumps-us-    | test-king-number-    | pass-do-it-    | just-do-it-    | pass-with-us-    | passresults-everything-    | passtutor-our-dumps-    | realtests-us-exam-    | latest-update-source-for-    | cbtnuggets-sale-exam    | experts-revised-exam    | certguide-sale-exam    | test4-sale-exam    | get-well-prepared-    | certkiller-sale-exam    | buy-discount-dumps    | how-to-get-prepared-for-the    | in-an-easy-way    | brain-dumps-sale    | with-pass-exam-guarantee    | accurate-study-material    | at-first-try    | 100%-successful-rate    | get-certification-easily    | material-provider-exam    | real-exam-practice    | with-pass-score-guarantee    | certification-material-provider    | for-certification-professionals    | get-your-certification-successfully    | 100%-Pass-Rate    | in-pdf-file    | practice-exam-for    | it-study-guides    | study-material-sku    | study-guide-pdf    | prep-guide-demo    | certification-material-id    | actual-tests-demo    | brain-demos-test    | best-pdf-download    | our-certification-material    | best-practice-test    | leading-provider-on    | this-course-is-about    | the-most-reliable    | high-pass-rate-of    | high-pass-rate-demo    | recenty-updated-key    | only-for-students-free-download    | courseware-plus-kit-for    | accurate-answers-of    | the-most-reliable-id    | provide-training-for    | welcome-to-buy    | material-for-success-pass    | provide-free-support    | best-book-for-pass    | accuracy-of-the-answers    | pass-guarantee-id    | pass-exam-key    | pass-sku-id    | study-for-exid    | pdf-sku-exid    | sku-pdf-id    | pdf-demo-key    | exam-demo-ske    | pass-it-dump    |
http://www.menuiserie-dauvergne.com/    | http://www.menuiserie-dauvergne.com/    |