Java interview questions

Java interview questions

Interview Question for Experience

Interview Question for Experience / Fresher
=======================================
1) What is Singleton ? and write a program for Singleton Class.

2) What are the conditions to be followed while we go for Singleton class?

3) How to remove the spaces in the given String ?

Note: Should not use String methods, and StringBuffer.
Eg:
Input : Java is easy and interesting
Output: Javaiseasyandinteresting
Use the Best Approach.

solution : String s = "Java is easy and interesting";
for(int i=0 ;i<s.length();i++){
if(s.charAt(i)==' ')

{
System.out.print("");
}
else{
System.out.print(s.charAt(i));
}
}

 
4)  What is daemon thread?

Ans: Daemon thread is a low priority thread. It runs intermittently in the back ground, and takes care of the garbage collection operation for the java runtime system. By calling setDaemon() method is used to create a daemon thread.

5) Write a program to replace the new character in the String.

 You can use anything.
Example:
Enter the String :
Java is easy and interesting.
Enter the character which is to be modified :
a
Enter the new character :
$
Output:
J$v$ is e$sy $nd interesting.

 6) Write a program to remove the duplicate characters. You can use anything.

Eg :
Input : Java is easy and interesting
Output: Jav iseyndtrg
Give the complete program. We will see how many are trying !!!


java interview questions

What will be the output of the program ?
‪#‎include‬< stdio.h >
int main()
{
char str1[] = "Hello";
char str2[] = "Hello";
if(str1 == str2)
printf("Equal ");
else
printf("Unequal ");
return 0;
}
 

Basic Programs Of Java

Find the O/P

class Hello { public static void main(String args[]) { System.out.println("Hello World"); } }

Find the O/P

class A { public static void main(String args[]) { System.out.print("done"); } }

Find the O/P

class C { public static void main(String args[]) { System.out.println("Hello to all"); System.out.println("Hello to all"); System.out.println("Hello to all"); } }

Find the O/P

class D { public static void main(String args[]) { System.out.println("Hello to all"); System.out.println(1000); System.out.println('a'); System.out.println(10.99); System.out.println(); System.out.println(100+100); System.out.println(100==2000); System.out.println(10!=40); } }

Find the O/P

class E { public static void main(String args[]) { int i = 10; System.out.println(i); i = 20; //Reinitialization System.out.println(i); } }

Find the O/P

class F { public static void main(String args[]) { int i; i = 10; System.out.println(i); } }

Find the O/P

class G { public static void main(String args[]) { int i = 20; int j = i; System.out.println(i); System.out.println(j); } }
 

No comments:

Post a Comment