Skip to main content

Posts

Memory Leak in Java? Does 'static' cause it?

Does 'static' cause Memory Leak in Java? What's memory leak? In simple terms, it's unused but referenced (somehow because the programmer probably unintentionally forgot to remove the references once the use of the object was over) part of the memory. Before we start discussing if 'static' can cause memory leak in Java, let me assure you that whatever you've read about Garbage Collectors in Java, is still valid and it certainly takes care of most (almost all) of the memory allocation/reclaimation of Java objects. But, that alone doesn't remove the possibility of the presence of memory leak in a Java program - just for example, you might not only be using only Java objects in your Java program. Putting it differently, what if you have used some native objects and forgot to reclaim the memory explicitly because that's anyway not going to be taken care by the GC (which takes care of heap memory management only)... right? Now that we agree with the pos...

Java Interview Tips

Whenever we go for technical interview we need to mind some tips. That makes you more stronger and confidence to attend the interview without any nervous. Just think about your strength and weakness. Some people can make their weakness as strength to the work they are going to do. Just read the following tips and get succeed in interviews. Wish you good luck. Why did you choose your major? Why did you choose your school? Describe a recent leadership experience. Which courses have you enjoyed the most? The least? Why? What is your GPA? If you could do so, how would you plan your education differently? Describe your most rewarding college experience. Your most challenging. Tell me about yourself. What do you consider to be your greatest strengths?

How To Deal with Array Exception in Java

Remember that array indexes start at 0. So, for an array with five locations, the indexes would be 0,1,2,3,4. Check that FOR loops and the results of any calculated indexes take this into account. Also, make sure that a value is checked before it is incremented. String[] bob = new String[10]; for(int i=1 ; i<10 ; i++) The index should start at 0, and go to 9 { bob[i]="bob" The error will point to this line } In the first program, the error is caused by the FOR loop having the wrong parameters. This causes the error in another place.

Oracle Database Interview Questions

1. What are the components of Physical database structure of Oracle Database? ORACLE database is comprised of three types of files. One or more Data files, two are more Redo Log files, and one or more Control files. 2. What are the components of Logical database structure of ORACLE database? Tablespaces and the Database's Schema Objects. 3. What is a Tablespace? A database is divided into Logical Storage Unit called tablespaces. A tablespace is used to grouped related logical structures together. 4. What is SYSTEM tablespace and When is it Created? Every ORACLE database contains a tablespace named SYSTEM, which is automatically created when the database is created. The SYSTEM tablespace always contains the data dictionary tables for the entire database.

Why wait(),notify() and notifyAll() in the Object class?

Java concurrency model uses locks to implement mutually exclusive access to objects in a multi-threaded environment and locks are associated with every object in Java (of type 'Object'), not only with Threads. wait, notify/notifyAll methods are used by threads to communicate with each other while trying to access a common object. Putting it differently, objects become a medium via which threads communicate with each other. For example: suppose there is a 'telephone' object, which at one point of time can be used by only one thread. Like every other object in Java, 'telephone' object would also have an intrinsic lock (monitor) associated with it which at one point of time can be acquired by only one thread. Suppose the 'telephone' object requires activation before it can be used and suppose only a few admin threads can activate the 'telephone' object.

How to Make a Java Class Immutable?

Immutability must be familiar to every one when we talk about String & StringBuffer classes in java. Strings are considered immutable because the values contained in the reference variable cannot be changed. Whereas String Buffer is considered mutable because the value in a string buffer can be changed (i.e. mutable). However I always thought how to make our user defined classes as immutable though I am unaware as to why any one would need this. The reason perhaps might be clear once we have a look at the code. Now in order to make a class immutable we must restrict changing the state of the class object by any means. This in turn means avoiding an assignment to a variable. We can achieve this through a final modifier. To further restrict the access we can use a private access modifier. Above do not provide any method where we modify the instance variables.

Event Handling in Java

Handling Events with an Anonymous Class If an event handler is specific to a component (that is, not shared by other components), there is no need to declare a class to handle the event. The event handler can be implemented using an anonymous inner class. This example demonstrates an anonymous inner class to handle key events for a component. component .addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { } }); Handling Action Events Action events are fired by subclasses of AbstractButton and includes buttons, checkboxes, and menus. AbstractButton button = new JButton(quot;OK"); button.addActionListener(new MyActionListener()); public class MyActionListener implements ActionListener { public void actionPerformed(ActionEvent evt) { // Determine which abstract // button fired the event. AbstractButton button = (AbstractButton)evt.getSource();