Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

November 28, 2018

Java program to print Fibonacci sequence

import java.text.DecimalFormat;
  
public class Fib {

        public static void main(String args[]) {
                for (int i = 1; i <= 20; i++) {
                        System.out.println("[" + i + "] : " + fib(i) + " : " + new DecimalFormat("#.###").format(ratio(i)));
                }
        }

        private static int fib(int n) {
                if (n==1 || n==2) {
                        return 1;
                } else {
                        return fib(n-1) + fib(n-2);
                }
        }

        private static double ratio(int n) {
                if (n > 1) {
                        return (double)fib(n-1)/(double)fib(n);
                } else {
                        return 0;
                }
        }

}

July 8, 2016

JBoss 6 root context

Suppose you have an application (say named example) deployed in JBoss 6.
By default your application will be accessed by <Your URL>/example.

Suppose you want to make the application available at <Your URL> i.e the root location.
Then follow the following 2 steps:

1. Change the context of the ROOT.war application

To do that, create a file named jboss-web.xml  under <base folder>/jboss-6.1.0.Final/server/default/deploy/ROOT.war/WEB-INF.

<?xml version="1.0"?>

<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd">

<jboss-web>
<context-root>root</context-root>
</jboss-web>

2. Add a jboss-web.xml  under WEB-INF of your application
<?xml version="1.0"?>

<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd">

<jboss-web>
<context-root>/</context-root>
</jboss-web>

Now running <Your URL> in a browser will point to your example application.