0% found this document useful (0 votes)
9 views19 pages

Placement Questions For Freshers

Uploaded by

Megha Urkude
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views19 pages

Placement Questions For Freshers

Uploaded by

Megha Urkude
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Placement Questions For Freshers

(Core Java)
1)What all Datatypes you know in Java?
> byte, short, int, long, float, double, char, Boolean.

2)Can you give required for each datatype?


> byte - 1, short - 2, int – 4, long – 8, float – 4, double – 8, char – 2, Boolean – 1.

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.

4)Is String datatype?


> No it’s a in-built class in java its in java.lang.* package it has methods like
length(),toString() etc.

5)Can you define class?


> Class is Object Oriented Concept in Java. It is Entity having Properties and Operation
where Properties means Variables and Operation means Methods.

6)Can you Define Object?


> It’s a instance of class. We create object in java by using new Operator. All Members of a
class reached into the memory. We use new Operator to create Object.

7)Can you list out some in built classes in Java?


> String, System, Thread, InputStream, OutPutStream, Reader, Writer,
Object, Scanner, StringBuffer, StringBuilder.

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.

9)Can Class be a return Type of any Method?


> Yes
Ex. Int m1(){
}
Ex. Student m1(){
Student stu = new Student();
return stu; }
10)What is Block in Java? What is its Syntax? When is it getting Executed?
> Whenever we load class in memory that time statis block will get executed and non static
block will get executed before a constructor.
block Syntax is static {

}
Try & Catch also block.

11) What is Super class of all classes in Java?


> Object class is Super class of all classes in java.
Object class comes under java.lang package there are 11 methods of Object class.
Clone(), equals(), getclass(), hashcode()

12)Do you know some methods in Object class? Can you name some of them?
> toString, hashcode, equals, clone, finalize, getclass, notify, wait, notifyall.

13) What is Package and Import Keyword?


>
Package – A package in java is a mechanism to contain classes, sub packages or
interfaces. They are used to prevent naming conflicts and controlling
access in addition to make searches and utilization of classes and
interface.
Import – When we want to use one class in another class we must use the import
keyword.

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.

4.public – It can be applied to constructor, global variables, static variables, methods.


Public members are accessible everywhere, in same class, outside the class, or
any package.
16) Can you elaborate protected access pacifier in Java?
> Protected members are accessible with in a same package and in other packages as well
provided caller is in subclass and Inheritance is used.
Clone(); is the protected method

17) What is Encapsulation? Explain in brief?


> Binding of data into a single entity. By default in java get encapsulation.
Proper encapsulation can be achieved by using private global variabales and accessing
those variables through getters and setters.

18) Why global variables are recommended to be private?


> If you make private no one can call those directly and assing invalid values.
We should be accesing it through one method so that we can add some validation
if needed.

19) Can you give me any real time example of encapsulation?


> In Laptop everything is properly bound in some body.

20) Explain Inheritance briefly?


> If members of parent come to child then that concept is called as inheritance.
There are many types of inheritance available in java
Simple Inheritance – In this, there will be only one super class and one sub class.
Every class has a super class as Object, and the packages of
Object class is java.lang.Object
Multi-level Inheritance – When a class extends a class, which in turn extends another
class, Is called Multi-level inheritance.
Multiple Inheritance – One class has many super classes. This is not allowed in java.
Hierarchial Inheritance – In such kind of inheritance one class is inherited by many
sub classes. In the example below, class B, C and D inherits
the same class.

21) Give real time example of Inheritance?


> Family.. most of things of parents inherited to there kids.

22) What are types of Inheritance?


> If members of parent come to child then that concept is called as inheritance.
Types:-
Simple Inheritance – Child class acquire properties from there Parent class.
Multi-level Inheritance – Child class acquire properties from there parent class and
acquire the properties from there parent class.
Multiple Inheritance – One class has many super classes. This is not allowed in java
Hierarchial Inheritance – In that case multiple child class who acquired properties
from there parent class.
23) Can you explain advantageds of Inheritance?
>
To change methods.
To reuse features of super class.
To add some additional we use features.

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.

