Introduction
Introduction
Introduction
In this lesson, you'll learn about introduction in Java. Coming from C#, you already have a foundation for understanding this concept. We'll build on that knowledge while highlighting the key differences.
In C#, you're familiar with introduction.
Java has its own approach to introduction, which we'll explore step by step.
The Java Way
Let's see how Java handles this concept. Here's a typical example:
class Hello {
public static void main(String[] args) {
System.out.println("Hello");
}
}Comparing to C#
Here's how you might have written similar code in C#:
using System;
class Hello {
static void Main() {
Console.WriteLine("Hello");
}
}You may be used to different syntax or behavior.
using vs import for bringing in namespaces/packages
You may be used to different syntax or behavior.
Console.WriteLine vs System.out.println for printing
You may be used to different syntax or behavior.
static void Main() vs public static void main(String[]) — Java requires public and lowercase main
You may be used to different syntax or behavior.
C# runs on .NET/CLR; Java runs on JVM
You may be used to different syntax or behavior.
Both require a class as the entry point
Step-by-Step Breakdown
1. Entry Point Differences
In C# the entry point is 'static void Main()'. In Java it must be exactly 'public static void main(String[] args)' — lowercase m, public, and the args parameter is required.
static void Main() {
Console.WriteLine("Hello");
}public static void main(String[] args) {
System.out.println("Hello");
}2. Namespaces vs Packages
C# uses 'using' to import namespaces. Java uses 'import' to import packages. Java's java.lang is always imported automatically — no need to import System equivalent.
using System;
using System.Collections.Generic;import java.util.ArrayList;
import java.util.List;
// java.lang.* (String, Math, etc.) is auto-imported3. Print Statements
Console.WriteLine has a direct Java equivalent. System.out is a PrintStream object with println, print, and printf methods.
Console.WriteLine("Hello");
Console.Write("No newline");
Console.WriteLine($"Value: {x}");System.out.println("Hello");
System.out.print("No newline");
System.out.printf("Value: %d%n", x);4. Runtime Platforms
Both languages compile to bytecode and run on a managed runtime with a JIT compiler and garbage collector. The key difference is ecosystem: .NET for C#, JVM for Java.
// C# compilation chain:
// .cs -> (csc/Roslyn) -> .dll/.exe -> CLR JIT -> machine code
// Java compilation chain:
// .java -> (javac) -> .class -> JVM JIT -> machine code
// Both have GC, reflection, and generics at runtimeCommon Mistakes
When coming from C#, developers often make these mistakes:
- using vs import for bringing in namespaces/packages
- Console.WriteLine vs System.out.println for printing
- static void Main() vs public static void main(String[]) — Java requires public and lowercase main
Key Takeaways
- Java entry point is 'public static void main(String[] args)' — lowercase, public, args required
- Use import instead of using; java.lang is always available
- System.out.println replaces Console.WriteLine
- Both platforms are managed runtimes with GC and JIT