Java 80:20
Java SE Guide,Java Tutorial,amit,amit manjhi,java, spring, sql,plsql,pl sql,webservices,oracle,java tutorial, interview questions,interview coding,java2080,java 20:80,manjhi,2080,amit manjhi 2080,amit manjhi 2080 blogger, amitin2019, manjhi blogger,java interview questions, java blog,amit manjhi software engineer,amit manjhi,
Sunday, June 15, 2025
Java 8 , ways to print List
package com.test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class PrintingList {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("System");
list.add("org");
System.out.println("--------using toString() to print list----------");
System.out.println(list);
System.out.println("--------using iterator to print list----------");
Iterator<String> i = list.iterator();
while(i.hasNext())
{
System.out.println(i.next());
}
System.out.println("--------using For loop to print list----------");
for(int j = 0 ;j<list.size();j++)
{
System.out.println(list.get(j));
}
System.out.println("--------using Enhanced For loop to print list----------");
for(String item : list)
{
System.out.println(item);
}
System.out.println("--------using foreach() with lamda to print list----------");
list.forEach(x->System.out.println(x));
// Here we are using forEach() or List. it takes Consumer functional Interface as paramer. Consumer Funtional Interface has accept() abstract method. So we are basically implementing accept() in forEach() using lamda expression.
}
}
--------using toString() to print list----------
[System, org]
--------using iterator to print list----------
System
org
--------using For loop to print list----------
System
org
--------using Enhanced For loop to print list----------
System
org
--------using foreach() with lamda to print list----------
System
org
Friday, August 12, 2022
Interview Codings
Reverse String
-------------------------
package strings;
public class Reverse_String {
public static void main(String[] args)
{
String original_string1 = "aidnI";
String original_string2 = "aidnI si taerg";
char[] ch = original_string1.toCharArray();
for(int i = ch.length-1;i>=0;i--)
{
System.out.print(ch[i]);
}
}
}
Thursday, November 19, 2020
Sunday, January 12, 2020
Get All Methods of Objects Class
import java.lang.reflect.Method;
public class Show_Methods {
public static void main(String[] args) throws ClassNotFoundException
{
int count = 0;
Class c = Class.forName("java.lang.Object");
Method[] m = c.getDeclaredMethods();
for(Method m1 : m)
{
count++;
System.out.println(m1.getName());
}
System.out.println("Total No. of Methods: "+count);
}
}
----------------------------------------------------------------
OutPut:
---------
finalize
wait
wait
wait
equals
toString
hashCode
getClass
clone
notify
notifyAll
registerNatives
Total No. of Methods: 12
Different ways to create objects in Java
ways to create objects in Java
This is the most common way to create an object in java. I read somewhere that almost 99% of objects are created in this way.
MyObject object = new MyObject();
If we know the name of the class & if it has a public default constructor we can create an object in this way.
MyObject object = (MyObject) Class.forName("subin.rnd.MyObject").newInstance();
MyObject anotherObject = new MyObject(); MyObject object = anotherObject.clone();
Object deserialization is nothing but creating an object from its serialized form.
ObjectInputStream inStream = new ObjectInputStream(anInputStream );
MyObject object = (MyObject) inStream.readObject();
Monday, January 6, 2020
TryLock game
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
class MyThread4 extends Thread
{
static ReentrantLock l = new ReentrantLock();
MyThread4(String name)
{
super(name);
}
@Override
public void run()
{
do
{
try {
if(l.tryLock(5000,TimeUnit.MICROSECONDS))
{
System.out.println(Thread.currentThread().getName()+" ..Got Lock and running safe code");
Thread.sleep(30000);
l.unlock();
System.out.println(Thread.currentThread().getName()+" ..Released the lock");
break;
}
else
{
System.out.println(Thread.currentThread().getName()+" ..Unable to get Lock and executing alternative code");
Thread.sleep(5000);
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
while(true);
}
}
public class ReentrantLock_Demo4
{
public static void main(String[] args)
{
MyThread4 mtt1 = new MyThread4("F1 Thread");
MyThread4 mtt2 = new MyThread4("F2 Thread");
mtt1.start();
mtt2.start();
}
}
-
Exception in thread "main" java.lang.IllegalStateException: Cannot get a STRING value from a NUMERIC cell at org.apache.poi.xss...
-
package multithreading; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; class MyThread4 extends...
-
package multithreading; import java.util.concurrent.locks.ReentrantLock; class MyyThread extends Thread { static ReentrantLock l = n...

