Menu
CoddyTech
Course

Java for C# Developers

Transfer C# experience to Java through explicit types, collections, methods, and object contracts. Build a connected multi-file order processor and port a stock ledger.

C# and Java side by side

The same program in C# and in Java, from the lessons of this course.

  1. Strings and Output

    C# interpolated strings use a dollar prefix, and Console.WriteLine supports formatting overloads. Java uses concatenation or formatting rather than that interpolation syntax. Both languages distinguish character literals from strings, but their entry-method…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Globalization;5class Program {6
    7static void Main() {8string name="Ada";Console.WriteLine($"Hi {name}!");9}10}
    Java
    1import java.util.*;2import java.util.function.*;3import java.util.stream.*;4public class Example {5
    6public static void main(String[] args) {7String name="Ada";System.out.println("Hi "+name+"!");8}9}
  2. String Equality

    C# string equality operators compare string contents. Java == compares String references, so a direct operator-for-operator port can change the result. Other C# classes may overload equality, while Java does not let ordinary classes redefine ==. Use an…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Globalization;5class Program {6
    7static void Main() {8string a=new string(new[]{'a','b'}),b=new string(new[]{'a','b'});Console.WriteLine(a==b);Console.WriteLine(Object.ReferenceEquals(a,b));9}10}
    Java
    1import java.util.*;2import java.util.function.*;3import java.util.stream.*;4public class Example {5
    6public static void main(String[] args) {7String a=new String("ab"),b=new String("ab");System.out.println(a.equals(b));System.out.println(a==b);8}9}
  3. Fixed-size Arrays

    C# and Java arrays both have fixed lengths and mutable elements. C# reads Length with an uppercase property, while Java reads a lowercase length field. C# index-from-end syntax belongs to newer language versions; the explicit length-minus-one form transfers…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Globalization;5class Program {6
    7static void Main() {8int[] a={2,4,6};Console.WriteLine(a[a.Length-1]);9}10}
    Java
    1import java.util.*;2import java.util.function.*;3import java.util.stream.*;4public class Example {5
    6public static void main(String[] args) {7int[]a={2,4,6};System.out.println(a[a.length-1]);8}9}
  4. While and Early Exit

    C# and Java both use break to terminate the nearest loop and continue to skip to its next iteration. A word sentinel demonstrates the distinction independently of numeric accumulation. Java still needs the corresponding string comparison method when matching…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Globalization;5class Program {6
    7static void Main() {8var kept=new List<string>();foreach(string word in new[]{"tea","","STOP","coffee"}){if(word=="STOP")break;if(word.Length==0)continue;kept.Add(word);}Console.WriteLine(String.Join(",",kept));9}10}
    Java
    1import java.util.*;2public class Example {3public static void main(String[] args) {4List<String> kept=new ArrayList<>();5for(String word:new String[]{"tea","","STOP","coffee"}) {6    if(word.equals("STOP")) break;7    if(word.isEmpty()) continue;8    kept.add(word);9}10System.out.println(String.join(",",kept));11}12}
  5. Static Methods and Returns

    C# and Java both distinguish static methods from instance methods, but C# supports ref and out parameter passing that Java does not reproduce directly. Java always passes argument values. A port may need a return value or a dedicated result object instead of…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Globalization;5class Program {6static int Hours(int total){return total/60;}7static void Main() {8Console.WriteLine(Hours(125));9}10}
    Java
    1import java.util.*;2import java.util.function.*;3import java.util.stream.*;4public class Example {5static int hours(int total){return total/60;}6public static void main(String[] args) {7System.out.println(hours(125));8}9}
  6. Input and Exact Formatting

    C# TryParse reports failure through a boolean and an out value. Java Integer.parseInt throws NumberFormatException, so validation usually uses a narrow catch. Both languages offer culture-aware formatting; this course chooses invariant or root-locale output…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Globalization;5class Program {6
    7static void Main() {8int cents=305;Console.WriteLine(String.Format(CultureInfo.InvariantCulture,"tea: {0}.{1:00}",cents/100,cents%100));9}10}
    Java
    1import java.util.*;2import java.util.function.*;3import java.util.stream.*;4public class Example {5
    6public static void main(String[] args) {7int cents=305;System.out.println(String.format(Locale.ROOT,"tea: %d.%02d",cents/100,cents%100));8}9}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Final Challenges

2 lessons

More courses for C# developers

Learn Java from another language

Frequently asked questions

Who is Java for C# Developers for?

For people who already write C# and want to learn Java. Each lesson starts from C# you know and shows how Java does the same thing, so you skip the beginner basics.

Do I need to know Java already?

No. The course starts with your first Java program. You need C# basics: variables, conditions, loops, functions and collections.

How many lessons does Java for C# Developers have?

Java for C# Developers contains 48 interactive lessons you can complete at your own pace.

What does Java for C# Developers cover?

The course is organized into chapters covering: Getting Started in Java, Values and Decisions, Collections and References, Iteration and Pipelines, and more.

Is Java for C# Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start Java for C# Developers for free

Get started