25) What is multilevel Inheritance?


> When a class extends a class, which in turn extends another class,
Is called Multi-level inheritance.

26) What is dynamic dispatch?


> In the case of dynamic dispatch at variables of super class always will compiled at compile
time and runtime.
In the case of method overridden method of sub class will compiled and method of
superclass will also compiled but at runtime method of subclass will get execute.

27) Can we assign subclass to super class and what will happen if we do that? at compile
time and runtime?
> Yes

28) Can private variables or methods inherit?


> No.. Because private members are only usefull in same class.

29) Explain super keyword and its syntax?


> Super in java is a keyword which is a reference variable.
It is used to refer to the immediate superclass object or instance variable.
The keyword super is placed inside a subclass to call a method from a superclass.
Syntax - super.a; , super.m1();

30) Explain this keyword and its syntax?


> This keyword in java is used inside a method or constructor of a class. It is used to refer to
a member of a current object within the instance of a method or constructor.
This represents current class object.
Syntax - this.a; , this.m1();

31) Do you know rule for writing super(), this() in a program?


> super() – Super call to constructor must be at first line of all constructors.
We strictly cannot call super() in methods in any line, this rule applies only to
super() not to super.a or super.m1();
this() – Call to constructor by using this ‘this()’ must be a first line of constructor only.
This means that we cannot add ‘this()’ anywhere other than the first line of
Constructor. Inside method ‘this()’ is not allowed.

32) What is constructor in Java?


> Constructor is a special method whose name is same as that of class name.
Constructor should not have any return type, not even void.
Constructor will be invoked by the JVM automatically whenever you create the object.

33) Can we call one constructor from another constructor?


> Yes.. we can call by creating object.

34) What will happen if we make constructor private?


> if private is applied to constructor, then we cannot create an object outside of class.

35) What are the ways to call constructors?


> super , this , create object

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.

37) Define Polymorphism?


> An entity which behaves differently in different cases is called as polymorphism
Polymorphism is useful in carrying out inheritance processes in java.
We can see polymorphism in java at compile time and runtime.
Compile time polymorphism is also called method overloading and runtime polymorphism
is called method overriding.
Example: You are using one button to switch the computer ON and OFF.

38) Give real time example of polymorphism?


> You are using one button to switch the computer ON and OFF. This is polymorphic
Behavior.

39) What is method overloading? Explain in detail all rules.


> Method overloading exists in the same class. There is no need of a superclass and subclass
relationship. Method name must be the same. Parameters must be changed.
Parameters must be different, the count of parameters does not matter.
Rules:
Access specifiers can be anything.
Return type can be anything.
Exceptions thrown can be anything.

40) What is method overriding ? explain in detail all rules.


> The process of implementing superclass method in subclass is called method overriding.
As per java principles, classes are closed for modification, so if we want to modify a
method in any class, changing the existing method is not a good idea. Instead of that, we
should extend that class and override method in child class.
Rules:
The subclass method name must be the same as superclass method name.
Subclass method parameters must be the same as superclass method parameters.
Subclass method’s return type must be the same as superclass method return type.

41) What is @Override annotation?


> @Override is the annotation which is used to make compiler check all the rules of
Overriding.
If this annotation is not written, then the compiler will apply all overriding rules only if
The superclass and subclass relation exist.
Method name same.
The parameters of both methods are some.

42) Can we override static method ?


> Static method cannot be overridden.

43) Can we override constructors ?


> Constructor cannot be overridden.

44) Can we override final methods?


> No, the methods that are declared as final cannot be overridden.

45) Can constructors be overloaded?


> Constructors can be overloaded. Overloaded constructors have the same name but the
different number of arguments.

46) What is static keyword in java?


>
Static is a keyword used for memory management.
Static means single copy storage for variable or method.
Static keyword can be applied to variables, methods, inner class and blocks.
Static members belong to class rather than instance of class.

