Comparing common computer languages with Copilot!
In many computer science classes, it's a tradition to begin with a 'Hello World' program. This project embraces that tradition while also showcasing the power of AI in creating dynamic applications in various languages. In this case, we wanted to compare Java, Python and JavaScript.
Starting with a prompt to create a Java app, we then instructed Copilot to produce the same code in Python and JavaScript. The result? A view of each of the languages side by side, highlighting their similarities and differences.
For comparison, you might want to see our 2023 Hello World JavaScript app.
For an historical perspective on 'Hello World', check out the Why Hello World movie clip.
Human's Note:
Notice how the 3 panels below are too narrow to display the code properly? That's why they were styled to be scrollable horizontally. That's not optimum but it does happen. Then we thought: Could Copilot help us with that? So we asked him to create a modal dialog that would display the code in a larger view. And it did! Click the 'View' button in each panel to see the code in a modal dialog. Be sure to check out the code to see how that was done. Thanks, Copilot!
HelloWorldWhimsy.java
// HelloWorldWhimsy.java
// A whimsical introduction to Java for Pythonistas!
// This program demonstrates the essentials:
// classes, methods, main, variables, printing, and comments.
// Get ready for AP Computer Science with a smile :)
// Every Java program starts with a class definition.
// The class name should match the filename!
/*
Prompt:
techtoolsguru: I am a high school computer science
teacher and this year I want to train students
in Java using AI. In the tradition of 'Hello World'
would you create a whimsical 'Hello World' app
in Java that touches on the essential elements
a 'newbie' would need to get started with Java.
(Students are getting ready for the AP Computer
Science Exam in May 2026). Please add lots
of comments to guide the development thought
process. These students have already had
training in Python3.
GitHub Copilot: Made changes.
I've created a whimsical Java "Hello World"
app called HelloWorldWhimsy.java in your
`JavaHelloWorld` folder. It includes lots
of comments to guide students who already
know Python, covering Java essentials like
classes, methods, variables, printing,
conditionals, and loops. Let me know
if you'd like to see or run the code!
*/
public class HelloWorldWhimsy {
// The main method is the entry point of every Java application.
// It's like Python's 'if __name__ == "__main__":', but always named 'main'.
public static void main(String[] args) {
// Print a message to the console (like Python's print function)
System.out.println("Hello, whimsical world of Java!");
// Variables must have a type in Java (unlike Python's dynamic typing)
int year = 2026; // Integer variable
String greeting = "Welcome to AP Computer Science!"; // String variable
double piApprox = 3.14; // Double-precision floating point
// Print variables (note the + for string concatenation)
System.out.println("The year is: " + year);
System.out.println(greeting);
System.out.println("Did you know? Pi is approximately " + piApprox);
// Let's do a simple calculation
int students = 20;
int computers = 18;
int difference = students - computers;
System.out.println("Difference between students and computers: " + difference);
// Conditional statements (if/else) -
// similar to Python, but with parentheses and curly braces
if (students > computers) {
System.out.println("We need more computers!");
} else {
System.out.println("Everyone has a computer. Yay!");
}
// Loops: for loop (like Python's for i in range(...))
System.out.println("Counting to 5:");
for (int i = 1; i <= 5; i++) {
System.out.println(i);
}
// Method call (see below)
sayGoodbye();
}//end main method
// Methods are like Python functions,
// but must be inside a class
public static void sayGoodbye() {
System.out.println("Goodbye, and happy coding!");
}//end sayGoodbye
}//end class HelloWorldWhimsy
/*
Output:
Hello, whimsical world of Java!
The year is: 2026
Welcome to AP Computer Science!
Did you know? Pi is approximately 3.14
Difference between students and computers: 2
We need more computers!
Counting to 5:
1
2
3
4
5
Goodbye, and happy coding!
*/
HelloPython.py
# HelloPython.py
'''
techtoolsguru:
Your 'HelloWorldWhimsy' was fantastic.
I'm also teaching a beginning Python3
course. Can you 'refactor' this program
as 'HelloPython.py' and add lots of
comments to guide a new learner into
the world of Python?
Copilot:
I've created a Python version called
HelloPython.py in the same folder. It
mirrors the whimsical style and
essential concepts from the Java
version, with lots of comments to
guide new Python learners. Let me
know if you'd like to see or run the code!
'''
# A whimsical introduction to Python for Java converts and new coders!
# This program demonstrates the essentials: variables, printing,
# comments, conditionals, loops, and functions.
# Get ready for a fun journey into Python programming :)
# In Python, you don't need to define a class for a simple script.
# Let's start with a friendly greeting!
print("Hello, whimsical world of Python!")
# Variables in Python are dynamically typed (no need to declare the type)
year = 2026 # Integer variable
greeting = "Welcome to AP Computer Science!" # String variable
pi_approx = 3.14 # Floating point variable
# Print variables (note the comma or + for string concatenation)
print("The year is:", year)
print(greeting)
print("Did you know? Pi is approximately", pi_approx)
# Let's do a simple calculation
students = 20
computers = 18
difference = students - computers
print("Difference between students and computers:", difference)
# Conditional statements (if/else) -
# similar to Java, but no parentheses or curly braces
if students > computers:
print("We need more computers!")
else:
print("Everyone has a computer. Yay!")
# Loops: for loop (like Java's for loop,
# but more readable)
print("Counting to 5:")
for i in range(1, 6): # range(1, 6) gives 1, 2, 3, 4, 5
print(i)
# Functions are defined with 'def'
# and can be called like methods in Java
def say_goodbye():
print("Goodbye, and happy coding!")
#end say_goodbye
# Call the function
say_goodbye()
# Output (for reference):
# Hello, whimsical world of Python!
# The year is: 2026
# Welcome to AP Computer Science!
# Did you know? Pi is approximately 3.14
# Difference between students and computers: 2
# We need more computers!
# Counting to 5:
# 1
# 2
# 3
# 4
# 5
# Goodbye, and happy coding!
HelloWebComputing.js
/*
I'm also teaching a course in HTML, CSS
and JavaScript. What would you suggest
for a similar app using those
technologies that captures the
essence of the Java and Python
applications? Please create it in a
single file: HelloWebComputing.html
and make sure it validates. Please
add lots of comments there too
to guide a new web developer
into the essentials of HTML and CSS.
*/
// This is a JavaScript comment. JS code makes your page interactive.
// Let's define some variables (no type needed, like Python)
const year = 2026;
const greeting = "Welcome to AP Computer Science!";
const piApprox = 3.14;
let students = 20;
let computers = 18;
let difference = students - computers;
// Function to display whimsical output in the page
function showWhimsy() {
// Use template literals (backticks) for easy
// string formatting
let output = `
<strong>The year is:</strong> ${year}
${greeting}
Did you know? Pi is approximately <strong>${piApprox}</strong>
Difference between students and computers: <strong>${difference}</strong>
`;
// Conditional statement (if/else)
if (students > computers) {
output += "We need more computers!
";
} else {
output += "Everyone has a computer. Yay!
";
}
// Loop: for loop (like Java and Python)
output += "Counting to 5:
";
for (let i = 1; i <= 5; i++) {
output += i + "<br>";
}
// Function call
output += sayGoodbye();
// Display the output in the page
document.getElementById('output').innerHTML = output;
}
// Functions in JavaScript are defined with 'function' or as arrow functions
function sayGoodbye() {
return "Goodbye, and happy coding!";
}