Sunday, February 28, 2016

ResultSet--Types and Concurrency

Type of ResultSet

ResultSet can be of three types. If you do not specify any ResultSet type, you will automatically get one that is TYPE_FORWARD_ONLY.
TypeDescription
ResultSet.TYPE_FORWARD_ONLYThe cursor can only move forward in the result set.
ResultSet.TYPE_SCROLL_INSENSITIVEThe cursor can scroll forward and backward, and the result set is not sensitive to changes made by others to the database that occur after the result set was created.
ResultSet.TYPE_SCROLL_SENSITIVE.The cursor can scroll forward and backward, and the result set is sensitive to changes made by others to the database that occur after the result set was created.

Concurrency of ResultSet

The possible RSConcurrency are given below. If you do not specify any Concurrency type, you will automatically get one that is CONCUR_READ_ONLY.
ConcurrencyDescription
ResultSet.CONCUR_READ_ONLYCreates a read-only result set. This is the default
ResultSet.CONCUR_UPDATABLECreates an updateable result set.
All our examples written so far can be written as follows, which initializes a Statement object to create a forward-only, read only ResultSet object −
try {
   Statement stmt = conn.createStatement(
                           ResultSet.TYPE_FORWARD_ONLY,
                           ResultSet.CONCUR_READ_ONLY);
}
catch(Exception ex) {
   ....
}
finally {
   ....
}

Concurrency of ResultSet

If you do not specify any Concurrency type, you will automatically get one that is CONCUR_READ_ONLY.
ConcurrencyDescription
ResultSet.CONCUR_READ_ONLYCreates a read-only result set. This is the default
ResultSet.CONCUR_UPDATABLECreates an updateable result set.
All our examples written so far can be written as follows, which initializes a Statement object to create a forward-only, read only ResultSet object −
try {
   Statement stmt = conn.createStatement(
                           ResultSet.TYPE_FORWARD_ONLY,
                           ResultSet.CONCUR_READ_ONLY);
}
catch(Exception ex) {
   ....
}
finally {
   ....
}

Monday, August 31, 2015

Java Interview Questions - Series 2

Try to solve these Java Interview questions and if not able to give answer than WhatsApp on 8800360849 to get answer.

1. What are different type of comments in Java?
2. What is the different between import and import static?
3. Can we execute some code before the entry point? If yes, how?
4. What are static blocks? How to use them?
5. Can we execute some code without entry point?
6. What is mean by command line arguments? How to use them in Java?
7. What is mean by triple dot (...) in Java?
8. What is for each loop? How and where to use it?
9. What is garbage collector? Can we forcibly call the garbage collector?
10. What is finalizer? Why and how to use it?
11. What is constructor? Can we have private constructor?
12. What is serialization? Why we need it and how to achieve it?
13. How to send and receive data using TCP/IP protocol?
14. How to send and receive data using UDP protocol?
15. What are legacy collections? Why not to be use them?
16. Which is the top level class in Java class hierarchy?
17. What are different scopes applied on the class members in Java?
18. What is JAR file? How to create and use the JAR files?
19. What is package? How to create and distribute the packages?
20. What is class library? How to create and use the class library?
21. Differentiate between String and StringBuilder class?
22. What are different types of Integral Literals in Java?
23. What is number separator in Java? How to use it?
24. How do you express an ‘is a’ relationship and a ‘has a’ relationship or explain inheritance and composition?
25. What is the difference between composition and aggregation?

Java Interview Questions - Series 1

Here are some Java interview questions you must know. If you don't know the answer then WhatsApp on 8800360849 to get answer of the question.

1. What is the different between abstract class and interface?
2. What is the difference between method overriding and method overloading?
3. What is marker interface?
4. What are factory methods?
5. What is singleton object?
6. What are different ways to use the final keyword?
7. What is ARM? How to use it?
8. What is volatile?
9. What is transient?
10. What is the difference among final, finally and finalizer?
11. What is the difference between throw and throws? Explain with example.
12. What is the different among Statement, PreparedStatement and CallableStatement?
13. What is the different between AWT and Swing?
14. Do all swing components and containers are light weight?
15. What is mean by pluggable look and feel?
16. What is auto boxing and auto unboxing?
17. What are generics? How to use the generics?
18. What is diamond operator? How to use it?
19. What is use of instanceof operator?
20. What is difference between mutable and immutable strings? How to manage them?
21. How to handle the deadlocks in threads?
22. What is mean by Inter Thread communication?
23. What is use of InetAddress class?
24. What are wrapper classes? Why and how to use them?
25. What is mean by array of array?

Tuesday, July 28, 2015

What are different types of entry points in Java?

Java provides mainly three entry points


public static void main(String args[])
public static void main(String []args)
public static void main(String... args)

or

static public void main(String args[])
static public void main(String []args)
static public void main(String... args)




How to Center a JFrame or JDialog?

Get the current size of the desktop and the size of current JFrame and divide by 2 the size difference.

Full example code

import javax.swing.*;
import java.awt.*;
public class MyWindow extends JFrame
{
    public MyWindow()
    {
       
        setSize(300,300);
       
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (int) ((screen.getWidth()-getWidth()) /2);
        int y = (int) ((screen.getHeight()-getHeight()) /2);
        setLocation(x, y);
       
        setVisible(true);
    }
    public static void main(String args[])
    {
        new MyWindow();
    }
}

Sunday, July 26, 2015

How to change Icon of the Jframe

Copy and Paste any Image file into your current project folder and use getClass() method to get reference of current folder then use its getResource() method to lookup the image file.

It returns a type of URL class from java.net package.
Load the image into memory using ImageIcon class
Now use setIconImage()  method to set the Icon image


Example

import javax.swing.*;
import java.net.*;
public class MyWindow extends JFrame
{
    public MyWindow()
    {
        URL iconURL = getClass().getResource("icon.jpg");
        ImageIcon icon = new ImageIcon(iconURL);
        setIconImage(icon.getImage());
        setSize(300,300);
        setVisible(true);
    }
    public static void main(String args[])
    {
        new MyWindow();
    }
}

How to make JFrame window Full Screen

Java provides getToolkit() method to get current environment details and then getScreentSize() of Toolkit class to get the current screen size. We can apply the size directly to the JFrame.

Solution 1

import javax.swing.*;
public class MyWindow extends JFrame
{
    public MyWindow()
    {
        setSize(getToolkit().getScreenSize());
        setVisible(true);
    }
    public static void main(String args[])
    {
        new MyWindow();
    }
}

Solution 2

import javax.swing.*;
import java.awt.*;
public class MyWindow extends JFrame 
{
    public MyWindow()
    {
        Toolkit t=getToolkit();
        Dimension d=t.getScreenSize();
        setSize(d);
        setVisible(true);
    }
    public static void main(String args[])
    {
        new MyWindow();
    }
}