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.
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…
Ruby1name="Ada"; puts "Hi "+name+" !"Java1import 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}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…
Ruby1a="ab";b="a"+"b";puts(a==b)Java1import 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}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…
Ruby1values=[2,4,6];puts values[-1]Java1import 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}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…
Ruby1n=3;while n>1;n-=1;end;puts nJava1public 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}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…
Ruby1def hours(total);total/60;end;puts hours(125)Java1import 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}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…
Ruby1cents=305;puts format("tea: %d.%02d",cents/100,cents%100)Java1import 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 questionsGetting Started in Java
6 lessonsValues and Decisions
5 lessonsCollections and References
5 lessonsIteration and Pipelines
5 lessonsMethods and Callbacks
5 lessonsInput, Errors, and Files
5 lessonsClasses and State
6 lessonsComposition and Contracts
5 lessonsProject: Order Processing
4 lessonsFinal Challenges
2 lessonsFrequently 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.