Menu
CoddyTech
Course

Java for Ruby Developers

Transfer Ruby experience to Java through typed values, control flow, collections, methods and object contracts. Build a connected multi-file order processor and port a stock ledger.

Ruby and Java side by side

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

  1. Strings and Output

    Ruby puts prints each supplied value with line termination, while print does not add a newline. Java System.out.println accepts one completed value, so combine pieces before the call. Ruby interpolation and Java concatenation are different syntax. Java 17…

    Ruby
    1name="Ada"; puts "Hi "+name+" !"
    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

    Ruby String == compares contents, while equal? tests object identity. Java == on String references tests identity, so use equals for contents and Objects.equals for nullable references. Ruby strings are normally mutable, whereas Java String is immutable…

    Ruby
    1a="ab";b="a"+"b";puts(a==b)
    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

    Ruby Array grows dynamically and supports negative indexing from the end. Java arrays instead have a fixed length, one component type and checked zero-based indexes. A negative Java index throws rather than selecting the last element, and length is a field…

    Ruby
    1values=[2,4,6];puts values[-1]
    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

    Ruby while supports break and next; Java calls the iteration-skip operation continue. Both stop entirely on break, but Java conditions must be Boolean rather than arbitrary truthy values. Ensure a manual index advances on every continuing path, and handle a…

    Ruby
    1n=3;while n>1;n-=1;end;puts n
    Java
    1public class Example {2    public static void main(String[] args) {3        String[] words = {"tea", "", "   ", "cake", "STOP", "later"};4        for (String word : words) {5            if (word.equals("STOP")) {6                break;7            }8            if (word.trim().isEmpty()) {9                continue;10            }11            System.out.println(word);12        }13    }14}
  5. Static Methods and Returns

    Ruby methods use an implicit receiver and return the final evaluated expression unless return says otherwise. Java methods belong to classes and non-void methods require an explicit result on every normal path. Static Java utilities need no object, while…

    Ruby
    1def hours(total);total/60;end;puts hours(125)
    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

    Ruby STDIN.each_line supplies lines and Integer(text,10) validates a complete numeric conversion, unlike permissive to_i. Java Integer.parseInt is strict about trailing characters and does not trim automatically. The course supplies input plumbing and expects…

    Ruby
    1cents=305;puts format("tea: %d.%02d",cents/100,cents%100)
    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 Ruby developers

Learn Java from another language

Frequently asked questions

Who is Java for Ruby Developers for?

For people who already write Ruby and want to learn Java. Each lesson starts from Ruby 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 Ruby basics: variables, conditions, loops, functions and collections.

How many lessons does Java for Ruby Developers have?

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

What does Java for Ruby 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 Ruby 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 Ruby Developers for free

Get started