47) Can local variable be static?


> Local variable cannot be declared as static else the compiler displays a modifier error.

48) What is difference between instance variable and static variables?


> Static variable: -
1)We can call static variable class name directly.
2)Static variable gives updated value for variable static variables will load at the same
class is loaded.
3)Static variable allocate single space for all copies of variable.
Instance variable: -
1)We can call instance variable by creating object.
2)Instance variable not gives updated value instance variable will load after constructor
calling.
3)Instance variable allocate different addresses for all copies of variables.
49) Do you know static block in java? When is it getting executed?
> Java’s static block is the group of statements that gets executed when the class is loaded
into memory by java ClassLoader.
It is used to initialize static variables of the class. Mostly it’s used to create static resources
when the class is loaded.
We cannot access non-static variables in static block.

50) Can constructor be static?


> Constructor cannot be static.

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.

52) What is final keyword in java?


>
Final keyword can be applied to variable, method and class. Final member cannot be
changed.
Java classes declared as final cannot be extended. Restricting inheritance.
Final parameters - values of the parameters cannot be changed after initialization.
Final method – can not be overridden.

53) What will happen if class is final?


> If a class is marked as final then no class can inherit any feature from the final class.
You cannot extend a final class. If you try it gives you a compile time error.

54) What will happen if variable final?


> If we initialize a variable with the final keyword, then we cannot modify its value.

55) What will happen if method final?


> If use the final keyword in a method declaration to indicate that the method cannot be
overridden by subclasses.

56) Can local variable be final?


> Yes, final is the only allowed access modifier for local variables.
Final local variable is not required to be initialized during declaration.

57) What is abstraction in Java?


>
Abstraction is a process of hiding details about implementation from the user while
letting them utilize the services or functions.
Exposing only required or important things is called abstraction.
Abstraction can be done in two ways:
# Abstract class # Interface
It is used for maintaining the standards of coding in project.
58) How to achieve Abstraction? explain in detail?
>
Abstraction is achieved by interfaces and abstract classes.
We can achieve abstraction 100% using interface.
An Abstract class is a class that is declared with an abstract keyword.

59) Can you explain Interface at least 4 points about it?


>
The Interface doesn’t have a constructor.
We cannot instantiate Interface but we can create reference variables.
It can be compiled but cannot run.
Interface can extends interface.
The Interface can extend multiple interface.

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.

62) What is garbage collection concept in java? Explain.


> Programmers do not have to worry about memory allocation and deallocation since it
automatically frees up memory for further use.
It removes unused objects.It recognizes objects that have not been referenced, and seeing
as they are not in use, it removes them.

63) How to advise or suggest garbage collection to happen?


> Garbage collection happened with System.gc() method.
gc() is static method of system class.

64) Explain System.gc()?


> System.gc() is method of garbage collection.
It is used to invoke garbage collection to perform cleanup processing.
gc(){
Runtime.getRuntime().gc();
}
65) What is use of finalize method?
> Finalize is method of garbage collection. It is invoked before object is garbage collected it
is the method of object class.

66) What is difference between final, finally and finalize?


> Final is keyword in java. Final is constant.
Finally is block in java. Finally block is concept of exception and it always execute.
Finalize is method in java. Finalize method call before object is garbage collected.

67) How to read file in Java? Can You write a program?


> With the help of InputStream we can read any file in java.
public class Example {
public static void main (string [] args) {
File path = new File(“c:/test/abc.txt”);
Int p=0;
while((p=path.read())!=1) {
char c=(char)p;
System.out.println(c);
}
}
}

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);
}
}
}

69) What is difference between FileInputStream and FileOutputStream ?


