DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Nitin Bansal
Nitin Bansal

Posted on

I made chatGPT to write hello world program in all major languages

✨The entirety of these are generated by chatGPT, including descriptions around building and running them πŸš€πŸ€–βœ¨

How awesome this is!!😎

Read on..


1. Java

public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
}
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file named HelloWorld.java and compile it using the javac command:

javac HelloWorld.java
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

2. JavaScript

console.log("Hello, World!");
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file with a .js extension, such as hello-world.js, and run it using a JavaScript interpreter, such as Node.js:

node hello-world.js
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

3. Python

Here is a hello-world program in Python:

print("Hello, World!")
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file with a .py extension, such as hello-world.py, and run it using a Python interpreter:

python hello-world.py
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

4. Golang

Here is a hello-world program in Go:

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file named hello-world.go and compile it using the go build command:

go build hello-world.go
Enter fullscreen mode Exit fullscreen mode

This will create an executable file named hello-world in the same directory. Run this file to see the output:

./hello-world
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

5. Rust

Here is a hello-world program in Rust:

fn main() {
    println!("Hello, World!");
}
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file named hello-world.rs and compile it using the rustc command:

rustc hello-world.rs
Enter fullscreen mode Exit fullscreen mode

This will create an executable file named hello-world in the same directory. Run this file to see the output:

./hello-world
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

6. C

Here is a hello-world program in C:

#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file named hello-world.c and compile it using the gcc command:

gcc hello-world.c -o hello-world
Enter fullscreen mode Exit fullscreen mode

This will create an executable file named hello-world in the same directory. Run this file to see the output:

./hello-world
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

7. C++

Here is a hello-world program in C++:

#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file named hello-world.cpp and compile it using the g++ command:

g++ hello-world.cpp -o hello-world
Enter fullscreen mode Exit fullscreen mode

This will create an executable file named hello-world in the same directory. Run this file to see the output:

./hello-world
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

8. Ruby

Here is a hello-world program in Ruby:

puts "Hello, World!"
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file with a .rb extension, such as hello-world.rb, and run it using a Ruby interpreter:

ruby hello-world.rb
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

9. Clojure

Here is a hello-world program in Clojure:

(println "Hello, World!")
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file with a .clj extension, such as hello-world.clj, and run it using the clojure command:

clojure hello-world.clj
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

10. Elixir

Here is a hello-world program in Elixir:

IO.puts "Hello, World!"
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file with a .exs extension, such as hello-world.exs, and run it using the elixir command:

elixir hello-world.exs
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

11. C-sharp

Here is a hello-world program in C#:

using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file named HelloWorld.cs and compile it using the csc command:

csc HelloWorld.cs
Enter fullscreen mode Exit fullscreen mode

This will create an executable file named HelloWorld.exe in the same directory. Run this file to see the output:

HelloWorld.exe
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

12. PHP

Here is a hello-world program in PHP:

<?php

echo "Hello, World!";
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file with a .php extension, such as hello-world.php, and run it using the php command:

php hello-world.php
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

13. Perl

Here is a hello-world program in Perl:

use strict;
use warnings;

print "Hello, World!\n";
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file with a .pl extension, such as hello-world.pl, and run it using the perl command:

perl hello-world.pl
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

14. Swift

Here is a hello-world program in Swift:

print("Hello, World!")
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file with a .swift extension, such as hello-world.swift, and run it using the swift command:

swift hello-world.swift
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

15. Objective-C

Here is a hello-world program in Objective-C:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog(@"Hello, World!");
    }
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file named hello-world.m and compile it using the clang command:

clang -fobjc-arc hello-world.m -o hello-world
Enter fullscreen mode Exit fullscreen mode

This will create an executable file named hello-world in the same directory. Run this file to see the output:

./hello-world
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

16. Kotlin

Here is a hello-world program in Kotlin:

fun main() {
    println("Hello, World!")
}
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file with a .kt extension, such as hello-world.kt, and compile it using the kotlinc command:

kotlinc hello-world.kt -include-runtime -d hello-world.jar
Enter fullscreen mode Exit fullscreen mode

This will create a JAR file named hello-world.jar in the same directory. Run this file to see the output:

java -jar hello-world.jar
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

17. Scala

Here is a hello-world program in Scala:

object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Hello, World!")
  }
}
Enter fullscreen mode Exit fullscreen mode

To run this program, save it in a file with a .scala extension, such as hello-world.scala, and compile it using the scalac command:

scalac hello-world.scala
Enter fullscreen mode Exit fullscreen mode

This will create a class file named HelloWorld.class in the same directory. Run this file using the scala command:

scala HelloWorld
Enter fullscreen mode Exit fullscreen mode

This will print "Hello, World!" to the console.

Top comments (0)

12 Gorgeous UI Components for Your Design Inspiration

>> Check out this classic DEV post <<