0% found this document useful (0 votes)
11 views5 pages

Java CommonQuestion

The document covers various concepts in Java, including OOP principles, method overloading and overriding, interfaces, access modifiers, exception handling, and data structures. It also includes practical coding problems related to string manipulation, array operations, and algorithmic challenges. Additionally, it provides links for further learning on OOP concepts, sorting, and Java tutorials.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Java CommonQuestion

The document covers various concepts in Java, including OOP principles, method overloading and overriding, interfaces, access modifiers, exception handling, and data structures. It also includes practical coding problems related to string manipulation, array operations, and algorithmic challenges. Additionally, it provides links for further learning on OOP concepts, sorting, and Java tutorials.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

OOPs pillars

Method Overloading vs Method Overriding


What is interface? Can we create object of interface? Can an interface implement
another interface?
Static
Diff btw String, StringBuffer, StringBuilder
Can we define a static method in an interface?
Explain access modifiers private, public, protected, default. Explain default
access modifier.
Difference between abstract class and interface.
Explain super and this keyword.
Explain try, catch, finally, throw, throws keyword in java
Exception Handling, Can we handle more than one exception in single catch block?
primitive vs reference types. Where are objects in java stored stack or heap
memory.
String constraint pool
Can we create a List of any primitive datatypes like int, char (List<int> list =
new ArrayList<>();)

super() -> parent class constructor


super.field -> parent class variable, We can do super.field = value; to override
the variable in parent class
super.method() -> parent class method
How java code is executed

How will you compare to strings if the are equal


String one = "abc";
String two = "abc";
if(one == two){
}
if(one.equals(two)){
}

Collection framework: Comparable vs Comparator

***************
Discuss the logic of how to reverse a string and check whether string is a valid
palindrome

// Find Largest and second lagest number in an array


// {1, 3, 55, 12, 6}

// {11, 22, 22, 22, 22, 33}

not sorted
1 -> n
Find missing number in an array
Here, from 1 to 5
{1, 2, 4, 5}
output : 3

Find repeating number in an array


Here, from 1 to 5
{1, 2, 2, 3, 4, 5}
output : 2

*************************
sort an array
*************************

Find max substring length with similar adjacent character


Input : str = "aaabbqqqqq"
Output : 5

Input : Hello
Output : 2

Input : world
Output : 1

***************

Find frequency of vowels in a string using HashMap


String str = "ppeeuuuuuaaabnnee"
Output :
e : 4
u : 5
a : 3

***************
String data = "hello world code";

output : code world hello


***************

Solve using map and then without map using two pointer
***************
Two Sum:
Input:
number = {2, 7, 11, 15} , target = 9

Output:
{2, 7}
or
{0, 1} // index

*********************************
int num1 = 12345;
sum of digits of num1 is 15

int num2 = 825;


sum of digits of num2 is 15

if sum of digits of both number are equal then print equal


else print not equal

*********************************

String str1 = "Program";


String str2 = "XYZ";

Output : PXrYoZgram

String str1 = "ABC";


String str2 = "Laptop";

Output : ALBaCptop
*********************************
Print pattern:

11 12 13 14 15
* * * *
31 32 33
* *
51

1 2 3 4 5
* * * *
6 7 8
* *
9

* * * * *
* * * *
* * *
* *
*

11 12 13 14 15
a b c d
31 32 33
a b
51

for input of
int n=23
1 2 3 4 5
* * * * *
11 12 13 14 15
* * * * *
21 22 23

int n=27
1 2 3 4 5
* * * * *
11 12 13 14 15
* * * * *
21 22 23 24 25
* *

print using while loop and for loop

*********************************

Output Based Question:

//String, String constraint pool


How will you compare to strings if the are equal
String one = "abc";
String two = "abc";
if(one == two){
System.out.println("== operator");
}
if(one.equals(two)){
System.out.println(".equals() method");
}
//Exception Handling
try{
int result = 25/0;
}
catch(Exception e1){
System.out.println("Exception Occurred");
}
catch(ArithmeticException e2){
System.out.println("ArithmeticException Occurred");
}
catch(ClassNotFoundException e3){
System.out.println("ClassNotFoundException Occurred");
}

System.out.println(result);

//OOPs Polymorphism
class Parent{
int val1 = 10;

public void method1(){


System.out.println("method1 of Parent");
}
}

public class Child extends Parent{


int val1 = 20;
int val2 = 500;

public void method1(){


System.out.println("method1 of Child");
}

public void method2(){


System.out.println("method2 of Child");
}

public static void main(String[] args) {


Parent obj = new Child();
System.out.println(obj.val1);
obj.method1();

// Can we do
// System.out.println(obj.val2);
// obj.method2();

}
}

Can we override a static method?

// super keyword -> by default super() parent constructor is called before called
atfirst when any contructor is called
class A {
int a1 = 10;
public void m1(){
System.out.println("m1 ");//1
}s
public A(){
this.m1();
System.out.println("A Constructor");//2
}
}

https://docs.google.com/document/d/1JP27T38JEqZOJcjMWAZU3p03fmcNLHNz1vf4Fr3Ozts/
edit?usp=sharing

class B extends A{
int a1 = 20;
public void m2(){
System.out.println(this.a1);
System.out.println(super.a1);
System.out.println("M2 ");
}
public B(){
System.out.println("B Constructor");//3
}
}

public class MainClass {


public static void main(String [] args){
B a = new B();
}
}

Session
Security
DI, Lifecycle
Thread pool
cross join,
Index, Cluster index non-cluste index which is faster and why
Inmemory authtication
discovery api, reseleance, RequestPart
Difference btw callable and runnable
Thread pool, grouping

OOP quick revision -https://www.javatpoint.com/java-oops-concepts


Only do learn the basic, sorting, arrays , string
https://takeuforward.org/strivers-a2z-dsa-course/strivers-a2z-dsa-course-sheet-2/
star pattern - https://www.youtube.com/watch?
v=6irHnysGbSI&list=PL7ersPsTyYt2prN058WfA_j3ElgwD1bht
java - https://www.youtube.com/watch?
v=oveyab6lO_E&list=PLA3GkZPtsafY62QhQ030p85HAer0pFDdr

You might also like