> FileInput Stream –
Input Stream read data from source once at a time.
Read next byte of data from Input Stream and return -1 at the end of File:
Close current InputStream : public int available () throws IOException
It is an abstract class that describes Stream Input
FileOutput Stream –
Output Stream write data to destination File.
Write byte to current OutputStream – public void write (int)throws IOException
Close current OutputStream : public void close() throws IOException
It is abstract class that describes stream output.
70) What is stream in Java? Can You define?
> Stream in java is a sequence of byte which makes Input output operation Feasible and
Faster. It facilitates a continuous flow of data.
All the classes required for I/O operation is given in java.Io package

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.

72) What is use of File class in Java?


> File is inbuilt class in java. This is used for file handling. It is present in java.IO package.
Used for getting path or renaming or deleting File.
Some methods of File class.
delete(), equals(), exists(), CreateNewFile(),

73) What is Serialization?


> Writing object state into any other source is called as Serialization.
Serialization is needed when there is problem to send data from one class to another class.
Where the other class is an a different location. String class and wrapper classes
implement serializable interface by default.
If the super class implements serializable interface then all its subclasses will be
serializable automatically.

74) What is De-serialization?


> De-serialization is reverse process of serialization.
In that case, byte stream recreate the actual java object in memory.
Constructor of object is never called when an object is De-serialized.

75) What is difference between Array and Collection?


>
Array –
In array once we give size then we cant adjust the size by our requirement.
Performance point of view array is faster than collection.
Memory point of view array not recommended to use.
Array hold primitive as well as object.
Array can hold only homogeneous value.
Collection –
In collection if we declare size then we can adjust size as our requirement.
Performance point of view collection if slower than array.
Memory point of view collection if recommended to use
Collection hold only object.
Collection can hold homogenous and heterogenous value.
76) What is difference between ArrayList and Vector and LinkedList?
> ArrayList, Vector and LinkedList is type of list interface.
ArrayList –
It maintain insertion order.
Iterator, ListIterator is used.
It is not synchronized.
It allow duplicate.
It maintain Index representation.
Vector –
It maintain insertion order.
Iterator, ListIterator is allow
It is synchronized.
It allow duplicate.
It maintain Index representation.
LinkedList –
It maintain insertion order.
Iterator, ListIterator is used.
It is not synchronized.
It allow duplicate.
It maintain Node representation.

77) What is difference between ArrayList and HashSet?


> They both are class of List Interface which is part of collection.
ArrayList –
Iterator and ListIerator is used.
It maintain insertion order.
It allow duplicate.
HashSet –
Iterator is used.
It maintain unordered sequence.
It does not allow duplicate.

78) What is difference between List, Set and Map?


> List and Set is part of Collection. Map is not a part of Collection.
List –
It allows duplicate value.
It maintain insertion order.
ArrayList, Vector and LinkedList are there
Set –
It does not allow duplicate value.
It does not maintain insertion order.
HashSet, LinkedList and TreeSet are there
Map –
It does not allow duplicate keys but allows duplicate values.
It does not maintain insertion order.
HashMap, LinkeHashMap, TreeMap and HashTable are there
79) Can you iterate arraylist by using Iterator ? Explain in with program ?
> Yes, we can iterate ArrayList with both Iterator and ListIterator.
Iterator itr = al.iterator();
Whereas al is reference variable of ArrayList
While (itr.hasNext()) {
Int a = itr.next();
(we assume that list is format of int)
}

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);
}

82) Can you iterate HashMap ? Explain in with program ?


> Yes,
Set s=hm.keyset();
//hm is object of hashmap
//set contain all keys
Iterator it=s.iterator();
while(itr.hasNext())
{
Int a=itr.next();
}

83) What you know about legacy classes in collection hierarchy?


> There are two legacy classes in collection Hierarchy where one is Vector and second one is
Hashtable.

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.

86) What is difference Iterator and ListIterator ?


> Iterator –
Using Iterator we can access the element of collection only in forward direction using
the hashNext() & next() methods.
You cannot add element to collection
You cannot replace the existing element with new element.
Using Iterator cannot access the index of element of collection
ListIterator –
Using ListIterator we can access the elements of collection in forward direction using
hasNext(), next() methods and in reverse direction using hasPrevious() and Previous()
methods.
You can add the element to collection.
You can replace the existing element with a new element by using Void Set.
Using Iterator access the indexes of element of collection. Using nextIndex()

