This note explains different ways to run C# (.cs), Java (.java), and C++ (.cpp) files using various tools and environments.
C# (.cs)
1. Without Installing .NET SDK (Using the Old Framework)
- Prerequisite: No need to install the .NET SDK, as Windows has an older version pre-installed.
- Steps:
- Navigate to the directory:
C:\Windows\Microsoft.NET\Framework\v4.0.30319
. - Open Command Prompt (as Administrator).
- Run the following command:
csc filename.cs && filename
- Navigate to the directory:
2. With .NET SDK Installed
- Prerequisite: Ensure you have .NET SDK installed.
- Steps:
- Open the folder containing your
.cs
file in Visual Studio Code (VSCode). - Open a new terminal in VSCode.
- Run the following command to create a new console app:
dotnet new console
- Open the folder containing your
3. Without SDK + Using Notepad++ (NppExec Plugin)
- Prerequisite: Notepad++ with the NppExec plugin installed.
- Steps:
- Save your file.
- Use the following NppExec code:
npp_save cd $(CURRENT_DIRECTORY) csc $(FILE_NAME) $(NAME_PART)
4. In Visual Studio Code (VSCode)
- Steps:
- Open a terminal and change directory to where you want to create the console application:
cd D: cd D:\Users\msash\Desktop // (or your preferred directory)
- Create a new console application:
dotnet new console -n YourAppName
- Change into the application directory:
cd YourAppName
- Open the project in VSCode:
code .
- Build the project (optional if you prefer using the CodeRunner extension in VSCode):
dotnet build
- Run the application:
dotnet run
- Open a terminal and change directory to where you want to create the console application:
Java (.java)
Using Notepad++ (NppExec Plugin)
- Prerequisite: Notepad++ with NppExec plugin installed.
- Steps:
- Save your
.java
file. - Use the following NppExec code:
npp_save cd $(CURRENT_DIRECTORY) javac $(FILE_NAME) java $(NAME_PART)
- Save your
Manually in Command Line
- Steps:
- Open the terminal or Command Prompt.
- Navigate to the directory containing the
.java
file. - Compile the Java file:
javac filename.java
- Run the compiled Java program:
java filename
C++ (.cpp)
Using g++ Compiler
- Prerequisite: Install the g++ compiler (usually comes with the GCC package).
- Steps:
- Open a terminal.
- Navigate to the directory containing the
.cpp
file. - Compile the C++ file:
g++ filename.cpp -o filename
- Run the compiled program:
./filename
Using Notepad++ (NppExec Plugin)
- Prerequisite: Notepad++ with NppExec plugin installed.
- Steps:
- Save your
.cpp
file. - Use the following NppExec code:
npp_save cd $(CURRENT_DIRECTORY) g++ $(FILE_NAME) -o $(NAME_PART) $(NAME_PART)
- Save your
Summary of Commands:
-
For C++:
- Using g++:
g++ filename.cpp -o filename && ./filename
- Using g++:
-
For Java:
- Using javac and java:
javac filename.java && java filename
- Using javac and java:
-
For C#:
- Using csc:
csc filename.cs && filename
- Using csc:
Notes:
- Ensure the correct environment is set up (e.g., .NET SDK for C#, Java JDK for Java, and g++ for C++).
- Using an IDE like VSCode or Notepad++ with the right plugins can make compiling and running your programs much easier.