Introduction to JR programming language

JR Programming Language Logo

1. Language overview

JR is a programming language especially created to solve concurrent programming problems. This language is an overview of Java who add to this last the main paradigms of concurrent programming. Moreover JR make easier the concepts still implemented in Java like process or semaphores. There is also several extensions for JR to add more functionalities like monitors and Conditional Critical Region (CCR). JR is the implementation of the SR language for Java.
JR makes nothing else than add a layer over Java. Once we use the JR compiler, the JR source files are transformed in Java files and are executed by the virtual machine like any other Java class.

JR is often used as a school support to learn concurrent programming.

In this article, we will see the bases of the programmation with JR.

The presented version is the one of June 2009, the version 2.00602 who are based on Java 6.0.

This article need that you’ve installed the JR environment on your system. An article is available here for the installation under Windows.

In this article, we will especially focus on the apports of the JR language for the concurrent programming. We will not see the the integrality of the language. JR has other benefits than make easier concurrent programming, but we will not see that in this article. Moreover, all the aspects of concurrent programming in JR will not be treated here.

2. Hello World

Like all other languages, we must start with a simple Hello World. Thus we’ll create a file Hello.jr. Nothing special here, it’s pure Java :

public class Hello {
    public static void main(String[] args){
		System.out.println("Hello World");
    }
}

Then we can compile it :

jrc Hello.jr

This will create a jrGen folder containing Java files. The result of a JR compilation is always a set of Java files corresponding to the translation of the JR files.

To launch your JR program, use the jr command followed by the name of the main class (class containing the main method) :

jr Hello

That will display :

Hello World

The jr command will also launch the compilation of Java files. This compilation will be done every time. If you want to make only the launch of compiled files, you can use the jrrun command.

Like said in introduction, the JR language extends the Java language. So, you can code in Java with JR. Thus an Hello World is only Java.

3. Processes

The first thing to see is the declaration of processes. This is done in an easier way than in Java. No need to instanciate some objects, this is done in a declarative way and JR make the rest.

For the declaration of process, JR introduce a new keyword process who enable to declare a process. Here is the simplest declaration of a process :

process Hello {
	System.out.println("Processus");
}

Like you can see it, it’s easier than in Java. And better, no need to launch it, you just have to instanciate the class. A process can also be declared static. This times, it will not be launched at the instanciation of the class but at the resolution of the class by the virtual machine. By example, we can rewrite an HelloWorld in that way :

public class HelloProcess {
    static process Hello {
		System.out.println("Hello World");
	}
 
	public static void main(String[] args){}
}

who display exactly the same thing as the first version of the Hello World. At the difference that our display is made from a thread.

Moreover, JR enable to declare a big set of threads in a declaration with the following syntax :

static process Hello((int id = 0; id < n; id++)){}

This will declare n threads. The syntax is the same as the for loop. Let’s declare 25 threads Hello World :

public class HelloProcess {
    static process Hello((int id = 0; id < 25; id++)){
		System.out.println("Hello World from thread " + id);
	}
 
	public static void main(String[] args){}
}

When we launch that, we could have the following result :

Hello World from thread 2
Hello World from thread 24
Hello World from thread 11
Hello World from thread 22
Hello World from thread 0
Hello World from thread 4
Hello World from thread 6
Hello World from thread 8
Hello World from thread 10
Hello World from thread 12
Hello World from thread 14
Hello World from thread 16
Hello World from thread 18
Hello World from thread 20
Hello World from thread 23
Hello World from thread 21
Hello World from thread 19
Hello World from thread 17
Hello World from thread 15
Hello World from thread 13
Hello World from thread 9
Hello World from thread 7
Hello World from thread 5
Hello World from thread 3
Hello World from thread 1

Like you can see, if you launch several times the program, the display is not same and the message commes in an order completely different order at each launch. Nothing can guarantee the order of the threads launches and still less the order of the execution of the instructions and you must not count on it.
It’s the basis of the concurrent programming. You cannot predict the order of the instructions in the different threads.

Related posts:

  1. Java Concurrency – Part 1 : Threads
  2. Monitor programming in JR
  3. Java Concurrency : Part 2 – Manipulate Threads
  4. Java Concurrency – Part 3 : Synchronization with intrinsic locks
  5. JR Operations and Capabilities
