A2Z UPDATES: CORE JAVA BASIC INTERVIEW QUESTIONS AND ANSWERS FOR FRESHERS PDF VIDEOS

Tuesday, 21 May 2013

CORE JAVA BASIC INTERVIEW QUESTIONS AND ANSWERS FOR FRESHERS PDF VIDEOS

We provide all core java interview questions in that basic core java interview questions and answers,these interview questions especially for freshers who learn java who want to face interview those people so useful these core java interview questions and answers for freshers,if any body wants to pdf also we provide like core java interview questions and answers for freshers pdf. Here any body learn core java concepts as well as how companys asked interview questions in core java&core java interview questions and answers videos.

core java interview questions

core java basic interview questions and answers:

-->
1.What is the most important feature of Java?

   Java is a platform independent language.This is basic core java interview question.


2. What do you mean by platform independence?


   Platform independence means that we can write and compile the java code in one platform (eg Windows) and can    execute the class in any other supported platform eg (Linux,Solaris,etc).This is basic core java interview questions.


3. What is a JVM?

      JVM is an acronym for Java Virtual Machine ,Its is an abstract machine which provides the   runtime environment in which java bytecode can be executed.JVMs(Java Virtual Machine) are available for many hardware and software platforms(so JVM is platform dependent)

4. Are JVM's platform independent?


JVM's are not platform independent. JVM's are platform specific run time implementation provided by the vendor. 


5. What is the difference between a JDK and a JVM? 


JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM. 


6. What is a pointer and does Java support pointers?


Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.



7. What is the base class of all classes? 

java.lang.Object 


8. Does Java support multiple inheritance?


Java doesn't support multiple inheritance.


9. Is Java a pure object oriented language? 


Java uses primitive data types and hence is not a pure object oriented language.


10. Are arrays primitive data types?


In Java, Arrays are objects.


11. What is difference between Path and Classpath?


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


12. What are local variables? 


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



13. What are instance variables? 

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


14. How to define a constant variable in Java?

The 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 also. static final int PI = 2.14; is an example for constant.


15. Should a main() method be compulsorily declared in all java classes?

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


16. What is the return type of the main() method?

Main() method doesn't return anything hence declared void. 


17. Why is the main() method declared static?

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


18. What is the arguement of main() method? 

main() method accepts an array of String object as arguement.



19. Can a main() method be overloaded?

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


20. Can a main() method be declared final? 

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


21. Does the order of public and static declaration matter in main() method?

No. It doesn't matter but void should always come before main(). 


22. Can a source file contain more than one class declaration? 

Yes a single source file can contain any number of Class declarations but only one of the class can be declared as public.


23. What is a package? 

Package is a collection of related classes and interfaces. package declaration should be first statement in a java class. 


24. Which package is imported by default?

 java.lang package is imported by default even without a package declaration.



25. Can a class declared as private be accessed outside it's package?

Not possible. 


26. Can a class be declared as protected? 

A class can't be declared as protected. only methods can be declared as protected.


27. What is the access scope of a protected method?

A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package. 


28. What is the purpose of declaring a variable as final?

A final variable's value can't be changed. final variables should be initialized before using them. 


29. What is the impact of declaring a method as final?

A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation. 


30. I don't want my class to be inherited by any other class. What should i do?

You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.



31.Why wait and notify is declared in Object class instead of Thread ?

Another tough java question, how can you answer this question if you are not designed Java programming language. anyway some common sense and deep knowledge of Java programming helps to answer such tough core java interview question. See this blog post to learn Why wait and notify is declared in Object class and not in Thread.


32.Why multiple inheritance is not supported in Java ? 

I found this core Java question really tough to answer because your answer may not satisfy Interviewer, in most cases Interviewer is looking for specific points and if you can bring them, they would be happy. Key to answer this kind of tough question in Java is to prepare topic well to accommodate any follow-ups. 


33.Why Java does not support operator overloading ? 

One more similar category of tough Java question. C++ supports operator overloading than why not Java? this is the argument Interviewer will give to you and some time even say that + operator is overloaded in Java for String concatenation, Don't be fooled with such arguments. 


34.Why String is immutable in Java?

My favorite Java interview question, this is tough, tricky but same time very useful as well. Some interviewer also ask this question as Why String is final in Java. look at this post for some points which make sense on Why String is final or immutable in Java 


35.Why char array is preferred to store password than String in Java?

Another tricky Java question which is based on String and believe me there are only few Java programmer which can answer this question correctly. This is a real tough core Java interview question and again solid knowledge of String is required to answer this. 


36.How to create thread-safe singleton in Java using double checked locking? 

