Skip to main content

Posts

Showing posts from November, 2011

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();

What is Bridge Pattern and Marker Interface

Bridge Pattern as the name suggests is used maily to decouple the interface and the class implementing the interface. Another obvious advantage is the extensibility provided in terms of Future enhancements. Also, hiding the actual implementation from the Client. Marker Interfaces are interfaces in Java that have no behavior. In other words, they are just empty interface definitions. For example in the Java API java.io.Serializable, Cloneable etc. All interfaces can act as marker interface but null interfaces are the most suited for it. also every interface has a boolean flag and that boolean flag goes for the entire generation of classes implenting that interface. I understand this boolean flag is the marker. What I want to know how this stuff is working in detail? Marker Interface: One of the "clean" features of the Java programming language is that it mandates a separation between interfaces (pure behavior) and classes (state and behavior). Interfaces are used in Ja

What is the differences between bean and ejb ?

A Java Bean is defined as an instance of a class that contains private attributes (data), and getter & setter methods. If you have: private String myString; in your class, you should have the methods public String getMyString (); and public void setMyString (String settingString); defined in your code. Although, I have found that it is not absolutely nessary to have everything defined; just don't be surprised if something breaks! An EJB (Enterprise Java Bean) is much more complex They only reside in application servers that handle EJBs (Tomcat doesn't hold EJBs). There are 3 types of EJBs: 1) Session Usually contain some business logic. 2) Entity Usually interface with a data store (such as a database). 3) Message-Driven Receives messages from JMS

What's the Difference between Forward and Include?

The <jsp:forward> action enables you to forward the request to a static HTML file, a servlet, or another JSP. <jsp:forward page="url" /> The JSP that contains the <jsp:forward> action stops processing, clears its buffer, and forwards the request to the target resource. Note that the calling JSP should not write anything to the response prior to the <jsp:forward> action. You can also pass additional parameters to the target resource using the <jsp:param> tag. <jsp:forward page="test.htm" > <jsp:param name="name1" value="value1" /> <jsp:param name="name2" value="value2" /> </jsp:forward>

What is the difference between Web Server and Application server?

Difference between AppServer and a Web server (1) Webserver serves pages for viewing in web browser, application server provides exposes businness logic for client applications through various protocols. (2) Webserver exclusively handles http requests.application server serves bussiness logic to application programs through any number of protocols. (3) Webserver delegation model is fairly simple,when the request comes into the webserver,it simply passes the request to the program best able to handle it(Server side program). It may not support transactions and database connection pooling. (4) Application server is more capable of dynamic behaviour than webserver. We can also configure application server to work as a webserver.Simply applic! ation server is a superset of webserver.

How To Do Pagination Similar in Google?

Suppose you've got 1000 records in a requestScope list or map called data: <display:table name="data" scope="request" id="record"> <display:column title="Title 1" property="property1"/> </display:table> and so on... There's a manual also. And you can provide the size of the page, the styles, an url to lin on each column. You can render a column by yourself or make it to autolink if the column is an url or emailaddress...

How differently does Java handle checked and unchecked exceptions?

If a method may throw checked exceptions, the calling code must handle the exception by either catching it or by declaring in the signature of the method (as throws). Unchecked exceptions do not have to be handled by the calling code. If a method might throw a checked exception, it must be declared in the signature of the method. Unchecked exceptions do not have to be listed in the method signature. When to use checked exceptions and unchecked exceptions? Please visit Best Practices for Exception Handling .

Tutorials for RESTful WebServices using JAX-RS [VIDEO]

The Best Tutorials for RESTful WebServices using JAX-RS. This video tutorial is the best to learn RESTful webservices, since it got more hits and likes on YouTube.

Java Program To Get Users IP Address

This following code shows how to obtain the IP address of the user that calls the server. The Request object has a few methods to get information about the call and about the caller, and one of them is named getRemoteAddr() which returns the IP address of the calling computer. The below example will print the IP address of the user on a blank html-page.

JDBC Program Using Type 3 Driver

A Sample Java Program Using JDBC TYPE 3 Driver. This driver is called as Network Protocol Pure Java Driver. This driver would only be the option when DB vendor supplied Type II & IV drivers are not available. Software: www.idssoftware.com Server: a) Install IDSServer software b) d:\IDSServer\IDSS.exe (The above said .exe runs as system startup service. IDSS.exe is a server socket program which runs on port number 12.)