java interview Questions
4.23K subscribers
61 photos
23 files
159 links
java interview questions for beginners
Any promotion for
rajp6133@gmail.com
Download Telegram
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
😊😊😊😊😊😊😊😊😊
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

πŸ‘πŸ‘πŸ‘πŸ˜ŠπŸ˜ŠπŸ˜ŠπŸ˜ŠπŸ˜ŠπŸ˜ŠπŸ˜Š
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/πŸ‘ˆπŸ‘ˆπŸ‘ˆπŸ‘ˆπŸ‘ˆπŸ‘ˆπŸ‘ˆ
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/
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/
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
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/
πŸ‘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);

    }

}

 
What is wrong in this code
Q1. What is a thread?
A1. It is a thread of execution in a program. The JVM (i.e. process) allows an application to have multiple threads of execution running concurrently. In the Hotspot JVM there is a direct mapping between a Java Thread and a native operating system (i.e. OS) Thread. When a thread terminates, all resources for both the native and Java thread are released.

Q2. What are the JVM created threads?
A2. The main thread and a number of background threads.

1) main thread, which is created as part of invoking the main(…) method

https://cjavapoint.blogspot.com/
πŸ‘1
3) Garbage Collection low priority background thread for minor GC activities. Minor GC evicts the objects in the β€œEden” and β€œSurvivor” part of the heap.

4) Compiler background thread to compile byte code to native code at run-time.

5) Other background threads such as signal dispatcher thread and periodic task thread.

Q3. What is the key difference between a process and a thread?

A3. A process is an execution of a program but a thread is a single execution sequence within the process. A process can contain multiple threads. A thread is sometimes called a lightweight process.