This Java question is also asked as What is thread-safe singleton and how to do you write it. Well Singleton created with double checked locking before Java 5 was broker and its possible to have multiple instance of Singleton if multiple thread try to create instance of Singleton at same time. from Java 5 its easy to create thread safe Singleton using Enum. but if interviewer persist with double checked locking then you have to write that code for them. remember to use volatile variable. See 10 Java singleton interview question for more details on this topic.


37.Write Java program to create deadlock in Java and fix it ?

One of the classical but tough core Java interview question and you are likely to fail if you have not involved in coding of multi-threaded concurrent Java application. 


38.What happens if your Serializable class contains a member which is not serializable? How do you fix it? 

Any attempt to Serialize that class will fail with NotSerializableException, but this can be easily solved by making that variable transient for static in Java. See Top 10 Serialization interview question answers in Java for more details.


39.Why wait and notify called from synchronized method in Java? 

Another tough core Java question for wait and notify. They are called from synchronized method or synchronized blockbecause wait and modify need monitor on Object on which wait or notify get called. 


40.Can you override static method in Java?

if I create same method in subclass is it compile time error? No you can not override static method in Java but its not a compile time error to declare exactly same method in sub class, That is called method hiding in Java. 


41. How could Java classes direct program messages to the system console, but error messages, say to a file? 

The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed: Stream st = new Stream (new FileOutputStream (“techinterviews_com.txt”)); System.setErr(st); System.setOut(st); 

42. What’s the difference between an interface and an abstract class?

An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class. 

43. Why would you use a synchronized block vs. synchronized method?

Synchronized blocks place locks for shorter periods than synchronized methods.

44. Explain the usage of the keyword transient?

This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).

45. How can you force garbage collection? 

You can’t force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.

46. How do you know if an explicit object casting is needed?

If you assign a superclass object to a variable of a subclass’s data type, you need to do explicit casting. For example: Object a;Customer b; b = (Customer) a; When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.

47. What’s the difference between the methods sleep() and wait()?

The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread. 

48. Can you write a Java class that could be used both as an applet as well as an application?

Yes. Add a main() method to the applet.

49. What’s the difference between constructors and other methods? 

Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times. 

50. Can you call one constructor from another if a class has multiple constructors?

Yes. Use this() syntax.

51. Explain the usage of Java packages?

This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes. 

52. If a class is located in a package, what do you need to change in the OS environment to be able to use it? 

You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let’s say a class Employee belongs to a package com.xyz.hr; and is located in the file c:/dev/com.xyz.hr.Employee.java. In this case, you’d need to add c:/dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows: c:>java com.xyz.hr.Employee.

53. What’s the difference between J2SDK 1.5 and J2SDK 5.0?

There’s no difference, Sun Microsystems just re-branded this version.

54. What would you use to compare two String variables – the operator == or the method equals()? 

I’d use the method equals() to compare the values of the Strings and the = = to check if two variables point at the same instance of a String object

55. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?

 Yes, it does. The FileNoFoundException is inherited from the IOException. Exception’s subclasses have to be caught first. 

56. Can an inner class declared inside of a method access local variables of this method? 

It’s possible if these variables are final. 

57. What can go wrong if you replace && with & in the following code: 
String a=null; if (a!=null && a.length()>10) {…} A single ampersand here would lead to a NullPointerException.

58. What’s the main difference between a Vector and an ArrayList?

Java Vector class is internally synchronized and ArrayList is not.

59. When should the method invokeLater()be used?

This method is used to ensure that Swing components are updated through the event-dispatching thread.

60. How can a subclass call a method or a constructor defined in a superclass? 

Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass’s constructor.

61. What’s the difference between a queue and a stack? 

Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule.

62. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces? 

Sometimes. But your class may be a descendant of another class and in this case the interface is your only option.

63. What comes to mind when you hear about a young generation in Java?

Garbage collection. 

64. What comes to mind when someone mentions a shallow copy in Java? 

Object cloning.

65. If you’re overriding the method equals() of an object, which other method you might also consider? 

hashCode()

66. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use: ArrayList or LinkedList?

ArrayList

67. How would you make a copy of an entire Java object with its state?

Have this class implement Cloneable interface and call its method clone().

68. How can you minimize the need of garbage collection and make the memory use more effective?

Use object pooling and weak object references.

69. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?

If these classes are threads I’d consider notify() or notifyAll(). For regular classes you can use the Observer interface.

70. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?

You do not need to specify any access level, and Java will use a default package access level.





core java interview question and answers videos:




more core java interview questions coming soon....


No comments :

Post a Comment