|
| |
| |
| |
|
Statistics |
| Unique Visitors: 33 |
| Total Unique Visitors: 902787 |
| Visitors Out: 1088 |
| Total Visitors Out: 3759 |
|
|
|
| |
|
|
| |
|
| Final,Finally and Finalize keyowrds in Java explained |
| 2012-05-09 09:30:00 |
final, finally, and finalize are keywords (and a method) in Java that despite their common naming are used for completely different purposes. It seems that because of this very reason interviewers like to ask questions about the differences between final, finally and finalize. So, in order to get a better understanding on this issue, here's my brief explanation of the final and finally keywords, and the finally method, along with relevant examples:Lets us start with Final Keyword final can be used to mark a variable "unchangeable" private final int test = 20; //the reference name can never change final marked method cannot be overridden.It is used for constant, method or class declaration. When used with constants, their values cannot be changed later, when used ...
|
| |
|
| Using Continue statement in Java |
| 2010-11-14 13:10:00 |
Sometimes we want to force an early iteration of the loop.That is we might want to continue running the loop but escaping the execution for few conditions.To skip some iteration of the loop we can use continue statement.Its opposite of break.break lets us come out of loop and switch statements whereas continue keeps us inside with leaving some conditional iterations.For example if we want to print the odd numbers only then we may skip the iterations of even numbers.For this purpose we can use continue statement.Let us consider below mentioned example:-public class TestContinue{ public static void main(String a[]){ for(int i=0;i<10;i++){ if(i%2==0) continue; System.out.println("The Odd Number is :- "+i); } }}NOTE:...
|
| |
|
| How to use Java command Line Arguments |
| 2010-11-14 06:44:00 |
Whenever we need to pass information into our program during execution ,we can use command line arguments.The Command line arguments are actually the arguments of main() method and are of String Format.Basically command line arguments are those directly follow program's name on the command prompt.As I told earlier that are none other than simple main() programs arguments.All the command line arguments are stored in the form of String.So it is advised to change to required type like integer,char etc before using them in the main program.Consider below Program as an Example:-public class CommandArguments{public static void main(String a[]){int sum=Integer.parseInt(a[0])+Integer.parseInt(a[1]);System.out.println("The Sum is :- "+sum);}}As you can see that before adding the command arguments w...
|
| |
|
| The " ? " Operator |
| 2009-12-27 12:48:00 |
Java includes a special Three-way(Ternary) operator that can replace certain types of if-then-else statements.These statements include assignment when certain conditions are fulfilled.This operator is " ? ".The working of " ? " operator is similar as in C,C++ and C#.The " ? " operator at first look might seem confusing but it is extremely useful in particular conditions when mastered.General Syntax :-expression 1 ? expression 2 : expression 3Here expression 1 can be any expression that evaluates to a Boolean value.If expression 1 is true then expression 2 is evaluated else expression 3 is evaluated.Both the expressions expression 1 and expression 2 must have a return type,they can never be void.Make it more clear by understanding below example.Example:-public class optest{ public static ...
|
| |
|
| Dynamic Initialization |
| 2009-12-23 11:05:00 |
There are two types of variable mainly:-1.Instance Variable or Class Variable2.Local Variable or method variableInstance variable are initialized by JVM to their default values if not defined explicitly.Whereas the local variables needs to be defined each time time they are declared.But the local variables can be used to a greater effect by using the concept of dynamic initialization.Dynamic Initialization can be defined as the dynamic operation that allows variables to be initialized dynamically using any expression valid at the time of the variable declaration.Above definition implies that if you need a variable to store value of an expression you can use dynamic initialization.In which value of an expression is assigned to a variable.Dynamic Initialization can be clear by understanding ...
|
| |
|
| Starting and running Multiple Threads |
| 2009-12-08 11:02:00 |
In the previous tutorials about Threads we have learnt about the basics of Threads,How to create a Thread and also how to start a Thread.So far we have learnt how to start a single Thread but in this tutorial we will learn about how we can start and run Multiple ThreadsTo start Multiple Threads we use Runnable interface method which is best one.So we will implement the Runnable interface in our class and use the instance of our class to start Threads.To start a Thread we simply need a method start() to begin all the Threads.Consider following example it will help you understand the Multiple Threads:-class MultiTest implements Runnable{ public void run() { for(int i=0;i...
|
| |
|
| How to Start a Thread in Java |
| 2009-12-04 11:03:00 |
There are two ways of Thread creation either by implementing Runnable or extending the Thread class.In both the cases you need to start the thread for getting the functionality you need.So in order to start a thread we need a method which is start() and it is invoked on Thread object.
Remember:-start() method is always invoked on Thread object to start a separate call stack of this thread,but if you call the run() method on your Runnable object then it is simply a method call and cannot initiate a separate call stack.It also clears that You start a Thread not a Runnable.
To start a new Thread in separate call stack use
t.start() // where t is Thread object which is in execution.
We have made a call to start() method but know what happens behind the scenes there are three things happen:-
A new Thread in execution starts(in a new call stack).The Thread moves from the new state to the runnable state.Whenever the Thread gets a chance to execute then it goes to running state and the ta...
|
| |
|
| How to use Swing Scroll Panes |
| 2009-12-02 11:16:00 |
A Scroll Pane is a component like JFrame or JPanel which is used to add other components but Scroll Pane has a Scroll Bar Associated with it which is a unique characteristic of this component Container.Scroll Panes are implemented in swing by JScrollPane class ,which extends JComponent class.Scroll Bar is either Vertical or Horizontal and they are used in Scroll Panes as needed.Like if you want to display the Scroll Bars all the time then you may use them always and also you might choose them to show up when container overflows.Constructors used to create the Scroll Pane in Swings are :-JScrollPane(Component cmp)JScrollPane(int vert, int horiz)JScrollPane(Component cmp, int vert, int horiz) Remember:- A window can not be added to a Scroll Pane like JFrame cannot be added to a JScrollPane,b...
|
| |
|
| How to Set Icons on Swing Buttons |
| 2009-12-01 14:14:00 |
Swing Buttons provides many exclusive features that are not found in the Button class defined in the AWT package.Swing Buttons are the subclass of AbstractButton class,which extends JComponent.You can always associate an icon of your choice with a Swing Button.The Icons are set as program runs or set when some event is fired like button pressed.AbstractButton class contains many methods that allow you to control the behaviour of buttons,check boxes and Radio Buttons.There is the way you can set the icon on the swing button and it is through the JButton constructor.Despite of being set by constructor we can change the Icon of our Button whenever some action is fired or some condition is met.We can define different Icons when button :-1.is disabled2.is pressed3.is selected(for radio buttons ...
|
| |
|
| The Garbage Collector Approaches |
| 2009-11-12 12:53:00 |
A Garbage Collector must do two things:-1.Detect garbage objects2.Deallocate the memory of garbage objects and make it available for the program.There are four approaches that a garbage collector may adopt to detect the garbage objects.A) Reference -counting Collectors :-Reference counting garbage collectors keep a count of the references for the each live object.When an object is created ,the reference count of each object is set to one.When you reference the object ,the reference count is incremented by one.Similarly when a reference to an object is eliminated ,the reference count is decremented by one.An object which has reference count zero is a garbage object when the object is garbage collected ,the references of the object that it refers to are decremented.Therefore garbage collecti...
|
| |
|
| |
 |