Pages: 1 2 3 4
  • http://www.squidoo.com/portlandphotoboothrental2 Nicolas Bohinc

    Thanks for this excellent blog.

  • http://www.squidoo.com/portlandphotoboothrental2 Nicolas Bohinc

    Thanks for this excellent blog.

  • Alexandre Jaquet

    I just found your article after discovering the existence of JR (We learned SR in the past) ;-)

  • Alexandre Jaquet

    I just found your article after discovering the existence of JR (We learned SR in the past) ;-)

  • Steve

    Not sure I see the point: you created a new syntax just to encapsulate new Thread(…).start().

    What’s the gain?

    • Baptiste Wicht

      It’s not me that created the syntax.

      The gain is that for almost every principle of concurrent programming, you have facilities to develop with them. It’s really easy to use semaphores, monitors, message passing, rendezvous, …

      Effectively, you can all the things of JR in Java, but it’s a lot more cleaner with JR.

      • Steve

        “It’s a lot more cleaner in Java”? Then why create JR?

        Besides, in my experience, the difficulty is precisely semaphores, monitors, etc… Creating threads is trivial, so I really don’t see the point in creating a language just for that purpose…

        • Baptiste Wicht

          What I wanted to say it’s that it’s cleaner in JR. Sorry for the error.

          There is not only facilities to create process but also to use semaphores and monitors and to use asychronous message passing and rendezvous. You can also make distributed programs.

          I think it’s good to have. But i’ll not use JR in my real projects

  • Steve

    Not sure I see the point: you created a new syntax just to encapsulate new Thread(…).start().

    What’s the gain?

    • Baptiste Wicht

      It’s not me that created the syntax.

      The gain is that for almost every principle of concurrent programming, you have facilities to develop with them. It’s really easy to use semaphores, monitors, message passing, rendezvous, …

      Effectively, you can all the things of JR in Java, but it’s a lot more cleaner with JR.

      • Steve

        “It’s a lot more cleaner in Java”? Then why create JR?

        Besides, in my experience, the difficulty is precisely semaphores, monitors, etc… Creating threads is trivial, so I really don’t see the point in creating a language just for that purpose…

        • Baptiste Wicht

          What I wanted to say it’s that it’s cleaner in JR. Sorry for the error.

          There is not only facilities to create process but also to use semaphores and monitors and to use asychronous message passing and rendezvous. You can also make distributed programs.

          I think it’s good to have. But i’ll not use JR in my real projects

  • Dontell

    You can write it almost as clean in Java now using static imports:
    for(final int id : sequence(0, 24)) process(new Runnable(){ @Override public void run(){
    System.out.println(“Hello World from thread ” + id);
    }});

    The annoying Runnable boiler plate will soon (“soon”) be replaced by something like
    for(final int id : sequence(0, 24)) process(#(){
    System.out.println(“Hello World from thread ” + id);
    });

    Whenever a new language comes up with “much cleaner syntax” it’s mostly only a trick of comparing apples (some marginal syntax sugar) with oranges (java code without proper static util methods).
    In the end, if you know what to do, you can get the same clarity in java (admitedly for functions only as soon as JDK7 will be out).

    The Java syntax isn’t perfect (and I’m no Java Zealot or something) but I have yet to see a language that is really a noteworthy potential successor.

    • Baptiste Wicht

      Thanks for the reply !

      Effectively, you can do a lot of JR very clean in Java. But if you watch the other articles I wrote about JR, you can see that JR make more than simplify only the creation of processes. You can easily create monitors, function pointers, make asynchronous message passing, rendezvous and even create several virtual machines and make distributed programming.

      But I don’t think JR is a language to replace Java, but it’s a very good language to learn concurrent programming. Personally, I didn’t use this language for my projects, I always use Java. We use JR at school. JR is not installed on a lot of machine, so it’s not easy to distribute that kind of programs.

  • Dontell

    You can write it almost as clean in Java now using static imports:
    for(final int id : sequence(0, 24)) process(new Runnable(){ @Override public void run(){
    System.out.println(“Hello World from thread ” + id);
    }});

    The annoying Runnable boiler plate will soon (“soon”) be replaced by something like
    for(final int id : sequence(0, 24)) process(#(){
    System.out.println(“Hello World from thread ” + id);
    });

    Whenever a new language comes up with “much cleaner syntax” it’s mostly only a trick of comparing apples (some marginal syntax sugar) with oranges (java code without proper static util methods).
    In the end, if you know what to do, you can get the same clarity in java (admitedly for functions only as soon as JDK7 will be out).

    The Java syntax isn’t perfect (and I’m no Java Zealot or something) but I have yet to see a language that is really a noteworthy potential successor.

    • Baptiste Wicht

      Thanks for the reply !

      Effectively, you can do a lot of JR very clean in Java. But if you watch the other articles I wrote about JR, you can see that JR make more than simplify only the creation of processes. You can easily create monitors, function pointers, make asynchronous message passing, rendezvous and even create several virtual machines and make distributed programming.

      But I don’t think JR is a language to replace Java, but it’s a very good language to learn concurrent programming. Personally, I didn’t use this language for my projects, I always use Java. We use JR at school. JR is not installed on a lot of machine, so it’s not easy to distribute that kind of programs.

  • http://www.aryol.com.tr prefabrik

    very qualified post. I’m new for JR programming language and your post about the introduction of it helps me a lot. thanks for your effort.

  • Anonymous

    This is good blog about JR programming language. JR programs are based on Java and again translated into accepted Java programs. The JR run-time support arrangement is aswell based on standard Java.

    toshiba coupon codes