87) What is difference between Collection and Collections ?


> Collection and Collections are the concept of collection framework. Where,
Collection is interface and collections is class.
Collection consist sub interface. such as List, Map, Set.
Collections consist of static utility methods. Such as Sort, Reverse.

88) What is difference between TreeSet, HashSet and LinkedHashSet?


> TreeSet –
Duplicate not allowed.
Maintain sorting order.
Null not allow.
Accessing element by Iterator.
LinkedHashSet –
Duplicate not allowed.
Maintain insertion order.
Null allow.
Accessing element by Iterator.
HashSet –
Duplicate not allowed.
Maintain un ordered.
Null allow.
Accessing element by Iterator.
89) What is difference between HashMap, TreeMap, LinkedHashMap, HashTable?
> HashMap –
Order not maintain.
Not thread safe.
Null value is allow.
TreeMap –
Maintain sorting order.
Null value allow but null key not allowed.
Not thread safe.
Linked HashMap –
Maintain insertion order.
Not thread safe.
Null value is allow.
HashTable –
Order not maintained.
Thread safe.
Null value not allow

90) What are generics in collection?


> We use generics for type safety, which means only one type of element will get added.
It does not mean Sun Microsystem has changed the add method of class ArrayList.

91) What is Runtime Exception and Compile Time Exception?


> Runtime exception means those exception while are unchecked.
The exception which are comes under runtime exception those are known as runtime
exception those are known as runtime exception and exception.
Which are comes under exception but not in runtime exception and error is called compile
time exception.
Runtime exception are ignored at the time of compilation.
Whenever compile time exception written in throws clause.
Then caller will get compile time exception if it is throws by some methods it will not get
compile time exception.

92) What is Checked Exception and Unchecked Exception?


>
Runtime exception is known as unchecked exception which are comes under in
Runtime exception in exception hierarchy.
Whereas compiletime exception in known as checked exception which are comes and
exception but not under runtime exception and error.

93) Give me examples of compile time exception?


> IOException & SQLException

94) Give me examples of run time exceptions?


> - NullPointerException
- ArrayIndexOutOfBoundException
- ArithmeticException
95) What is use of try block?
> If any chance to get exception in operation then we write that operation with exception in
try block.

96) What is use of catch block ?


> Whenever exception in try block will happen then for gives user friendly message to users
catch block will execute.
We can give any exception related message to user using catch block.

97) What is use of finally block?


> Whenever we want to execute a block always then finally block will use.
Finally block is execute always whenever it occurs exception or not

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) {
}

99) What is difference between throw and throws ?


> Throw –
You cannot throw multiple exception.
Throw is used within a method.
Java throw keyword is used to explicitly throw an exception.
Throws –
You can declare multiple exception.
Throws is used with the method signature.
Java throws keyword is used to declare an exception.

100) Explain throw and throws each with 3 points?


> Throw –
You cannot throw multiple exception.
Throw is used within a method.
Java throw keyword is used to explicitly throw an exception.
Throws –
You can declare multiple exception.
Throws is used with the method signature.
Java throws keyword is used to declare an exception.
101)Do you know any annotation in java? Please explain at least 2 annotations.
> 1. @Override – it shows that subclass method is overriding the parent class method.
2. @SuppressWarnings – it is used to suppress warnings issues by compiler.

102) What is a syntax of one dimensional array?


> int a[] = {1,2,3,4};
int []a = {1,2,3,4};
int a[] = new int[2];

103) What is a syntax of two dimensional array?


> int a[][] = new int[2][];
Int a[][] = {{1,2},{2,4}};

104) Can you reverse an array? Explain with program.


> Yes,
int arr[] = {1,2,3,4,5};
for(int I = arr.length – 1;i>=0;i--);
{
S.o.p(arr[i]);
}

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);
}

