Placement Questions For Freshers
Placement Questions For Freshers
(Core Java)
1)What all Datatypes you know in Java?
> byte, short, int, long, float, double, char, Boolean.
3)What is default value of byte, short, int, long, float, double, Boolean, char?
> byte – 0, short – 0, int – 0, long – 0L, float – 0.0f, double – 0.0d, Boolean – False,
char – Blank, String - Null.
8)What is Difference Between Global and Local Variable? Any 3-4 Differences.
> Global Local
1.Outside of a method. 1.Inside a method.
2.Accessible across a class. 2.Accessible with in a method.
3.Initialized with Default Values. 3.We have to initialized variables.
4.We can apply access sp. static to a 4.Local variable loads on stack.
Global variables.
5.Local Variable loads on Heap.
}
Try & Catch also block.
12)Do you know some methods in Object class? Can you name some of them?
> toString, hashcode, equals, clone, finalize, getclass, notify, wait, notifyall.
14)Can we give Fully Qualified Class name instead of importing that class? If yes How to do
that?
> Yes, we can give fully qualified class name instead of importing that class.
Com.hello.B bb = new com.hello.B();
15) What are Access Modifiers/ Access Specifiers available in Java? Explain each of them in
details?
> There Four Access Specifiers.
1.private - A class cannot be private. Private access specifier can be applied to global
variable, method, constructor, and inner class only. Local variables cannot be
private but global variables can be private. If we make constructor private, we
cannot create an object of that class from other classes.
2.default – When an access specifier is not specified members of a class, then it is called
default. Default members can be accessible only within same package or folder.
3.protected - Protected members are accessible with in a same package and in other
packages as well provided caller is in subclass and Inheritance is used.
24) Why multiple Inheritance not supported in case of classes but in case of interfaces?
> In case of classes every class has default constructor and every constructor have super
keyword at first line.
Multiple inheritance are means one child class acquired from multiple parent class.
At that time child class will get confused which super class it should acquired.
27) Can we assign subclass to super class and what will happen if we do that? at compile
time and runtime?
> Yes
36) How many constructors we can have in a program? If more than one allowed What care
we need to take?
> we need take different arguments for all constructors.
51) Can we call static method and variables with object ? Why its not preferable?
> Static methods can’t access instance methods and interface variables directly. They must
use reference to object. And static method can’t use this keyword as there is no instance
for ‘this’ to refer to.
60) Can you explain abstract class at least 4 points about it?
>
Abstract class can have Constructor.
We cannot instantiate Abstract class.
If we don’t want to implement or override that method, make those methods as
abstract.
Abstract static final combinations are not allowed in java.
61) Can you list out difference between abstract class and interface?
> Abstract Class Interface
1) Constructor Present. 1) No constructor present.
2) Multiple inheritance not allowed in 2) Multiple inheritance allowed.
case of classes.
3) It has abstract and concrete methods 3) Methods are abstract only we implement
To use this class we extend it. Interfaces in class.
68) How to write text file in java? Can you write a program?
> with the help of OutputStream we can write file in java. There are many type
OutputStream like FileOutputStream, ByteArrayOutputStream etc.
public class Example {
public static void main (string [] args) {
String path =“C:/test/abc.txt”;
FileOutputStream fo = new FileOutputStream(path);
String s=”pune”;
byte b[] = s.getBytes();
fo.Write(b);
}
}
}
71) What are types of stream? explain character and byte stream?
> There are two types of stream provided by JVM.
1) Character Stream – When the I/O manages 16-bit Unicode character is called as
character stream. A Unicode set is basically type of character set
where each character corresponds to a specific numeric value. It is
used for reading only text file.
2) Byte Stream – when I/O manages 8 bit bytes of row binary data then its called as byte
stream. It is used for reading everything in the text file like .pdf, .jpg etc.
80) Can you iterate arraylist by using ListIterator? Explain in with program ?
> Yes, we can iterate ArrayList by ListIterator
ListIterator itr = al.ListIterator;
While(itr.hasNext()) {
Int a = itr.next();
}
81) Can you iterate ArrayList by using for each? Explain in with program?
> Yes, we can iterate ArrayList using for each loop.
For(int a:a1) {
System.out.println(a);
}
84) What comes under List then Set and then Map explain each of them?
> Set and List is interfaces of collection interface.
ArrayList, LinkedList and Vector are comes under List interface.
It allows duplicate value whereas it maintain insertion order.
HashSet, LinkedHashSet, TreeSet are the classes of set interface.
It does not allow duplicate values it does not maintain insertion order as well.
HashMap, LinkedHashMap, TreeMap, HashTable are comes under map interface.
It does not allow duplicate keys. it does not maintain insertion order.
85) What is difference for each and for loop? Explain in with program?
> For loop –
1)It has increment decrement.
2)we use semicolon in for loop
3)It is old approach as compare to for each loop.
For each loop –
1)It is the feature of java 1.5
2)It does not have increment decrement.
3)There are only arguments passing in for each loop.
98) Can we write multiple catch blocks for every try block? If yes, then what care we need to
take?
> Yes, we can write multiple catch blocks for every try block.
We need to take care of exception of first catch block is always sub exception of exception.
Try {
}
Catch (RuntimeException e){
}
Catch(Exception e) {
}
105) Can you iterate array by using for each loop? How?
> int arr[] = {1,2,3,4};
For (int a : arr)
{
S.o.p(a);
}
107) What is difference between equals method of object class and String class?
> Equals method are in object class as well as string class.
Method of string class is overridden in object class.
Equals method of object class is check whether reference or address of string is equal or
not and string class equals method is check whether contain of string is same or not.
String X = “JBK”;
JBK.equals(X);
117) Can you explain difference between prepared statement and statement?
>
Prepared statement and statement both are interface.
Prepared statement is SubInterface of statement interface.
Prepared statement has less features where as statement has more features.
Prepared statement uses place holders, faster , precompiled queries.
While creating object of prepared statement we need to pass SQL queries.
118) Can you explain How to retrieve data from database in java. Please explain all steps.
> class.ForName();
Connection con = DriverManager.getconnection();
ResultSet rs = st.executequery(“Select * from Student”);
While (rs.next()) {
Int a= rs.getInt(“id”);
}