Values in CLIPS

Our first program will demonstrate various value types including strings, integers, floats, and booleans. Here’s the full source code.

public class Values {
    public static void main(String[] args) {
        // Strings, which can be concatenated with +.
        System.out.println("java" + "lang");

        // Integers and floats.
        System.out.println("1+1 = " + (1 + 1));
        System.out.println("7.0/3.0 = " + (7.0 / 3.0));

        // Booleans, with boolean operators as you'd expect.
        System.out.println(true && false);
        System.out.println(true || false);
        System.out.println(!true);
    }
}

To run the program, compile the code and then use java to execute it.

$ javac Values.java
$ java Values
javalang
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false

Java has various value types including strings, integers, floats, booleans, etc. This example demonstrates a few basic ones:

  1. Strings: In Java, strings can be concatenated using the + operator.
  2. Integers and Floats: Java supports basic arithmetic operations on numeric types.
  3. Booleans: Java includes boolean operators for logical operations.

Note that unlike some languages, Java doesn’t have a built-in println function. Instead, we use System.out.println() to print to the console.

Also, in Java, you need to explicitly wrap arithmetic operations in parentheses when including them in a string concatenation, as shown in the 1+1 and 7.0/3.0 examples.