8 C
New York
Sunday, November 27, 2022

The differences between Java and TypeScript devs must know – TheServerSide.com

Getty Images/iStockphoto
TypeScript is growing in popularity as the programming language of choice for both front-end and back-end developers.
With TypeScript, developers can fully wield the power of the principles and practices of object-oriented programming (OOP). Meanwhile, they can build on their experience with JavaScript, the language from which TypeScript is derived.
Typescript is a good fit for Java programmers who want to branch out into another language but still leverage their expertise with OOP.
Here are the five things every Java developer who’s learning TypeScript needs to know:
TypeScript was intended to be an OOP language from the start. All the standard features of OOP available in Java are in TypeScript.
First and foremost, TypeScript is a strict type language. As with Java, TypeScript establishes the type of a variable at design time, when the variable is declared. The following is an example of strict type declaration in TypeScript, which declares the variable firstName as a variable of type string:
let firstName: string
As with Java, under TypeScript classes and interfaces are first-class building blocks of the language. You can declare the scope of class variables and methods as public, protected and private. Java has supported this style of scoping since its inception.
Finally, TypeScript lets you apply decorators to classes, methods, accessors, properties and parameters. A decorator can impose behavior on a class, method, accessor, property or parameter in a declarative manner by using the given decorator prefixed with the @ symbol, as shown in the following example that uses a decorator name @sealed:
class BugReport {
 type = “report“;
 title: string;
 constructor(t: string) {
  this.title = t;

The Java equivalent of a TypeScript decorator is an annotation.
Both TypeScript and Java are OOP languages, but there are differences in their syntax. The following example declares a variable named firstName in Java:
String firstName = “John“;
The next example declares firstName in TypeScript:
const firstName: string = ‘John‘;
As you can see, the examples above have the same intent: declare a variable named firstName of type String and then assign the value “John” to the variable. The difference is in the syntax of each expression.
Java programmers coming to TypeScript must take some time to learn the TypeScript syntax. TypeScript syntax isn’t that hard to learn; it’s just a bit different from Java syntax.
Both Java and TypeScript are compiled languages. This means that a compiler inspects the text of source code to make sure the code is syntactically correct and then converts the source code text into a format that a computer at runtime can process.
In Java, source code is compiled into bytecode that is run by the Java Virtual Machine installed on a given computer. In TypeScript, source code is compiled into JavaScript code that is run by the JavaScript runtime. For front-end developers, the JavaScript runtime is a component that’s part of the web browser. For back-end developers, the JavaScript runtime is installed on the server that runs the back-end application.
The physical file transformation in Java converts a text file that has the .java file extension into bytecode that has the .class file extension.
Typescript, by comparison, compiles source code text files with the .ts extension into JavaScript code that has the .js file extension.
Java programming has matured over the years to the point where there are comprehensive package and build systems to deploy components and libraries that programmers can easily use in their code. Two popular package management and build systems among Java developers are Maven and Gradle. Various repositories that host components to download and install support these package management systems.
TypeScript developers use the NPM package management and build system to create applications intended to run under NodeJS. Publicly available NPM packages are hosted on npmjs.com.
Any Java or TypeScript developer can write an application using nothing more than a simple text editor. However, most developers use an integrated developer environment (IDE) such as IntelliJ, WebStorm, Eclipse or Visual Studio Code.
The benefit of using an IDE is that developers can write better code, faster. IDEs can detect syntax errors in code at design time, even before the code is compiled. Many IDEs also detect inefficient code and suggest better ways to write the code.
Many IDEs offer a feature called code completion, which offers suggestions for developers to complete a programming statement as the developer writes. Auto-completion can also automatically import dependency statements when you declare a class or interface that’s part of an external dependency.
This code completion capability has different names in different IDEs. In Microsoft Visual Studio Code, it’s branded as IntelliSense and IntelliCode. Eclipse has a setting called Content Assist, while IntelliJ and Webstorm call their setting code completion.
TypeScript has a lot to offer Java developers. Coders who understand the intricacies of object-oriented programming can apply what they know to TypeScript immediately. Also, TypeScript offers a way for Java developers to transition into the world of browser-based software development.
There is a learning curve for developers to move from Java to TypeScript. For most, getting the hang of TypeScript is a matter of understanding the syntax. The five tips in this article should make the move easier.
More than ever, increases in data-centric developer reliance, data sources and users push developers to understand IT purchasing …
As with any software development cycle, API security must be built in from the start. Follow these guidelines to design, deploy …
Developers who work with microservices may find the concept familiar, but cell-based architecture takes its own spin on …
Java 20 will likely include useful features such as improvements to concurrency and profiling, but the incremental updates are …
API testing — including data-driven API testing — differs from other software tests in its overall process and relevant metrics…
Questions surround GitHub Copilot’s use of open source code, but it’s a Supreme Court decision on Warhol’s art that developers …
AWS Batch enables developers to run thousands of batches within AWS. Follow this tutorial to set up this service, create your own…
Alloy, a new infrastructure platform, lets partners and Oracle-affiliated enterprises resell OCI to customers in regulated …
Dell dropped news at separate events this week — one that showcased edge management software, another that showed deepening HCI …
Victor Zhora, a key Ukrainian cybersecurity official, says Russia is acting with “no particular strategy” in its cyber attacks on…
CISA added two Cisco AnyConnect flaws to its Known Exploited Vulnerabilities catalog, which signals active exploitation and an …
Password expiration policies that force users to regularly reset passwords are counterproductive. It’s time to align those …
Many organizations struggle to manage their vast collection of AWS accounts, but Control Tower can help. The service automates …
There are several important variables within the Amazon EKS pricing model. Dig into the numbers to ensure you deploy the service …
AWS users face a choice when deploying Kubernetes: run it themselves on EC2 or let Amazon do the heavy lifting with EKS. See …
All Rights Reserved, Copyright 2000 – 2022, TechTarget

Privacy Policy
Cookie Preferences
Do Not Sell My Personal Info


Related Articles


Please enter your comment!
Please enter your name here

Latest Articles