Programming Language Examples

JavaScript


class Person {
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }

    greet() {
        console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
    }
}

const person = new Person("Alice", 30);
person.greet();
    

Python


class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def greet(self):
        print(f"Hello, my name is {self.name} and I am {self.age} years old.")

person = Person("Alice", 30)
person.greet()
    

Java


class Person {
    String name;
    int age;

    Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    void greet() {
        System.out.println("Hello, my name is " + name + " and I am " + age + " years old.");
    }

    public static void main(String[] args) {
        Person person = new Person("Alice", 30);
        person.greet();
    }
}
    

C++


#include 
#include 

class Person {
public:
    std::string name;
    int age;

    Person(std::string name, int age) {
        this->name = name;
        this->age = age;
    }

    void greet() {
        std::cout << "Hello, my name is " << name << " and I am " << age << " years old." << std::endl;
    }
};

int main() {
    Person person("Alice", 30);
    person.greet();
    return 0;
}
    

C#


using System;

class Person {
    public string Name { get; set; }
    public int Age { get; set; }

    public Person(string name, int age) {
        Name = name;
        Age = age;
    }

    public void Greet() {
        Console.WriteLine($"Hello, my name is {Name} and I am {Age} years old.");
    }
}

class Program {
    static void Main() {
        Person person = new Person("Alice", 30);
        person.Greet();
    }
}
    

PHP


class Person {
    public $name;
    public $age;

    public function __construct($name, $age) {
        $this->name = $name;
        $this->age = $age;
    }

    public function greet() {
        echo "Hello, my name is {$this->name} and I am {$this->age} years old.";
    }
}

$person = new Person("Alice", 30);
$person->greet();
    

Swift


class Person {
    var name: String
    var age: Int

    init(name: String, age: Int) {
        self.name = name
        self.age = age
    }

    func greet() {
        print("Hello, my name is \(name) and I am \(age) years old.")
    }
}

let person = Person(name: "Alice", age: 30)
person.greet()
    

Go


package main

import "fmt"

type Person struct {
    name string
    age  int
}

func (p Person) greet() {
    fmt.Printf("Hello, my name is %s and I am %d years old.\n", p.name, p.age)
}

func main() {
    person := Person{name: "Alice", age: 30}
    person.greet()
}
    

Ruby


class Person
    attr_accessor :name, :age

    def initialize(name, age)
        @name = name
        @age = age
    end

    def greet
        puts "Hello, my name is #{@name} and I am #{@age} years old."
    end
end

person = Person.new("Alice", 30)
person.greet
    

R


Person <- setRefClass("Person",
    fields = list(name = "character", age = "numeric"),
    methods = list(
        greet = function() {
            cat("Hello, my name is ", name, " and I am ", age, " years old.\n")
        }
    )
)

person <- Person$new(name = "Alice", age = 30)
person$greet()
    
>>Top 10 Programming Languages and Their Uses

Languages in Web Development

Web development relies on various programming languages to create dynamic, functional, and visually appealing websites. These languages are divided into different categories based on their roles in development.

Frontend Languages

Frontend development focuses on the user interface and experience. The key languages include:

  • HTML: Defines the structure and content of a web page.
  • CSS: Styles the appearance of web elements.
  • JavaScript: Adds interactivity and dynamic behavior.

Backend Languages

Backend development involves server-side operations and database management. Common backend languages include:

  • Python: Used with frameworks like Django and Flask for building robust applications.
  • PHP: A widely used server-side scripting language.
  • Node.js: Allows JavaScript to be used for backend development.
  • Ruby: Known for its simplicity, often used with Ruby on Rails.

Database Languages

Databases store and manage data efficiently. The main languages for databases include:

  • SQL: Structured Query Language used for managing relational databases.
  • NoSQL: Includes databases like MongoDB that store data in flexible formats.

Conclusion

Web development integrates multiple languages to ensure seamless functionality. Understanding the role of each language helps developers build efficient and scalable web applications.