## Java Interview Questions

- 0of 0 votes
what is the difference between internal repository and internet repository?

- 0of 0 votes
what about your project performance...how can i answer this question?

- 0of 0 votes
How to convert http to https in java....can anyone knows please tell me?

- 2of 2 votes
Given a String with print all the possible combinations of the all the characters in the string as a string for Example

"abc" is the input the you should print the below:

abc

ab

ac

a

bc

b

c

There is one invisible string which is actually a blank string.

- 0of 0 votes
Given a string that contains exactly a single pair of parenthesis, return parenthesis and their contents, so "xyz(abc)123" yields "(abc)". etc.

Condition: You are not allowed to use a variable anywhere, Regex is not allowed.

- 0of 0 votes
Given a string that contains exactly a single pair of parenthesis, return parenthesis and their contents, so "xyz(abc)123" yields "(abc)". etc.

Condition: You are not allowed to use a variable anywhere.

- 0of 0 votes
Write a java program for Fibonacci series...in this format

{1, 1, 2, 3, 5, 8, 13, 21, 34, 55,}print {1,1,#,3,5,#,13,21,#,55}instead of even numbers print #..how to solve this question

- 0of 0 votes
String="welcome bangalore" i want erolagnab welcome how to reverse this string..can anyone knows pls answer this one.

- 0of 0 votes
int[] a1={1,3,5,7} int[] a2={3,6,8,9} int[] a3={}...

Merge first two arrays in a sorted order result put it in third array output will be{1,3,3,5,7,8} write a code for this one?

- 0of 0 votes
write a java program consider a text file,that file is having N number of lines.how to print last N lines..

- 0of 0 votes
string[][] names={{"perk","parker"},{"jhon","raj"},{"ram","lakshman"}};

write a java program print lastname,then firstname in sorted order without using string.compareTo,collections.sort,arrays.sort

- 0of 0 votes
Lakshmi is a primary school teacher. She wants to give some laddus to the children in her class. All the students sit in a line and each of them has a rating score according to his or her usual performance. Lakshmi wants to give at least 1 laddu for each child. Children get jealous of their immediate neighbors, so if two children sit next to each other then the one with the higher rating must get more laddus. Lakshmi wants to save money, so she wants to minimize the total number of laddus.

Tip: Please understand the question clearly and pay good attention to below provide - sample input and output - completely in order to arrive at correct solution.

Input

The first line of the input is an integer N, the number of children in Lakshmi's class. Each of the following N lines contains an integer indicates the rating of each child.

Ouput

Output a single line containing the minimum number of laddus Lakshmi must give.

Explanation

Sample Input

3

1

2

2

Sample Ouput

4

Explanation

The number of laddus Lakshmi must give are 1, 2 and 1.

- 0of 0 votes
Base class is given you need to stop exposing the base class methods without touching the base class at all.

- -1of 1 vote
The boggle game - given a 2d array of characters

- 0of 0 votes
Evaluate a given mathematical expression, taking into consideration the BODMAS rule. The expression contains no brackets.

- 0of 0 votes
Serialize and deserialize a tree.

Given a tree - not necessarily a binary tree - the serialize method should create a string for the tree. The deserialize method should be able to reproduce the same tree using the string derived from the serialize method.

Basically, serialize() takes in a tree and returns a string, deserialize() takes in a string and returns the tree.

- 0of 0 votes
String d1="7 dec 2012";

String d2="15 dec 2012";

String d3="12 dec 2012";

String d4="16 dec 2012";

String d5="16 dec 2012";

String d6="24 dec 2012";

days between d1 and d2 is: 9

days between d3 and d4 is: 1 (12 dec to 15 dec counted in d1 and d2, don't count overlapping days)

days between d3 and d4 is: 8 (16 dec counted in d3 and d4, don't count overlapping days)

now final output should be: 9 + 1 + 8=18

- 1of 1 vote
Given a string (for example: "a?bc?def?g"), write a program to generate all the possible strings by replacing ? with 0 and 1.

Example:

Input : a?b?c?

Output: a0b0c0, a0b0c1, a0b1c0, a0b1c1, a1b0c0, a1b0c1, a1b1c0, a1b1c1.

- 0of 0 votes
`Given the following directory structure: org | -- Robot.class | -- ex |-- Pet.class | |-- why |-- Dog.class And the following source file: class MyClass { Robot r; Pet p; Dog d; Which statement(s) must be added for the source file to compile? (Choose all that apply.) A. package org; B. import org.*; C. package org.*; D. package org.ex; E. import org.ex.*; F. package org.ex.why; G. package org.ex.why.Dog;`

- 0of 0 votes
Here is a small program which will be of my help.

Please code it in JAVA. If you are successful, please send me the code as early as possible by tomorrow.

If you are not able to get, please send me the update.

The Definition is given as below:

1. A File contains string for Example: GCDNPQACKSPEGF...FIM

2. Read each character from this file and ASSIGN the values as below:

A,C,S = 3

F,D,N,T= 4

P,F,Y = 9

M,E,G = 2

Q,H,I,K,R,L = 6

3. AFTER ASSIGNING CHECK THE FILE FOR MAPPING

4. Sum THE VALUES in that sequence for Eg: 2+ 3+ 4...... = SUM = 60

5. FIND THE total LENGTH of the sequence for E: L = 20

6. Find the AVERAGE A = SUM/L =60/20 =3

7. USE THE PATTERNS as triplets from the same file as given below AND CALCULATE EACH PATTERN'S WEIGHTAGE as for Eg:

GCD = 2 + 3 + 4 = 9 (G = 2, C=3, D=4 from the mapping)

CDN = 3+4+4 = 11

...........

for all possible patterns

8. FinD THE MAXIMUM OF ALL THE PATTERN'S WEIGHTAGE

So, the o/p should be : Average -->

Triplet and its Weightage as :GCD : 2 + 3+ 4 = 9 for all possible triplets

Maxi Weightage -->

- 0of 0 votes
A matrix will be given which contains nos. and dots. will have to output another matrix in which the nos. are surrounded by single loop. the value of each number in a matrix equals the number of lines surrounding it.

Empty spaces in matrix/dots may be surrounded by any number of lines.

When completed, the solution forms a single continuous loop with no crossings or branches.

Value of each no. should connect the adjacent dots horizontally and vertically so that the lines form a simple loop with no loose ends based on the above rules.

eg

input Matrix

1.31.3

...3..

.3.21.

.02.1.

..2...

2.23.3

output Matrix

- -

1 .|3|1 .|3|

- - | - |

|. . .|3|. .|

| - - -

|.|3|. 2 1|.

- - - _

. 0 2 .|1 .|

- - - -

|.|.|2 . .|.

| - - -

|2 . 2|3|. 3|

- - - - -

i tried making rules and then call the function to make lines, but couldnt succeed in gettin desired output.

for any queries please comment

- 0of 0 votes
A matrix will be given which contains nos. and dots. will have to output another matrix in which the nos. are surrounded by single loop. the value of each number in a matrix equals the number of lines surrounding it.

Empty spaces in matrix/dots may be surrounded by any number of lines.

When completed, the solution forms a single continuous loop with no crossings or branches.

Value of each no. should connect the adjacent dots horizontally and vertically so that the lines form a simple loop with no loose ends based on the above rules.

eg

input Matrix

1.31.3

...3..

.3.21.

.02.1.

..2...

2.23.3

output Matrix

- -

1 .|3|1 .|3|

- - | - |

|. . .|3|. .|

| - - -

|.|3|. 2 1|.

- - - _

. 0 2 .|1 .|

- - - -

|.|.|2 . .|.

| - - -

|2 . 2|3|. 3|

- - - - -

i tried making rules and then call the function to make lines, but couldnt succeed in gettin desired output.

for any queries please comment

- 0of 0 votes
Multiple threads are running in my program. Exception occurs in one of the thread. There is no exception handling done.

What will happen to my program? Will it terminate the complete program? What will happen to other threads?

- 0of 0 votes
i) Explain Polymorphism

ii) Output of the below code snippet :-`public class ParentTest { public int x = 0; public void print() { System.out.println("In Parent"); } } public class ChildTest extends ParentTest { public int x = 1; public void print() { System.out.println("In Child"); } public static void main( String args[] ) { ParentTest s = new ChildTest(); System.out.println(s.x); s.print(); } }`

- 0of 0 votes
In synchronous request from browser how do you get results if you have to access 2 different databases

- 0of 0 votes
In assembly line situation, how do you pass a job from thread1 to thread2 to thread3?

- 0of 0 votes
in a web request you want to send results to the browser/client only if the caching operation goes success. how do you accomplish this.

- 0of 0 votes
`public class Gen { public static void main(String[] args) { Integer i1 = new Integer(1); Integer i2 = new Integer(1); System.out.println(i1 != i2); System.out.println(i1 <= i2); System.out.println(i1 >= i2); } }`

WHY THE OUTPUT IS TRUE IN ALL CASES?

- 0of 0 votes
public class Gen {

public static void main(String[] args) {

Integer i1 = new Integer(1);

Integer i2 = new Integer(1);

System.out.println(i1 != i2);

System.out.println(i1 <= i2);

System.out.println(i1 >= i2);

}

}

- 0of 0 votes
A non-empty zero-indexed array A consisting of N integers is given. The leader of this array is the value that occurs in more than half of the elements of A.

Write a function:

int arrLeader(int A[], int N);

int arrLeader(NSMutableArray *A);

int arrLeader(const vector<int> &A);

class Solution { int arrLeader(int[] A); }

class Solution { public int arrLeader(int[] A); }

function arrLeader(A);

function arrLeader(A)

function arrLeader($A);

function arrLeader(A : array of longint; N : longint) : longint;

def arrLeader(A)

sub arrLeader { my (@A)=@_; ... }

def arrLeader(a)

Private Function arrLeader ( A As Integer() ) as Integer

that, given a non-empty zero-indexed array A consisting of N integers, returns the leader of array A. The function should return -1 if array A does not contain a leader.

Assume that:

l N is an integer within the range [1..1,000,000];

l each element of array A is an integer within the range [0..2,147,483,647].

For example, given array A consisting of ten elements such that:

A[0] = 4 A[1] = 2 A[2] = 2 A[3] = 3 A[4] = 2 A[5] = 4 A[6] = 2 A[7] = 2 A[8] = 6 A[9] = 4

the function should return -1, because the value that occurs most frequently in the array, 2, occurs 5 times, and 5 is not more than half of 10.

Given array A consisting of five elements such that:

A[0] = 100 A[1] = 1 A[2] = 1 A[3] = 50 A[4] = 1

the function should return 1.

Complexity:

l expected worst-case time complexity is O(N);

l expected worst-case space complexity is O(1), beyond input storage (not counting the storage required for input arguments).

Elements of input arrays can be modified.

// you can also use includes for example:

// #include <algorithm>

int arrLeader ( const vector<int> &A ) {

// write your code here

}