Forwarded from java interview Questions (Raj patel)
Without existing container object if there is a chance of existing contained objects
such type of relationship is called aggregation .
in aggregation objects have weak association. https://cjavapoint.blogspot.com/2019/12/aggregation.htmlππππππ
such type of relationship is called aggregation .
in aggregation objects have weak association. https://cjavapoint.blogspot.com/2019/12/aggregation.htmlππππππ
What is meant by Interface?
Answer: Multiple inheritances cannot be achieved in java. To overcome this problem Interface concept is introduced.
An interface is a template which has only method declarations and not the method implementation.
For more questions visit
ππhttps://cjavapoint.blogspot.com/?m=1ππ
Answer: Multiple inheritances cannot be achieved in java. To overcome this problem Interface concept is introduced.
An interface is a template which has only method declarations and not the method implementation.
For more questions visit
ππhttps://cjavapoint.blogspot.com/?m=1ππ
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
For more questions visitππhttps://cjavapoint.blogspot.com/?m=1ππ
Visit ππ https://cjavapoint.blogspot.com/?m=1ππ
What is finally and finalize in java ?
The finally block is used with try-catch to put the code that you want to get executed always, even if an exception is thrown by the try-catch block. finally block is mostly used to release resources created in the try block.
finalize() is a special method in Object class that we can override in our classes. This method gets called by the garbage collector when the object is getting garbage collected. This method is usually overridden to release system resources when the object is garbage collected.
For more questions visit πππ https://cjavapoint.blogspot.com/?m=1
The finally block is used with try-catch to put the code that you want to get executed always, even if an exception is thrown by the try-catch block. finally block is mostly used to release resources created in the try block.
finalize() is a special method in Object class that we can override in our classes. This method gets called by the garbage collector when the object is getting garbage collected. This method is usually overridden to release system resources when the object is garbage collected.
For more questions visit πππ https://cjavapoint.blogspot.com/?m=1
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
What is static import?
If we have to use any static variable or method from other class, usually we import the class and then use the method/variable with class name.
import java.lang.Math; //inside class double test = Math.PI * 5;
We can do the same thing by importing the static method or variable only and then use it in the class as if it belongs to it.
import static java.lang.Math.PI; //no need to refer class now double test = PI * 5;
Use of static import can cause confusion, so itβs better to avoid it. Overuse of static import can make your program unreadable and unmaintainable.
More questions visit https://cjavapoint.blogspot.com/?m=1 ππ
If we have to use any static variable or method from other class, usually we import the class and then use the method/variable with class name.
import java.lang.Math; //inside class double test = Math.PI * 5;
We can do the same thing by importing the static method or variable only and then use it in the class as if it belongs to it.
import static java.lang.Math.PI; //no need to refer class now double test = PI * 5;
Use of static import can cause confusion, so itβs better to avoid it. Overuse of static import can make your program unreadable and unmaintainable.
More questions visit https://cjavapoint.blogspot.com/?m=1 ππ
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
What is Marker interface?
A marker interface is an empty interface without any method but used to force some functionality in implementing classes by Java. Some of the well known marker interfaces are Serializable and Cloneable.
For More questions visit https://cjavapoint.blogspot.com/?m=1 πππ
A marker interface is an empty interface without any method but used to force some functionality in implementing classes by Java. Some of the well known marker interfaces are Serializable and Cloneable.
For More questions visit https://cjavapoint.blogspot.com/?m=1 πππ
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
Q) What are the main differences between Process and thread? Explain in brief.
1) One process can have multiple threads. A thread is a smaller part of a process.
2) Every process has its own memory space, executable code and a unique process identifier (PID) while every thread has its own stack in Java but it uses process main memory and shares it with other threads.
3) Threads of same process can communicate with each other using keyword like wait and notify etc. This process is known as inter process communication
For questions visit:-
https://cjavapoint.blogspot.com/?m=1
πππππππππ
1) One process can have multiple threads. A thread is a smaller part of a process.
2) Every process has its own memory space, executable code and a unique process identifier (PID) while every thread has its own stack in Java but it uses process main memory and shares it with other threads.
3) Threads of same process can communicate with each other using keyword like wait and notify etc. This process is known as inter process communication
For questions visit:-
https://cjavapoint.blogspot.com/?m=1
πππππππππ
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
Q) How can we create a thread in java?
There are following two ways of creating a thread:
1) By Implementing Runnable interface.
2) By Extending Thread class
ππππππππππ
There are following two ways of creating a thread:
1) By Implementing Runnable interface.
2) By Extending Thread class
ππππππππππ
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
Java program to ReverseString using ByteArrayCore java String πππππππππππππ/ Java program to ReverseString using ByteArray.
import java.lang.*;
import java.io.*;
import java.util.*;
// Class of ReverseString
class ReverseString
{
public static void main(String[] args)
{
String input = "JavaInterview";
// getBytes() method to convert string
// into bytes[].
byte [] strAsByteArray = input.getBytes();
byte [] result =
new byte [strAsByteArray.length];
// Store result in reverse order into the
// result byte[]
for (int i = 0; i<strAsByteArray.length; i++)
result[i] =
strAsByteArray[strAsByteArray.length-i-1];
System.out.println(new String(result));
}
}
Output:
weivretniavaj More java interview questions and java program visit my blog πππππhttps://cjavapoint.blogspot.com/πππππππ
import java.lang.*;
import java.io.*;
import java.util.*;
// Class of ReverseString
class ReverseString
{
public static void main(String[] args)
{
String input = "JavaInterview";
// getBytes() method to convert string
// into bytes[].
byte [] strAsByteArray = input.getBytes();
byte [] result =
new byte [strAsByteArray.length];
// Store result in reverse order into the
// result byte[]
for (int i = 0; i<strAsByteArray.length; i++)
result[i] =
strAsByteArray[strAsByteArray.length-i-1];
System.out.println(new String(result));
}
}
Output:
weivretniavaj More java interview questions and java program visit my blog πππππhttps://cjavapoint.blogspot.com/πππππππ
Asked in "TCS" exam...
ππππ
100 people standing in a circle in an order 1 to 100. No.1 has a sword. He kills next person (i.e.no. 2 )and gives sword to next to next (i.e no.3). All person does the same until only 1 survives. Which number survives at the last?
More questions visit
ππππ
https://cjavapoint.blogspot.com/
ππππ
100 people standing in a circle in an order 1 to 100. No.1 has a sword. He kills next person (i.e.no. 2 )and gives sword to next to next (i.e no.3). All person does the same until only 1 survives. Which number survives at the last?
More questions visit
ππππ
https://cjavapoint.blogspot.com/
1. What do you mean by Platform independence of java?
You can write and compile program in one Operating system and run in other operating system.
For example:
You can compile program in Windows and can run it in Unix.
2. What is difference between JVM, JRE and JDK ?
JVM : JVM stands for Java Virtual Machine. It is virtual machine which actually runs the byte code.
JRE : JRE stands for Java Runtime Environment. It provides runtime environment for java code. It has JVM , libraries such as rt.jar and other files.
JDK : JDK stands for Java development kit. It is superset of JRE, it has JRE + compilation and debugging tools(javac and java).
3. What are memory areas allocated in JVM?
Memory areas allocated in JVM are:
Heap area
Method area
JVM language stacks
Program counter (PC) register
Native method stacks
4. What are some core concepts of OOPS in Java ?
Core concepts of OOPs are :
Encapsulation
Polymorphism
Abstraction
Inheritance
https://cjavapoint.blogspot.com/
You can write and compile program in one Operating system and run in other operating system.
For example:
You can compile program in Windows and can run it in Unix.
2. What is difference between JVM, JRE and JDK ?
JVM : JVM stands for Java Virtual Machine. It is virtual machine which actually runs the byte code.
JRE : JRE stands for Java Runtime Environment. It provides runtime environment for java code. It has JVM , libraries such as rt.jar and other files.
JDK : JDK stands for Java development kit. It is superset of JRE, it has JRE + compilation and debugging tools(javac and java).
3. What are memory areas allocated in JVM?
Memory areas allocated in JVM are:
Heap area
Method area
JVM language stacks
Program counter (PC) register
Native method stacks
4. What are some core concepts of OOPS in Java ?
Core concepts of OOPs are :
Encapsulation
Polymorphism
Abstraction
Inheritance
https://cjavapoint.blogspot.com/
What do you understand by copy constructor in Java? There is no copy constructor in java. However, we can copy the values from one object to another like copy constructor in C++.
There are many ways to copy the values of one object into another in java. They are:
By constructor
By assigning the values of one object into another
By clone() method of Object class
There are many ways to copy the values of one object into another in java. They are:
By constructor
By assigning the values of one object into another
By clone() method of Object class
Core java Interview Questions for All. Aggregation
Learn java interview questions for student.learn java,core java interview question,java interview question.
Without existing container object if there is a chance of existing contained objects
such type of relationship is called aggregation .
in aggregation objects have weak association.
Example:
Within a department there may be a chance of several professors will work whenever
we are closing department still there may be a chance of existing department object the
relationship between department and professor is called aggregation where the objects
having weak association.
More Questions Visit My Blog ππππππππhttps://cjavapoint.blogspot.com/
Learn java interview questions for student.learn java,core java interview question,java interview question.
Without existing container object if there is a chance of existing contained objects
such type of relationship is called aggregation .
in aggregation objects have weak association.
Example:
Within a department there may be a chance of several professors will work whenever
we are closing department still there may be a chance of existing department object the
relationship between department and professor is called aggregation where the objects
having weak association.
More Questions Visit My Blog ππππππππhttps://cjavapoint.blogspot.com/
π1
A very simple code that should print numbers from 7 to 21. But does it?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.concurrent.TimeUnit;
class Counter extends Thread {
//instance variable
Integer count = 0;
// method where the thread execution will start
public void run() {
int fixed = 6; //local variable
for (int i = 0; i < 3; i++) {
System.out.println(Thread.currentThread().getName() + ": result="
+ performCount(fixed));
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
// letβs see how to start the threads
public static void main(String[] args) {
System.out.println(Thread.currentThread().getName() + " is executing..." );
Counter counter = new Counter();
//5 threads
for (int i = 0; i < 5; i++) {
Thread t = new Thread(counter);
t.start();
}
}
//multiple threads can access me concurrently
private int performCount(int fixed) {
return (fixed + ++count);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.concurrent.TimeUnit;
class Counter extends Thread {
//instance variable
Integer count = 0;
// method where the thread execution will start
public void run() {
int fixed = 6; //local variable
for (int i = 0; i < 3; i++) {
System.out.println(Thread.currentThread().getName() + ": result="
+ performCount(fixed));
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
// letβs see how to start the threads
public static void main(String[] args) {
System.out.println(Thread.currentThread().getName() + " is executing..." );
Counter counter = new Counter();
//5 threads
for (int i = 0; i < 5; i++) {
Thread t = new Thread(counter);
t.start();
}
}
//multiple threads can access me concurrently
private int performCount(int fixed) {
return (fixed + ++count);
}
}