Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
Core Java Interview Questions & Answers
Sponsered Links
Sponsered Links

Core Java Interview Questions & Answers

 What is the most important feature of Java?
Java is a platform independent language.

What do you mean by platform independence?

Platform independence means that we can write and compile the java code in one platform like (Windows) and we can execute the class in any other supported platform like (Linux, Solaris etc).

Is JVM platform independent?

JVM is not platform independent. It is a platform specific run time implementation provided by the vendor.

What is a JVM?

JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

Difference between JRE/JVM/JDK?

To See in Details Click on this Link:-

What is Externalizable?

- Externalizable is an Interface that covers Serializable Interface. It sends data into Streams in Compressed Format. It has two methods, that is: writeExternal (ObjectOuput out) and readExternal (ObjectInput in).

What is a pointer and does Java support pointers?

Pointer is a reference deal to a memory location. Improper treating of pointers leads to memory escapes and reliability issues hence Java doesn't support the usage of pointers.

Does Java support multiple inheritance?

Java doesn't support multiple inheritance.

Is Java a pure object oriented language?

Java is not a pure object oriented language because it uses primitive data types.

What is difference between Path and Classpath?

Path and Classpath are operating system level environment variables. Path is used define where the system can find the executables (.exe) files and Classpath is used to specify the location .class files.

Can there be an abstract class with no abstract methods in it?

- Yes

Can an Interface be final?

- No

What are local variables?

Local variables are those which are declared within a block of code like methods. Local variables should be initialized before accessing them.

Can an Interface have an inner class?

- Yes. public interface xyz{ static int i=0; void ss(); class abc{ abc(){ int j; System.out.println("In side the interface"); }; public static void main(String abc[]){ System.out.println("Interface is in"); } } }

Can we define private and protected modifiers for variables in interfaces?

- No

What modifiers are allowed for methods in an Interface?

- Only public and abstract modifiers are allowed for methods in interfaces.

What is a local, member and a class variable?

- Which variable declared within a method that is called “local” variables, which variable declared within the class (not within any methods) are called “member” variables (global variables) and which variables declared within the class (not within any methods and are defined as “static”) are called class variables.

What are the different identifier states of a Thread?

- 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

What are some alternatives to inheritance?

- 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 better 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 more difficult to re-use (because it is not a subclass).

What is instance variables?

Instance variables are those variable which is defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.

What is constant variable in Java?

The constant variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed.

Should a main method be mandatory declared in all java classes?

No it is not required. main method should be defined only if the source class is a java application.

What is the return type of the main method?

Main method doesn't return anything therefore it declared void.

Why is the main method declared static?

main method is called by the JVM yet before the instantiation of the class hence it is declared as static.

What is the argument of main method?

The main method accepts an array type of String object as an argument.

Can main method be overloaded?

Yes. You can have any number of main methods with different method signature and implementation in the class.

Can a main method be declared final?

Yes. Any inheriting class will not be able to have it's own default main method.

Why isn’t there operator overloading?

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

How do I convert a numeric IP address like into a hostname like

String hostname = InetAddress.getByName("").getHostName(); Why do threads block on I/O? - Threads block on I/O (that is enters in the waiting state) so that other threads may execute while the I/O operation is performed.

What is synchronization and why is it important?

- 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.

Is null a keyword?

- No, The null value is not a keyword.

How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?

- Unicode requires 16 bits and ASCII require 7 bits. while 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.

What are wrapped classes?

- Wrapped classes are classes that allow primitive types to be accessed as objects.

What is a native method?

- A native method is a method that is implemented in a language other than Java.

What is the catch or declare rule for method declarations?

- 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.

What is the range of the char type?

- The range of the char type is 0 to 2^16 - 1.

Sponsered Links
Latest Updates
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved