J--

From Esolang
Jump to navigation Jump to search

J-- is basically a non-OOP version of Java. It is compiled into Java code and is run like a normal Java program, though you can not create new classes. There are plenty of classes available for you to use, including integers, strings, and every other Java class. J-- automatically imports: java.lang.*, java.util.*, java.math.*. It was made in July, 2015, by User:Phase.

Keywords

All J-- code is put into a class called J. There are various keywords that are changed into real Java code:

  • main -> public static void main(String[]a)
  • fn -> public static
  • str -> String
  • dub -> double
  • fpn -> float
  • vd -> void
  • echo -> System.out.println
  • ^^ -> !=
  • nw -> new
  • map -> HashMap

Built in functions

Here's a copy of some built in functions:

        add("public static int fac(int n){int f=1;for(int i=1;i<=n;i++){f*=i;}return f;}"); //factorial function
        add("public static final double GR = (1+Math.sqrt(5))/2;") //golden ratio used for other functions
        add("public static int fibo(int n){" +
            "return (Math.pow(GR,n) - Math.pow(-GR, -n))/Math.sqrt(5);}"); //get nth fibonacci number

Examples

Hello World

main{echo("Hello World");}

Cat

main{ echo(input()); }

Fibonacci sequence

main{
    for(int i=0;i<10;i++){
        echo(fibo(i));
    }
}

Factorial

main{
    echo(factorial(5));
}

External resources