Java for C Developers
Transfer C experience to Java through values, control flow, collections, methods, exceptions, files and object contracts. Build a connected multi-file order processor.
C and Java side by side
The same program in C and in Java, from the lessons of this course.
Strings and Output
C printf formats a byte string using conversion specifiers whose types must match the supplied arguments. Java System.out.println accepts one value; concatenate text or use formatted output to assemble a line. Java String objects are immutable and are not…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <stdarg.h>6#include <errno.h>7#include <limits.h>8#include <ctype.h>9 10 11int main(void) {12const char *name="Ada"; printf("Hi %s!\n",name);13 return 0;14}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
C string contents are compared with strcmp; == on the decayed char pointers compares addresses. Java object == likewise compares references, but String.equals compares content. Use Objects.equals when either Java reference may be null. Do not infer value…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <stdarg.h>6#include <errno.h>7#include <limits.h>8#include <ctype.h>9 10 11int main(void) {12char a[]="ab",b[]="ab"; const char *left=a,*right=b; printf("%s %s\n",strcmp(a,b)==0 ? "true":"false",left==right ? "true":"false");13 return 0;14}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
C arrays have storage and bounds that a pointer parameter alone does not retain. Java arrays are objects with a runtime length fixed after creation; allocation initializes primitive elements to zero and accesses are checked. Uninitialized C automatic storage…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <stdarg.h>6#include <errno.h>7#include <limits.h>8#include <ctype.h>9 10 11int main(void) {12int values[3]={2,4,6}; printf("%zu\n",sizeof values/sizeof values[0]);13 return 0;14}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
C and Java while loops test before the body, break exits the loop, and continue skips the remaining body. Advance a manual index before a possible continue so an ignored item cannot stall the loop. In Java use String.equals for a stop word rather than…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <stdarg.h>6#include <errno.h>7#include <limits.h>8#include <ctype.h>9 10 11int main(void) {12int n=3; while(n>1) --n; printf("%d\n",n);13 return 0;14}Java1public class Example {2 public static void main(String[] args) {3 String[] words = {"red", "", "blue", "STOP", "green"};4 int index = 0;5 while (index < words.length) {6 String word = words[index++];7 if (word.equals("STOP")) break;8 if (word.isEmpty()) continue;9 System.out.println(word);10 }11 }12}Static Methods and Returns
C functions may be declared at file scope and a static function has internal linkage. Java static methods belong to classes and need no instance receiver; static has a different role from C linkage. Declare a return type and return on every normal path of a…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <stdarg.h>6#include <errno.h>7#include <limits.h>8#include <ctype.h>9 10static int hours(int total) { return total/60; }11int main(void) {12printf("%d\n",hours(125));13 return 0;14}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
C token readers and line readers have different whitespace behavior, and strtol exposes an end pointer for checking trailing text. Java Scanner and line-based input have similar distinctions, while Integer.parseInt requires a complete integer string. Keep…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <stdarg.h>6#include <errno.h>7#include <limits.h>8#include <ctype.h>9 10 11int main(void) {12int cents=305; printf("tea: %d.%02d\n",cents/100,cents%100);13 return 0;14}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 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.