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

is not a JMX compliant Standard MBean

I got the fallowing exception and issue solved. If your are using MBean , MBean Interface and Implementation should be in same package, Otherwise use MXBean. javax.management.NotCompliantMBeanException: MBean class comlanka.rest.controller.DataManagerController does not implement DynamicMBean, and neither follows the Standard MBean conventions (javax.management.NotCompliantMBeanException: Class comlanka.rest.controller.DataManagerController is not a JMX compliant Standard MBean) nor the MXBean conventions (javax.management.NotCompliantMBeanException: comlanka.rest.controller.DataManagerController: Class comlanka.rest.controller.DataManagerController is not a JMX compliant MXBean)         at com.sun.jmx.mbeanserver.Introspector.checkCompliance(Introspector.java:176)         at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:317)         at com.sun.jmx.mbeanserver.Jmx...

AWS amplify hugo App build specification amplify.yml

 I needed a content-oriented site with solely static content for a little project I'm working on, so Hugo was an obvious choice. I looked into using AWS Amplify to host it, But the default amplify.yml not working for me and can't find the correct build file, I have modified the amplify.yml to build the Hugo cms. Hope this is helpful, Please comment. version : 1 frontend : phases : build : commands : - npm install - npm run build:webpack && npm run build:hugo artifacts : baseDirectory : dist files : - '**/*' cache : paths : []

hamcrest and junit java.lang.NoSuchFieldError: NONE

Issue - When you using hemcrest with JUnit5 you may get  java.lang.NoSuchFieldError: NONE error. Solution - Add junit-vintage-engine to classpath           <dependency>             <groupId>org.junit.vintage</groupId>             <artifactId>junit-vintage-engine</artifactId>             <version>5.3.1</version>             <scope>test</scope>         </dependency>  Full Exception - java.lang.NoSuchFieldError: NONE at org.hamcrest.DiagnosingMatcher.matches(DiagnosingMatcher.java:12) at org.hamcrest.beans.SamePropertyValuesAs.hasMatchingValues(SamePropertyValuesAs.java:63) at org.hamcrest.beans.SamePropertyValuesAs.matchesSafely(SamePropertyValuesAs.java:31) at org.hamcrest.TypeSafeDiagnosingMatcher.matches(TypeSafeDiagnosing...