Create a desktop shortcut to lock computer

You can lock your windows desktop by clicking on “windows key + L“. There is another way to do this. By creating a shortcut.

Right Click on your desktop and select

New -> Shortcut.

A shortcut will be created and a dialog box would pop up.

Copy paste %windir%\system32\rundll32.exe user32.dll,LockWorkStation into the text box of the dialog.

Click Next. Type any name you like.

A desktop shortcut with the name that you gave would be created. Double click anytime to lock your computer.

Generate dynamic id’s for struts html tags

Do you use struts tags to generate html content? If yes, then sooner or later you’ll come across a scenario where you would generate html elements with the same name but would need different id’s for each element. I faced a similar predicament recently. I had no other option but to use scriptlets to generate id’s for the html elements. However, I soon found out using scriptlets within the struts html tags isn’t really straight forward.

Here’s the code I tried in my first attempt:

<%int i=0;%>

//iteration logic here

<html:text property=”example” styleid=”example<%=i%>”>

Well, if you write the code as shown above, the html code generated would be :

<input type=”text” name=”example” id = “example<%=i%>”>

and not

<input type=”text” name=”example” id=”example0″>

To get the expected result, i.e. for the scriptlet to work inside the struts html tag, write as below:

<html:text property=”example” styleid=’<%=”example”+i%>’

That’s it. If any of you ever find out a way to generate different id’s for html elements with the same name using strtus tags exclusively then do let me know :)

Method overriding and overloading in Java

I know this may be trivial for many people but then it can be pretty confusing for new bees (pssst.. in the beginning me too used to be confused between overloading and overriding)

OVERRIDING – when you extend a class and write a method in the derived class which is exactly similar to the one present in the base class, it is termed as overriding.

Example:

public class BaseClass{

public void methodToOverride()

{

//Some code here

}

}

public class DerivedClass extends BaseClass{

public void methodToOverride()

{

//Some new code here

}

}

As you can see, in the class DerivedClass, we have overridden the method present in the BaseClass with a completely new piece of code in the DerivedClass.

What that effectively means is that if you create an object of DerivedClass and call the methodToOverride() method, the code in the derivedClass will be executed. If you hadn’t overridden the method in the DerivedClass then the method in the BaseClass would have been called.

OVERLOADING -  when you have more than one method with the same name but different arguments, the methods are said to be overloaded.

Example:

public class OverLoadingExample{

public void add(int i, int j)

{

int k = i + j;

}

public void add(String s, String t)

{

int k = Integer.parseInt(s) + Integer.parseInt(t);

}

}

As you can see in the example above, we have the same method add() taking two parameters but with different data types. Due to overloading we can now call the add method by either passing it a String or int :)