106) How to create a String object?


> String is a class in java. We can create String Object in 2 ways.
(1) String X = “hello”;
(2) String X= new String(“hello”);
In string X = “hello”; we used string pool concept
In string X = new String (“hello”); here we also use string pool concept but string will get
stored into heap memory.

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);

108) What is difference between == and equals method of String class?


> == is like equals method of object class it will check references and addresses of object
and equals method of string class check contain of string.
109) Tell me 5 methods of String class and explain each one of them with program?
> 1. toString() –
String st = new String(“JBK”);
S.O.P(st.toString());
2. equals() –
String s1 = “JBK”;
String s2 =”JBK”;
S.O.P(s1.equals(s2));
3. SubString() –
String st = “ ”;
String str = “ “;
Str = st.substring(8,17);
S.O.P(str);
4. Split();
5. IndexOf(); -
String g = new String(“Sohels”);
S.O.P(g.indexOf(‘u’));

110) What is String pool concept in Java?


> String pool is concept of String.
It is one copy storage.
It is resource management technique.
If there is X variable which have “h” value and there is Y variable which have “r” value then
it stored at once in memory only address will be different.

111) Difference between String, StringBuffer and the StringBuilder.


> String –
It is thread safe.
Stored in constant string pool.
StringBuffer –
Stored in heap memory.
It is thread safe.
StringBuilder –
Stored in heap memory.
It is not thread safe.

112) How to create a simple thread in Java?


> There are two ways to achieve thread.
1) by extends thread.
2) by implements runnable interface.
When we extends thread by thread class its trigger by using start method.
For runnable interface same

113) Define Thread?


> Every executable program is called as throws. It is used for parallel programming.
114) What is difference between thread and process?
> Thread – Every executable program is thread it is one task.
Process – In process there are multiple threads.

115) Can you explain lifecycle of Thread?


>
First we call start method.
Then we reaches to ready to run state.
Then automatically run method will get called.
Then it reaches to running state.
It may go to sleep state or web state.
After sleep state or web state it will go to ready to run state.

116) Can you write statements for JDBC connectivity?


>
Class.ForName(“com.mysql.jdbc.Driver”);
Connection con = Drivermanager get connection ()
Statement st = con.createstatement();
ResultSet rs = st.executequery (“select from student”);

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”);
}

119) What is SQL?


> SQL means structured query language. This is language used by database to do operation
with data.
220) What is DDL , DML and DCL?
> DDL – Data definition language
It is used for changing a definition of table or database.
In DDL there are alter query where we can change column name etc.
DML – Data manipulation language
In DML we change the data and manipulate data.
DCL – Data Control language
It will granting permission from database user that is administrative task.
221) What is RDBMS?
>
It is Relational Database
Where we have primary Key, Foreign Key.
It have proper structure like Rows, Coloumn.
We can apply joins.
Where we can Fire query and Fetch class.

222) Can you write select query with where condition?


> Select empname from employee where ename = ‘Sohel’;

223) Can you write update query with where condition?


> update from employee set ename = ‘Sohel’;
Where ename = ‘JCS’;

224) Can you delete query with where condition?


> delete from employee where ename
ename = ‘java’;

225) Can you write insert query?


> insert into employee (eid,ename) values (‘34’,’kiran’);

226) What is Primary Key?


>
That is column in database.
Value should be unique and not null.
Every table have multiple primary key.
It is not mandatory but it is recommended.

227) What is Foreign Key?


>
This is one of the column which is primary key of another table.
Primary key of one table can be Foreign key of another table.

128) Can you explain Memory Management in Java?


>
In java memory will get allocate when we create object.
It divided into four parts.
1)Heap memory – In heap global variable and static method will get stored.
2)Static Memory – Here method will coming so that those can execute at runtime.
3)Method Area – Byte code get stored.
4)Program Counter – To keep track of execution or sequence of a methods.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy