I want to know if there is any way to print the underlined text on console using java String class.
You can only rely on how the String is interpreted by your console. For example, in
bash, you can do something like inserting your string between escape sequences
\033[0m (for bold):
\033[1mInsert your String here\033[0m
You should read the documentation of your favorite console.