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 {
Typescript hello world
export class HelloWorld {
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 methodpublic 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 methodclass 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 Typespublic 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 Typesclass 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
Post a Comment