Redirect your output as an html file through terminal
<p>Here is the file which I am trying to get a display in a web browser via terminal on mac.
When I run the program it does not send the program to web browser but it just prints the whole code.
If my understanding is wrong then please let me know.
The following code should give me an output as an html file:</p>

<p>Hello</p>

<p>Hi, how are you?</p>

<p>Code:</p>

<pre><code>public class OutputHTML {
public static void main(String[] args) {

    // DOCTYPE declaration
    System.out.println("&lt;!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"&gt;");

    // html start
    System.out.println("&lt;html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\"&gt;");

    // head start
    System.out.println("&lt;head&gt;");
    System.out.println();

    // meta tag for encoding
    System.out.println("  &lt;meta http-equiv=\"Content-type\" content=\"text/html; charset=UTF-8\" /&gt;");
    System.out.println();

    // title
    System.out.println("  &lt;title&gt;" + "Hello" + "&lt;/title&gt;");
    System.out.println();

    // head end
    System.out.println("&lt;/head&gt;");

    // body start
    System.out.println("&lt;body&gt;");
    System.out.println();

    // heading
    System.out.println("&lt;h1&gt;" + "Hello" + "&lt;/h1&gt;");
    System.out.println();

    // simple paragraph
    System.out.println("&lt;p&gt;" + "Hi, how are you?" + "&lt;/p&gt;");
    System.out.println();

    // body end
    System.out.println("&lt;/body&gt;");

    // html end
    System.out.println("&lt;/html&gt;");
}
</code></pre>

<p>}</p>
