How to Print Colored Text Console Output in Java

While programming in Java sometimes you may need to print the output of the program in the console to testing and debugging the program. While program throws many exceptions and prints tens of lines in the console, you may find it difficult to find the actual exception message.

In this case, it is good practice to change the color of the particular exception message so that we can easily debug the program and it will make our work easier.

There is another need to modify the output color of text while you are writing the command line application. It is a good Idea to change the color of the particular output line to highlight the main point of the output.

I find this trick useful while programming such type of command line tool and the debugging the web and desktop application.

You can also use this tricks to change the console output color using system.out.print() function in Java.

However this DOS / Window doesn’t support the ANSI colored character so that you won’t be able to run this program correctly in the Windows Command Prompt. You can use the console of the IDE like Eclipse, NetBeans etc and the any Linux distro terminal.

Change Output Text Color In Java

Source Code

OutPut

change-console-text-color-java-codepuran

How to Create 2D Matrix Using ArrayList Collection Class In Java

In this simple program, I am going to share the code snippets for creating the 2D matrix using the Java collection class ArrayList.

Problem Statement

Create a 2 Dimensional matrix using the ArrayList in Java.

Source Code

Output

 

OutPut: ArrayList-Matrix-java-codepuran.com

Execute DOS Command Using Java Program

Ever wanted to run DOS commands from the Java program?

Here I am sharing the code snippets of How to Run DOS Command in Java Program.

In this program, we are using the popular DOS command ipconfig testing.

The Output will be displayed in the console. You can also store the output in the file or can parse the output to Digg the meaningful information from it.

How to Execute DOS Command in Java Program?

Source Code

Output

In console window the above program will print the output same as the, you get firing command ipconfig in command prompt.