Featherweight Java

Featherweight Java (FWJ) is a lightweight version of the Java programming language that is designed to simplify its syntax and semantics while retaining the key features of object-oriented programming. FWJ was developed as a minimalistic programming language to help teach the basics of object-oriented programming, and its syntax is similar to that of Java, but with less functionality.

One of the main uses of lightweight versions of Java like FWJ is to make rigorous proofs about type safety easy. Type safety enforces data to have valid types for certain operations. For example, writing [12 + "String"] in Java will produce a type error because you cannot add an integer to a string. FWJ has a simple type system based on class types, object types, and method types, which is designed to be type-safe and ensures that programs are checked at compile-time to ensure that they are free of type errors.

## Overview

In this section, we'll cover the basics of Featherweight Java and what sets it apart from Java.

### Syntax

FWJ has a simplified syntax compared to Java. It uses a minimal set of constructs to represent object-oriented concepts, such as classes, objects, methods, and inheritance.

### Type System

FWJ has a simple type system based on class types, object types, and method types. The type system is designed to be type-safe, meaning that programs are checked at compile-time to ensure that they are free of type errors. A type error is when the wrong type (String, int, boolean, etc.) is being used in the wrong place.

## Features

In this section, we'll cover the key features of Featherweight Java.

### Classes

FWJ supports the definition of classes, which can have fields and methods. Classes can also extend and implement other classes to inherit their fields and methods.

### Objects

FWJ supports the creation of objects, which are instances of classes. Objects have a state represented by their fields and can invoke methods defined in their class or any of their ancestor classes.

### Methods

FWJ supports the definition of methods, which can have parameters and a body that consists of a sequence of statements. Methods can be invoked on objects to perform some action or return a value.

### Inheritance

FWJ supports single inheritance, meaning that classes can only extend one other class. Inheritance allows classes to reuse the fields and methods of their parent class.

## Example

In this section, we'll provide an example of a simple Featherweight Java program.

```
class Point {
 int x;
 int y;

 Point(int x, int y) {
 this.x = x;
 this.y = y;
 }

 int getX() {
 return this.x;
 }

 int getY() {
 return this.y;
 }
}

class Main {
 static void main(String[] args) {
 Point p = new Point(1, 2);
 System.out.println(p.getX()); // Output: 1
 System.out.println(p.getY()); // Output: 2
 }
}

```
This program defines a `Point` class with two fields (`x` and `y`) and two methods (`getX` and `getY`). It also defines a `Main` class with a `main` method that creates a `Point` object and invokes its `getX` and `getY` methods.

## Conclusion

Featherweight Java is a simple and minimalistic programming language that can be used to teach the basics of object-oriented programming. Its syntax and semantics are designed to be easy to understand, while still retaining the key features of object-oriented programming.