Running C,C++, Java, Python and PHP on VS Code

Run C, C++, Python, Java, PHP, and Flutter on VS Code (Windows)

How to Run C, C++, Python, Java, PHP, and Flutter on VS Code (Windows)

Visual Studio Code (VS Code) is a lightweight and versatile editor. With the right setup, you can use it for multiple programming languages. Below is a step-by-step guide to run C, C++, Python, Java, PHP, and Flutter on Windows.

1. Running C and C++

Install Compiler

  • Download MinGW-w64 from winlibs.com.
  • Add C:\mingw64\bin to the PATH environment variable.
  • Verify with gcc --version and g++ --version.

Hello World Example

// hello.cpp
#include <iostream>
using namespace std;

int main() {
    cout << "Hello, C++ World!" << endl;
    return 0;
}

Compile with g++ hello.cpp -o hello.exe and run with ./hello.exe.


2. Running Python

  • Download Python from python.org (check “Add Python to PATH”).
  • Verify with python --version.
  • Install the Python extension in VS Code.
# hello.py
print("Hello, Python World!")

Run with python hello.py.


3. Running Java

  • Download JDK from Adoptium.
  • Add JDK bin path to PATH variable.
  • Verify with java -version and javac -version.
  • Install Extension Pack for Java in VS Code.
// Hello.java
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, Java World!");
    }
}

Compile with javac Hello.java and run with java Hello.


4. Running PHP

  • Download PHP for Windows from windows.php.net.
  • Extract to C:\php and add C:\php to PATH.
  • Verify with php -v in Command Prompt.
  • Install the PHP Extension Pack in VS Code (optional but useful).
<?php
  echo "Hello, PHP World!";
?>

Run with php hello.php in the terminal.


5. Running Flutter

Install Flutter SDK

Device Options

  • With Android Studio: full emulator and SDK support.
  • Without Android Studio: use Android command-line SDK tools or a physical device with USB debugging.
  • Alternative: run Flutter apps on Web or Desktop (no Android SDK needed).

Hello World Example

// lib/main.dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Hello Flutter')),
        body: const Center(child: Text('Hello, Flutter World!')),
      ),
    );
  }
}

Create a project with flutter create hello_app and run with flutter run.

Tip: Run flutter doctor to check if your setup is correct.

Final Words

VS Code is a powerful and flexible environment for developers. With the right tools, you can easily code in C, C++, Python, Java, PHP, and even build cross-platform apps with Flutter — all from one place.

Post a Comment

0 Comments

Me