C#
JV

C# to Java

10 lessons

Progress0%
1Introduction2Type Systems3Properties & Getters4Generics5Collections6LINQ to Streams7Async Programming8Ecosystem9Modern Java Features10Concurrency
All Mirror Courses
C#
JV
Introduction
MirrorLesson 1 of 10
Lesson 1

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.

Mirror Card
C#
From C#:

In C#, you're familiar with introduction.

JV
In Java:

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:

JV
Java 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#:

C#
C# (What you know)
using System;

class Hello {
    static void Main() {
        Console.WriteLine("Hello");
    }
}
Mirror Card
C#
From C#:

You may be used to different syntax or behavior.

JV
In Java:

using vs import for bringing in namespaces/packages

Mirror Card
C#
From C#:

You may be used to different syntax or behavior.

JV
In Java:

Console.WriteLine vs System.out.println for printing

Mirror Card
C#
From C#:

You may be used to different syntax or behavior.

JV
In Java:

static void Main() vs public static void main(String[]) — Java requires public and lowercase main

Mirror Card
C#
From C#:

You may be used to different syntax or behavior.

JV
In Java:

C# runs on .NET/CLR; Java runs on JVM

Mirror Card
C#
From C#:

You may be used to different syntax or behavior.

JV
In Java:

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.

C#
C#
static void Main() {
    Console.WriteLine("Hello");
}
JV
Java
public static void main(String[] args) {
    System.out.println("Hello");
}
Common Pitfall
If you capitalize 'Main' in Java the JVM won't find your entry point and will throw a runtime error.

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.

C#
C#
using System;
using System.Collections.Generic;
JV
Java
import java.util.ArrayList;
import java.util.List;
// java.lang.* (String, Math, etc.) is auto-imported

3. Print Statements

Console.WriteLine has a direct Java equivalent. System.out is a PrintStream object with println, print, and printf methods.

C#
C#
Console.WriteLine("Hello");
Console.Write("No newline");
Console.WriteLine($"Value: {x}");
JV
Java
System.out.println("Hello");
System.out.print("No newline");
System.out.printf("Value: %d%n", x);
Rule of Thumb
println adds a newline; print does not. Use printf for formatted output just like C#'s string.Format.

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.

JV
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 runtime
Rule of Thumb
Think of the JVM and CLR as siblings. Most performance intuitions transfer directly.

Common 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
Common Pitfall
Don't assume Java works exactly like C#. While the concepts may be similar, the syntax and behavior can differ significantly.

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
Rule of Thumb
The best way to learn is by doing. Try rewriting some of your C# code in Java to practice these concepts.
OverviewNext