Topic 1- 6 steps of Angular Installation for Java Developers

For Java developers transitioning to Angular, setting up Angular is akin to setting up your Java environment with tools like the JDK, Maven, or Spring Boot. This guide will walk you through the Angular setup step-by-step while drawing parallels to familiar Java concepts to make the process easier.


Step 1: Install Node.js

Think of Node.js as the Angular equivalent of the JDK. It provides the runtime environment for building Angular applications.

  • Download and Install Node.js:
    Visit the Node.js official website, download, and install it using the default settings.
  • Java Comparison: This is like installing the JDK to compile and run Java applications.

Step 2: Verify Node.js Installation

After installing Node.js, verify its setup.

  1. Open your terminal or command prompt.
  2. Run the following command to check the npm (Node Package Manager) version: npm -v
    • Java Comparison: Similar to running java -version to verify your JDK installation.
    • Example Output: 8.3.1

Step 3: Install Angular CLI

The Angular CLI (Command Line Interface) is to Angular what Maven or Gradle is to Java. It simplifies the creation and management of Angular projects.

  1. Install Angular CLI globally using the following command: npm install -g @angular/cli
    • The -g flag ensures the CLI is available globally, much like setting up Maven globally for Java projects.

Step 4: Create Your First Angular Project

Just as you’d initialize a Maven project for Java, you’ll create a new Angular project using the CLI.

  1. Run this command: ng new myapp
  2. During project setup, you’ll be prompted to configure:
    • Add Angular Routing?: Choose Yes to set up navigation within the app.
      • Java Comparison: Similar to configuring URL mappings in Spring MVC.
    • Stylesheet Format?: Select SCSS (Sass).
      • Java Comparison: SCSS is like JSP—an enhanced version of basic styling tools.

Step 5: Navigate to Your Project Directory

Once the project is created, navigate into the project directory:

cd myapp

  • Java Comparison: Similar to navigating into your Java project folder to run or edit it.

Step 6: Run Your Angular Application

Run your Angular app with the following command:

ng serve -o

  • Explanation:
    • ng serve: Builds and serves the application.
    • -o: Automatically opens the app in your default web browser at http://localhost:4200.
  • Java Comparison: Similar to running a Spring Boot application on a local server (e.g., localhost:8080).

Major Version Differences

As Angular evolves, certain features differ across major versions. Here are key distinctions relevant to Java developers:

  1. Angular 5:
    Manual setup of polyfills required (similar to adding JAR dependencies manually in Maven).
  2. Angular 10:
    Strict mode is enabled by default (like enabling additional checks in Java compilation).
  3. Angular 15+:
    Supports standalone component projects (akin to modularizing Java applications with Spring Boot microservices).

Using Node Version Manager (Optional)

If you’ve managed multiple JDK versions in Java, you’ll appreciate nvm (Node Version Manager) for handling different Node.js versions.

  • Why Use nvm?
    • Seamlessly switch between Node.js versions for different projects.
    • Avoid version conflicts.
    • Upgrade Node.js without reinstalling manually.
  • How to Install nvm:
    1. Download nvm from the nvm-windows GitHub releases page.
    2. Run the installer and follow the setup instructions.
    3. Verify installation by running: nvm --version

Summary

Here’s a quick comparison between Angular setup steps and Java development:

Angular StepJava Equivalent
Install Node.jsInstall JDK
Install Angular CLIInstall Maven/Gradle
Add RoutingConfigure URL mappings in Spring MVC
Use SCSS for StylingUse JSP for advanced templating and styles
Run the Angular ProjectRun a Spring Boot application

With your Angular environment set up, you’re ready to build applications just as efficiently as you build Java ones!


Complete Angular Demo Code

Github project link – https://github.com/kuldeep101990/angular-step1

Below is a sample Angular project showcasing the steps in action. You can follow these steps to create and run the project in your local environment.

// --- app.component.ts ---
import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'angular-step1';
}

<!-- app.component.html -->
<h1>Welcome to {{ title }}!</h1>

/* app.component.scss */
h1 {
  color: #3498db;
}


2 comments

Leave a Reply

Your email address will not be published. Required fields are marked *