Posts

Explain briefly about POJO in Java?

Explain briefly about POJO in Java? POJO is Plain old java object. The class with its private attributes and the having the getter and setter method. these methods are public so any class from out side can access this attributes via the methods only not directly. Example : import java.util.Date; public class Student { private int id; private String name; private Date dob; public Date getDob() { return dob; } public void setDob(Date dob) { this.dob = dob; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } Here you can see the Student class POJO with id , name and DOB attributes and having the getter and setter methods.

How do I create an array of a string?

How do I create an array of a string? Here is the example code. public class ArrayDemo { public static void main(String[] args) { String[] strArray = new String[2]; strArray[0] = "Hello"; strArray[1] = "World !"; System.out.println(strArray[0] +" "+strArray[1]); } } Output: Hello World !

In Java, how would you create a function that prints out a string every 10 seconds?

In Java, how would you create a function that prints out a string every 10 seconds? Below is the program to print string in every 10 seconds. import java.util.TimerTask; public class PrintHelper extends TimerTask { int i = 0; @Override public void run() { System.out.println("Timer ran " + ++i); } } import java.util.Timer; import java.util.TimerTask; public class TimerTest { public static void main(String[] args) { Timer timer = new Timer(); TimerTask task = new PrintHelper(); timer.schedule(task, 0, 10000); } }  Here I am using java Timer class to print string in every specified time. Output: Timer ran 1 Timer ran 2 Timer ran 3 Timer ran 4 Timer ran 5 Timer ran 6 Timer ran 7 Timer ran 8

What are the predefined abstract classes in Java?

What are the predefined abstract classes in Java? There are many but some of them are AbstractMap<K,V>, AbstractMap<K,V>,AbstractCollection<E>,AbstractList<E>  ext.

What is abstract modifier in Java?

What is abstract modifier in Java? Abstract is keyword in java which can be used with class and the method. If You define the any method as abstract in any class then you don't need to provide the implementation of that method but, its child concrete class must have to provide the  implementation of it. If you declare any method as abstract in any class you must have to declare the class as abstract. but if the class is abstract that does not mean that you will have the abstract method in it.

How to know the compiled version of jar file or class file?

How to know the compiled version of jar file or class file? To know the complied version of the jar file or class file below is the code. You have to run the MainClass and pass the file name in the argument. You have to put jar or class file in same path of MainClass file. import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.logging.Logger; public class CheckVersionUtil { private static final Logger LOGGER = Logger.getLogger(CheckVersionUtil.class.getSimpleName()); public static void copyToTemp(String destinationDir, String srcFile) throws IOException { LOGGER.info(...

How can I find the current Java version running in my computer?

How can I find the current Java version running in my computer? To check the java running version run below command. java -version To check the running java compiler version on your computer run below command. javac -version