java4all@1986 java. Powered by Blogger.

>> Saturday, June 25, 2011

Q).what is a the difference between System.err and System.out
A)
.We can redirect System.out to another file but we cannot redirect System.err stream.

Q).What are  the differences between an abstract class and an interface?
A)
.An abstract class can have concrete method, which is not allowed in an interface. Abstract class can have private or protected methods and variables and only public methods and variables are allowed in interface. We can implement more than one interface , but we can extend only one abstract class. Interfaces provides loose coupling where as abstract class provides tight coupling.

Q).What is the difference between synchronized block and synchronized method ?
A)
.Synchronized blocks place locks for the specified block where as synchronized methods place locks for the entire method.

Q).How can you force garbage collection in java?
A)
.You cannot force Garbage Collection, but you can request for it by calling the method System.gc().  But it doesn't mean that Garbage Collection will start immediately. The garbage collection is a low priority thread of JVM.

Q).How can you call a constructor from another constructor ?
A).
By using this() reference.

Q).How can you call the constructor of super class ?
A).
By using super() syntax.

Q).What's the difference between normal methods and constructors?
A)
.Constructors must have the same name of the class and can not have a return type. They are called only once,  while regular methods can be called whenever required. We cannot explicitly call a constructor.

Q).What is the use of packages in java ?
A)
.Packages are a way to organize files in java when a project consists of more than one module. It helps in resolving name conflicts when different modules have classes with the same names.

Q).What must be the order of catch blocks when catching more than one exception?
A).
The sub classes must come first. Otherwise it will give a compile time error.

Q).How can we call a method or variable of the super class from child class ?
A)
.We can use super.method() or super.variable syntax for this purpose.

Q).If you are overriding equals() method of a class, what other methods you might need to override ?
A).
HashCode

Q).How can you create your own exception ?
A).
Our class must extend either Exception or its sub class.

Q).What is serialization ?
A).
Serialization is the process of saving the state of an object.

Q).What is de-serialization?
A).
De-serialization is the process of restoring the state of an object.

Read more...

Q).Why threads block or enters to waiting state on I/O?
A)
.Threads enters to waiting state or block on I/O because other threads can execute while the I/O operations are performed.

Q).What are transient variables in java?
A)
.Transient variables are variable that cannot be serialized.
   
Q).What is synchronization
A)
.Synchronization is the ability to control the access of multiple threads to shared resources. Synchronization stops multithreading. With synchronization , at  a time only one thread will be able to access a shared resource.

Q).What is List interface ?
A).
List is an ordered collection of objects.
       
Q).What is a Vector
A).
Vector is a grow able array of objects.

Q).What is the difference between yield() and sleep()?
A)
.When a object invokes yield() it returns to ready state. But when an object invokes sleep() method enters to not ready state.
       
Q).What are Wrapper Classes ?
A)
.They are wrappers to primitive data types. They allow us to access primitives as objects.
       
Q).Can we call finalize() method ?
A).
Yes.  Nobody will stop us to call any method , if it is accessible in our class. But a garbage collector cannot call an object's finalize method if that object is reachable.

Q).What is the initial state of a thread when it is created and started?
A).
The thread is in ready state.

Q).Can we declare an anonymous class as both extending a class and implementing an interface?
A)
.No. An anonymous class can extend a class or implement an interface, but it cannot be declared to do both

Q).What is the use of the finally block?
A)
.Finally is the block of code that executes always. The code in finally block will execute even if an exception is occurred. finally will not execute when the user calls System.exit().

Q).    What is an abstract method ?
A).
    An abstract method is a method that don't have a body. It is declared with modifier abstract.

Read more...

Q).Why do threads block on I/O? 
A).Threads block on i/o (that is enters the waiting state) so that other threads may execute while the I/O operation is performed.

Q).What is synchronization and why is it important?
A).With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object’s value. This often leads to significant errors.

Q).Is null a keyword?
A).The null value is not a keyword.

Q).Which characters may be used as the second character of an identifier,but not as the first character of an identifier? 
A).The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.

Q).What modifiers may be used with an inner class that is a member of an outer class? 
A).A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.

Q).How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters? 
A).Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.

Q).What are wrapped classes? 
A).Wrapped classes are classes that allow primitive types to be accessed as objects.

Q).What restrictions are placed on the location of a package statement within a source code file? 
A).A package statement must appear as the first line in a source code file (excluding blank lines and comments).

Q).What is the difference between preemptive scheduling and time slicing? 
A).Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.

Q).What is a native method?
A).A native method is a method that is implemented in a language other than Java.

Q).What are order of precedence and associativity, and how are they used?
A).Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left.

Q).What is the catch or declare rule for method declarations? 
A).If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause.

Q).Can an anonymous class be declared as implementing an interface and extending a class? 
A).An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

Q).What is the range of the char type? 
A).The range of the char type is 0 to 2^16 - 1.

Read more...

Q).Can there be an abstract class with no abstract methods in it?
A).Yes

Q).Can an Interface be final? 
A).No

Q).Can an Interface have an inner class?
A).Yes.
public interface abc
 {
  static int i=0; void dd();
  class a1
  {
   a1()
   {
    int j;
    System.out.println("inside");
   };
   public static void main(String a1[])
   {
    System.out.println("in interfia");
   }
  }
 }

Q).Can we define private and protected modifiers for variables in interfaces? 
A).No

Q).What is Externalizable? 
A).Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)

Q).What modifiers are allowed for methods in an Interface? 
A).Only public and abstract modifiers are allowed for methods in interfaces.

Q).What is a local, member and a class variable? 
A).Variables declared within a method are “local” variables. Variables declared within the class i.e not within any methods are “member” variables (global variables). Variables declared within the class i.e not within any methods and are defined as “static” are class variables.

Q).What are the different identifier states of a Thread?
A).
The different identifiers of a Thread are: R - Running or runnable thread, S - Suspended thread, CW - Thread waiting on a condition variable, MW - Thread waiting on a monitor lock, MS - Thread suspended waiting on a monitor lock.

Q).What are some alternatives to inheritance? 
A).Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).

Q).Why isn’t there operator overloading? 
A).Because C++ has proven by example that operator overloading makes code almost impossible to maintain. In fact there very nearly wasn’t even method overloading in Java, but it was thought that this was too useful for some very basic methods like print(). Note that some of the classes like DataOutputStream have unoverloaded methods like writeInt() and writeByte().

Q).What does it mean that a method or field is “static”? 
A).Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That’s how library methods like System.out.println() work. out is a static field in the java.lang.System class.

Q).How do I convert a numeric IP address like 192.18.97.39 into a hostname like java.sun.com?
A).String hostname = InetAddress.getByName("192.18.97.39").getHostName.

Read more...

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP