Skip to main content

⚛️ React Day 1 — From Java to JSX( JavaScript XML) My First Frontend App Setup!

⚛️ React Journey Day 1: From Zero to Hello World (With Java Dev Mindset)

Hey folks! 👋 Welcome to Day 1 of my Full Stack Journey — and today, we officially begin learning React, from scratch, as a backend developer!


🚀 Why Do We Need Node.js and npm to Run React?

If you’re from a Java background like me, think of this:

Concept Java React
Language Java JavaScript (JSX)
Runtime JRE / JDK Node.js
Build Tool Maven / Gradle npm (Node Package Manager)

Node.js allows JavaScript to run outside the browser. React apps use Node to:

  • Compile JSX into plain JS
  • Run local development servers
  • Install libraries (just like Maven dependencies)

npm is like Maven — it downloads, installs, and manages your frontend packages and scripts.


🔧 What is Vite? And Why Do We Use It?

Vite is a modern build tool that gives us:

  • Instant startup
  • Faster hot reload
  • Simple setup

It's like the Spring Boot Initializr of the frontend world! 🧠

Feature Spring Boot Vite
Project Setup start.spring.io npm create vite
Dev Server Embedded Tomcat Vite Dev Server

🔄 Alternatives to Vite

  • create-react-app (CRA) – older, heavier setup
  • Parcel – zero config but less popular
  • Webpack (manual) – expert level
  • Next.js – production-ready framework on top of React

🔥 Today, Vite or Next.js is preferred in companies


📦 Setting Up React Project — Step-by-Step

✅ Prerequisite: Install Node.js (Mac & Windows)

Go to https://nodejs.org and download the LTS version:

  • 🍏 Mac users: Download the macOS installer (.pkg)
  • 🪟 Windows users: Download the Windows installer (.msi)

After installation, open Terminal or Command Prompt and run:

node -v
npm -v

🍏 Optional for Mac Users: If you use or want to use Homebrew (Mac’s terminal-based package manager), install Node with:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install node

Otherwise, download the Node.js macOS installer (.pkg) from nodejs.org.

🧠 React Setup Commands — Explained Step-by-Step (for Java Devs)

npm create vite@latest my-react-app -- --template react
cd my-react-app
npm install
npm run dev

✅ 1. npm create vite@latest my-react-app -- --template react

This command scaffolds a new React project using the latest version of Vite.

Part Meaning
npm Node’s package manager — like mvn or gradle
create vite@latest Use the latest official Vite project generator
my-react-app Your app/project folder name
-- Separates npm arguments from Vite ones
--template react Use React as the frontend template

Java Analogy: Like using Spring Initializr with a web dependency and generating a project zip.


✅ 2. cd my-react-app

Change directory into the newly created React app folder.

Java Analogy: cd my-spring-app after generating a project using start.spring.io.


✅ 3. npm install

Installs all dependencies defined in package.json — React, Vite, JSX tooling, etc.

Java Analogy: Like mvn install to download all dependencies from pom.xml.

📦 What Does npm install Do?

This command installs all the dependencies listed in your project’s package.json.

  • 📥 Downloads required libraries (React, Babel, Vite, etc.)
  • 🧱 Creates a node_modules/ folder — like your local dependency JARs
  • 🧾 Generates a package-lock.json to lock versions

Think of it like running:

mvn install

in a Spring Boot project. It resolves and pulls all required dependencies.


🧠 Java Comparison

React (npm) Java (Maven)
npm install mvn install
Reads package.json Reads pom.xml
Creates node_modules/ Uses .m2/repository
Creates package-lock.json No exact lock, but fixed versions in <version>

🔒 What is package-lock.json and Why Is It Important?

When you run npm install, it not only installs your dependencies but also creates a special file called package-lock.json.

🧠 What It Does

  • Locks the exact versions of all dependencies (and their sub-dependencies)
  • Ensures everyone on your team uses the same versions
  • Makes builds predictable and stable
"axios": {
  "version": "1.4.0",
  "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz"
}

🚫 What Happens Without It?

  • You install axios@1.4.0
  • Your teammate installs axios@1.4.5
  • Unexpected bugs may crash production 💥

🧠 Java Analogy

React (npm) Java (Maven)
package.json with ^1.4.0 <version>[1.4.0,2.0.0)</version>
package-lock.json Pinning versions or lock plugin (in Gradle)

✅ Summary

  • package-lock.json = your project's version snapshot
  • Protects you from bugs in new versions
  • Ensures consistent builds across all machines

✅ When Should You Run It?

  • 📁 After downloading or cloning a React project
  • 🔄 After deleting node_modules/
  • ➕ After adding new dependencies like npm install axios

⚠️ Important Notes

  • 🚫 Never push node_modules/ to GitHub
  • ✅ Only commit package.json and package-lock.json

Once installed, you’re ready to run:


✅ 4. npm run dev

Starts the Vite development server.

  • Hot reload enabled 🔁
  • Watches for code changes 👀
  • Serves your app on http://localhost:5173 🌐

Java Analogy: Like ./mvnw spring-boot:run to launch your backend locally.

⚙️ What Does npm run dev Actually Do?

This command tells npm (Node Package Manager) to run the script named dev from your project’s package.json file.

"scripts": {
  "dev": "vite",
  "build": "vite build",
  "preview": "vite preview"
}

So when you run npm run dev, it executes Vite — your development server.

🔍 What Happens Internally?

  • 🟢 Starts Dev Server → Runs at http://localhost:5173
  • 🔁 Hot Reload → Instantly reloads browser on code changes
  • Compiles JSX → Converts JSX to regular JavaScript using ESBuild
  • 📁 Serves Static Files → Loads from public/ and src/

✅ It's optimized for speed and instant feedback — perfect for development!

🧠 Java Comparison

React (Vite) Java (Spring Boot)
npm run dev mvn spring-boot:run
Starts Vite dev server on port 5173 Starts embedded Tomcat on port 8080
Hot-reloads UI as you type Rebuild + restart on code changes

💡 Why Use npm run dev Instead of Just vite?

  • ✅ Ensures the right version of Vite is used from your local project
  • ✅ Reads any custom configs from vite.config.js
  • ✅ More portable — works for all devs on your team

🎯 Summary

  • npm run dev starts the Vite server using your project’s local config
  • It’s fast, hot-reload enabled, and watches your JSX/TSX code
  • It's the frontend version of spring-boot:run for Java devs

🌐 You can now open http://localhost:5173 in your browser and start building your UI!






📦 What’s Inside package.json?

You’ll see these scripts under the scripts section:

{
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  }
}

So when you run npm run dev, it’s just calling vite under the hood.


🧠 Summary Table

Command What It Does Java Equivalent
npm create vite@latest my-app -- --template react Create a new React app using Vite start.spring.io project creation
cd my-app Enter the project folder cd my-springboot-app
npm install Install frontend dependencies mvn install
npm run dev Run Vite dev server with hot reload mvn spring-boot:run

🎉 After this, you can open http://localhost:5173 in your browser and see your first React component in action!


📁 Folder Structure — Compared with Java

Java Project React Project
src/main/java src/ (JSX code)
src/main/resources public/ (static files)
pom.xml package.json

🧠 Your First Component (App.jsx)

Open App.jsx and write:

function App() {
  return (
    <div>
      <h1>Hello Anand!</h1>
      <p>This is your first React component.</p>
    </div>
  );
}

export default App;

Java Comparison:

  • function App() = like a public class
  • return (<div>) = like HTML template builder
  • export default App = like your main class being exposed

🧩 What is JSX?

JSX = JavaScript + XML

It allows us to write:

<h1>Hello</h1>

inside JavaScript functions. It’s not natively supported by browsers, so tools like Babel (inside Vite) convert it to valid JS.

Supported File Extensions:

  • .js — Plain JavaScript
  • .jsx — JavaScript with JSX
  • .ts — TypeScript
  • .tsx — TypeScript with JSX

🎯 Mini Practice

function App() {
  const name = "Anand";
  const year = new Date().getFullYear();

  return (
    <div>
      <h2>🚀 Hello {name}!</h2>
      <p>React Journey — {year}</p>
      <button onClick={() => alert("Keep Learning!")}>Motivate Me</button>
    </div>
  );
}

Try it, run it, and smile when the alert works 😄

FILE : /my-react-app/src/App.jsx


✅ Wrapping Up

  • You now know what Node.js & npm are — like JDK + Maven
  • Vite is your Spring Boot of the frontend
  • JSX is HTML + JavaScript (JSX = JavaScript + XML)
  • You created and ran your first React component!
From Day 2 onward: I’ll start using .tsx files — because most companies today expect React with TypeScript.
It's strongly typed, safer, and aligns well with enterprise-grade standards. 💼⚛️🟦

Stick around — React is just getting fun! ⚛️

If you liked this post or are following the same path, drop a comment below — let’s learn React + TypeScript together! 💬🔥

Comments

Popular posts from this blog

🔐 Is final Really Final in Java? The Truth May Surprise You 😲

💬 “When I was exploring what to do and what not to do in Java, one small keyword caught my eye — final . I thought it meant: locked, sealed, frozen — like my fridge when I forget to defrost it.”   But guess what? Java has its own meaning of final… and it’s not always what you expect! 😅 Let’s break it down together — with code, questions, confusion, jokes, and everything in between. 🎯 The Confusing Case: You Said It's Final... Then It Changed?! 🫠 final List<String> names = new ArrayList <>(); names.add( "Anand" ); names.add( "Rahul" ); System.out.println(names); // [Anand, Rahul] 🤯 Hold on... that’s final , right?! So how on earth is it still changing ? Time to dive deeper... 🧠 Why Is It Designed Like This? Here’s the key secret: In Java, final applies to the reference , not the object it points to . Let’s decode this like a spy mission 🕵️‍♂️: Imagine This: final List<String> names = new ArrayList <>(); Be...

🌟 My Journey – From Zero to Senior Java Tech Lead 🌟

 There’s one thing I truly believe… If I can become a Java developer, then anyone in the world can. 💯 Sounds crazy? Let me take you back. 🕓 Back in 2015… I had zero coding knowledge . Not just that — I had no interest in coding either. But life has its own plans. In 2016, I got a chance to move to Bangalore and joined a Java course at a training center. That’s where it all started — Every day, every session made me feel like: "Ohhh! Even I can be a developer!" That course didn’t just teach Java — it gave me confidence . 🧪 Two Life-Changing Incidents 1️⃣ The Interview That Wasn't Planned Halfway through my course, I had to urgently travel to Chennai to donate blood to a family member. After that emotional rollercoaster, I found myself reflecting on my skills and the future. The next day, as I was preparing for my move to Bangalore to complete the remaining four months of my course, I randomly thought — "Let me test my skills... let me just see...

🎢 Java Loops: Fun, Fear, and ForEach() Fails

🌀 Oops, I Looped It Again! — The Ultimate Java Loop Guide You Won't Forget “I remember this question from one of my early interviews — I was just 2 years into Java and the interviewer asked, ‘Which loop do you prefer and why?’” At first, I thought, “Duh! for-each is cleaner.” But then he grilled me with cases where it fails. 😵 That led me to explore all loop types, their powers, and their pitfalls. Let’s deep-dive into every major Java loop with examples &  real-world guidance so you'll never forget again. 🔁 Loop Type #1: Classic For Loop — “The Old Reliable” ✅ When to Use: You need an index You want to iterate in reverse You want full control over loop mechanics ✅ Good Example: List<String> names = List.of("A", "B", "C"); for (int i = 0; i < names.size(); i++) { System.out.println(i + ": " + names.get(i)); } 🔥 Reverse + Removal Example: List<String> item...