Java for JavaScript Developers
Transfer JavaScript experience to Java through explicit types, collections, methods, and object contracts. Build a connected multi-file order processor and port a stock ledger.
JavaScript and Java side by side
The same program in JavaScript and in Java, from the lessons of this course.
Strings and Output
JavaScript template literals interpolate expressions inside backticks, and console.log accepts several arguments. Java uses ordinary string concatenation or formatting. JavaScript can execute these statements at file scope, whereas the Java demonstration…
JavaScript1const name="Ada"; console.log(`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
JavaScript strict equality compares primitive strings by value and objects by identity. Java String is a reference type whose content comparison uses equals. Translating every JavaScript strict equality to Java reference equality breaks separately allocated…
JavaScript1const a=["a","b"].join(""); const b="ab"; console.log(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
JavaScript arrays are resizable objects and can mix value types. Java arrays have a fixed length and component type. JavaScript at(-1) can read the last element, whereas Java requires an explicit nonnegative last index. A Java array has one component type and…
JavaScript1const a=[2,4,6]; console.log(a.at(-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
JavaScript permits any truthy loop condition while Java demands a boolean. Both languages support break and continue. A JavaScript while condition that depends on an object or numeric value needs an explicit comparison when ported. Java break exits a loop…
JavaScript1const kept=[];for(const word of ["tea","","STOP","coffee"]){if(word==="STOP")break;if(word==="")continue;kept.push(word);}console.log(kept.join(","));Java1import 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}Static Methods and Returns
JavaScript function declarations can live at module scope and return values without a declared return type. Java static utility methods live inside a class and declare their result type. Both languages pass object references as values; rebinding a parameter…
JavaScript1function hours(total){return Math.trunc(total/60);} console.log(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
JavaScript parseInt accepts a valid numeric prefix, and Number has different conversion rules. Java Integer.parseInt requires a complete valid integer representation and has fixed-range overflow checks. Choose validation intentionally instead of translating…
JavaScript1console.log(parseInt("12cats",10));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 JavaScript Developers for?
For people who already write JavaScript and want to learn Java. Each lesson starts from JavaScript 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 JavaScript basics: variables, conditions, loops, functions and collections.
How many lessons does Java for JavaScript Developers have?
Java for JavaScript Developers contains 48 interactive lessons you can complete at your own pace.
What does Java for JavaScript 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 JavaScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.