Newbie Java questions

  1. If Runnable interface is better than Thread class, than why we are using Thread class? What is the need for Thread class?
  2. Why we are calling System.gc() method to garbage collection of unused object, if garbage collection is automatically done in Java by daemon thread in background process with regular interval?
  3. What is the significance of Marker interface? Why are we using, even though it has no method?
  4. Why we are always doing rs.next() in first line of while loop in retrieving data from database through result set?
  5. Please give me the details of synchronization? And which are the methods and elements used in it and why only that methods and variables?
  6. Why we are not using Java in real time based application, but instead we are using C or C++?
  7. Detail difference between 4 types of driver and their use in different different applications?
  8. Is Java code with native methods platform-independent?
  9. Why is the compiler platform-independent, while JVM is platform-dependent?\
  10. Mention different type of compilers and interpreters in Java?
This entry was posted in Java. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

59 Comments on Newbie Java questions

  1. Miriam Smith
    Posted 2/6/2007 at 10:44 pm | Permalink

    7. Detail difference between 4 types of driver and their use in different different applications?
    ODBC drivers. ODBC binary code — and in many cases, database client code — must be loaded on each client machine that uses a JDBC-ODBC Bridge. Sun provides a JDBC-ODBC Bridge driver, which is appropriate for experimental use and for situations in which no other driver is available.
    A native API partly Java technology-enabled driver.
    A net-protocol fully Java technology-enabled driver
    A native-protocol fully Java technology-enabled driver

  2. Miriam Smith
    Posted 2/6/2007 at 10:57 pm | Permalink

    9.Why is the compiler platform-independent, while JVM is platform-dependent?
    byte code is common for all but machine code is not

  3. Ann Sebastian
    Posted 2/6/2007 at 11:23 pm | Permalink

    How can we make an instance of user defined class type to an immutable object ?

    One way to do this is to make the instance final.This means the reference cannot be reassigned.

  4. Miriam Smith
    Posted 2/7/2007 at 12:02 am | Permalink

    5 Please give me the details of synchronization? And which are the methods and elements used in it and why only that methods and variables?

    5 Please give me the details of synchronization?
    And which are the methods and elements used in it
    and why only that methods and variables?

    Access to atomic operations in multithreaded applications has to be synchronized.
    Make the variables private and synchronize the code that modifies the variables.
    When a non-static method is synchronized, a lock on the current instance of the class
    whose code we are executing is acquired.
    Variables and classes can’t be synchronized only methods and blocks.
    If a thread goes to sleep, it does not release the lock.
    A thread can acquire more than one lock.
    A lock can be acquired by one thread at a time.

    To synch a non static method:

    public synchronized void synched(){
    System.out.println(”this method is synchronized.”);
    }
    or
    public void synched(){
    synchronized(this){
    System.out.println(”this method is synchronized.”);
    }
    }

    To synch a static method:
    public static synchronized void synched(){
    System.out.println(”this method is synchronized.”);
    }
    or
    public static void synched(){
    synchronized(MyClass.class){
    System.out.println(”this method is synchronized.”);
    }
    }
    or
    public static void synched(){
    Class c = Class.forName(”MyClass”);
    synchronized (c){
    System.out.println(”this method is synchronized.”);

    }
    }

    Access to static fields should be done from static synchronized methods
    Access to non-static fields should be done from non-static synchronized methods

  5. Abilash
    Posted 3/1/2007 at 1:49 am | Permalink

    If i am having a class it doesn’t want to extend any class except Thread,in this situation why don’t i use Runnable? Then what is the use of Thread Class? We can use Runnable instead of Thread right?

  6. Mohammad Ishaq
    Posted 7/9/2007 at 1:59 am | Permalink

    who told u (1)Thead is better than or equal to (2)Runnable interface to create a thread,It all ways to better to use Runnable Interface to create a thead why because u create a thread using 2 we will more features,by extending ex(Frame class in java.awt.*)it.
    if use (1) to create a thead we willnot get any features as java doesn’t support Muliple Inheritence.

  7. Dipesh Rane
    Posted 7/24/2007 at 7:30 am | Permalink

    Q8. Is Java code with native methods platform-independent?

    Ans: Java code with native methods is not platform-independent. Native means the code in context to java changes with platform so that code will be different for different operating systems.
    eg. File operations in windows will require some different mechanism
    than Linux so this code will change according to platform such sort of code is put inside native code.

  8. Dipesh Rane
    Posted 8/6/2007 at 5:25 am | Permalink

    Q2.Why we are calling System.gc() method to garbage collection of unused object, if garbage collection is automatically done in Java by daemon thread in background process with regular interval?

    Ans: Garbage collector is low priority thread. Garbage collector can not be invoked by programmer at all. It’s totally JVM dependent. Garbage collector will remove only those objects whose reference count has fallen down to zero. However programmer can make a request to invoke the garbage collector using System.gc() please note that this is only a request to JVM to invoke garbage collector this doesn’t ensure that garbage collector will be called.

    Thanks
    Dipesh

  9. Sandeep
    Posted 8/14/2007 at 1:57 am | Permalink

    If Runnable interface is better than Thread class, than why we are using Thread class? What is the need for Thread class?

    Extending the Thread class will make your class unable to extend other classes, because of the single inheritence feature in JAVA. However, this will give you a simpler code structure. If you implement runnable, you can gain better object-oriented design and consistency and also avoid the single inheritance problems.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*