Skip to main content

java typescript comparison

I am working as java developer for many years with java swing and web service. However I don't like to write JavaScript as many java developer.

Currently we got chance to work with angular2 and Typescript. Now we can manage source easily with Typescript. It makes easier to write javascript code with Typescript.

Now I am trying to compare Typescript and Java.

Java hello world

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

Typescript hello world
export class HelloWorld {
    public static main(args : string[]) {
        console.info(" Hello Java Typescript comparison.");
    }
}
HelloWorld.main(null);
Java class, constructor, method and static method
public class Student {
    private String name;
    private int age;

    public Student() {
    }
    public int getAge()
    {
        return age;
    }
    public static void staticMethod(int birthDay)
    {
        //implementation     
    }
}
Typescript class, constructor, method and static method
class Student {
    private name:string;
    private age:number;

    public constructor() {
        this.age = 0;
    }
    public getAge():number {
        return this.age;
    }
    public static staticMethod(birthDay:number) {
      //implementation 
    }
}

Java Types
public class TypesExample {
    private boolean isDone = true;
    private int intValue = 10;
    private float floatValue = 100;
    private long longValue = 1000;
    private String stringValue = "Java vs Typescripe";
    private int[] intArray ={1,2,3};
    private List<String> genericString;
    private BookingType bookingType = BookingType.FLIGHT;
    private Object anyType;

    enum BookingType{
        HOTEL,
        FLIGHT,
        CAR    }
}

Typescript Types
class TypesExample {
    private isDone : boolean = true;
    private intValue : number = 10;
    private floatValue : number = 100;
    private longValue : number = 1000;
    private stringValue : string = "Java vs Typescripe";
    private intArray : number[] = [1, 2, 3];
    private genericString : Arry<string>;
    private bookingType : TypesExample.BookingType = TypesExample.BookingType.FLIGHT;
    private anyType : any;
    constructor() {
    }
}

export namespace TypesExample {
    enum BookingType {
        HOTEL, FLIGHT, CAR    }
}

Comments

Popular posts from this blog

Angular 2 Typescript without node or npm

To getting start with angular2 app, we need to setup some bunch of  tool and boilerplate codes. Fortunately there are many easy getting-start projects available for angular2. Those are  angular-cli , angual2-seed etc. Anyway we need to rely on node and npm, that would need for real angular2 projects. But sometimes we need to test  angular2 features  and share demo codes with others. Installing large node modules and setting-up not worth for this kind of task. However for small task you can use angular2 without npm.     have a look at github repository -  https://github.com/ishara/angular2-without-npm happy coding.

How to select GC for java application

Which garbage collection(GC) algorithm suite for the application If you don't have any strict pause-time requirements, first run your application and allow the VM to select a collector. If necessary, adjust the heap size to improve performance. If the performance still doesn't meet your performance, then use the specific collector and try. Performance is dependent on the size of the heap, the amount of live data maintained by the application, and the number and speed of available processors. If the recommended collector doesn't achieve the desired performance, then first attempt to adjust the heap and generation sizes to meet the desired goals. If performance is still inadequate, then try a different collector: Use the concurrent collector to reduce pause-time, and use the parallel collector to increase overall throughput on multiprocessor hardware. Available Collector in Oracle JDK -XX:+UseSerialGC -XX:+UseParallelGC -XX:+UseG1GC -XX:+UseCon...