We can reverse a String via characters as well as with words. There are multiple ways to achieve it. Below are the methods to do do the same: converting a string into an array to reverse by characters Splitting String with blank spaces to reverse by words Using the reverse() method from the StringBuffer classRead More
Java Programs
Copy formatting & style of cells from one sheet to another.
This blog contains steps to copy Formatting & Style from one Excel sheet to another sheet. Also, shows how to identify the Cell Type. To implement formatting in the excel sheet while writing data, please visit the below link: Copy Formatting & Style Below are the requirements: inputfile.xlsx file Sheet having list of few ElectronicRead More
Getting IP address and Hostname using InetAddress Class.
InetAddress class is used to represent the Internet Protocol address.getByName(hostName) returns the all the details of a given hostname. InetAddress Class Usage In the below program TM-RXTUVC4 is the name of your Computer. Once we created an object of InetAddress class. And pass hostname as an argument via getByName() all the details like IP address,Read More
User inputs via Command Prompt using arguments of main() method of a class.
There is also a third way to take user input via using Console class. This method helps a user to take inputs via Command Prompt. Before reading this post, would request you to visit below tutorial first to get more understanding on Console Class: Basic Java – 17 || Runtime User Input using Console ClassRead More
Program for List and ArrayList in Java.
Basic difference between List and ArrayList is that List is an Interface and ArrayList is a Collection class. ArrayList implements List Interface. Declaration and Initialization of List and ArrayList Traversing values in the List Using List with Integer values We can use all the methods as it is for integer values as well. Other UsefulRead More
Useful methods and implementation under Scanner Class.
To get user input at runtime we have to use Scanner Class. It contains various inbuilt methods which can be used to make user interaction more smoother and error free. Scanner Class Please visit below link to get theoretical as well as practical knowledge of Scanner Class and its methods: Basic Java – 15 || RuntimeRead More
Swapping two variable values without using any third variable.
Swapping of two values: /** * @author ashok.kumar * */ public class Swapping { public static void main(String[] args) { // TODO Auto-generated method stub int x=2; int y=5; System.out.format(“Value of x=%d and y=%d before swapping.\n”,x,y); x=x+y; // x=7 y=x-y; // y=2 x=x-y; // x=5 System.out.format(“Value of x=%d and y=%d after swapping.”,x,y); } } RelatedRead More
Difference between int x= 10 and y=010 in Java.
Logically there is no difference between 10 and 010 in numbers. But in java, there is a difference of presentation and actual values of these numbers. Int x = 10; System.out.println(x); // Output: 10 Int y = 010; System.out.println(y); // Output: 8 Exactly when we print 010 it actually prints 8 which is Octal valueRead More
Parameterized Constructors v/s Setter and Getter function in JAVA.
In my opinion, there is only a syntax difference between parameterized constructors and setter function in JAVA. Both would be used to initialize the class variables with user-defined values. In parameterized constructors, all the class variables can be initialized within one function (constructor) which is automatically invoked when a user creates an object of thatRead More
Override a Static Method.
It is possible to override a Static method. But make sure that all the methods having the same signature along with the Static keyword. package Override; /** * @author ashok.kumar * */ public class Parent { public static void printData() { System.out.println(“Parent Class.”); } } /** * */ package Override; /** * @author ashok.kumar *Read More