C for Java Developers
Move from Java to C17: explicit interfaces, pointers, arrays, strings, ownership and structs. Build a multi-file stock ledger and port two complete programs.
Java and C side by side
The same program in Java and in C, from the lessons of this course.
Printing and Comments
Java printf checks format compatibility at runtime. C variadic formatting lacks that object-type safety; use a conversion matching the promoted argument type.
Java1 2public class Main {3 4public static void main(String[] args) {5System.out.printf("value=%d%n",7);6}7}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10printf("value=%d\n",7);11return 0;12}Booleans and Branches
Java requires boolean conditions and an explicit emptiness test. C accepts scalar conditions, but an empty-string pointer is non-null and therefore true.
Java1 2public class Main {3 4public static void main(String[] args) {5String s="";System.out.println(s.isEmpty());6}7}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10const char *s=""; printf("%s\n",s?"true":"false");11return 0;12}Arrays Need Lengths
Java arrays are objects with a runtime length. C array parameters become pointers, losing the bound; pass size_t length explicitly rather than looking for an array.length member.
Java1 2public class Main {3 4public static void main(String[] args) {5int[] a={2,4,6};System.out.println(a.length);6}7}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10int a[]={2,4,6};printf("%zu\n",sizeof a/sizeof a[0]);11return 0;12}Function Arguments Are Values
Java passes primitive values and object references by value. C also passes values; passing a pointer copies the pointer while enabling access to the pointed-to object. Neither reassigns an ordinary caller variable automatically.
Java1 2public class Main {3static void change(int x){x=9;}4public static void main(String[] args) {5int x=2;change(x);System.out.println(x);6}7}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8static void change(int n){n=9;(void)n;}9int main(void) {10int x=2;change(x);printf("%d\n",x);11return 0;12}Addresses and Dereferencing
Java aliases managed objects without exposing their addresses. C address-taking and dereferencing provide explicit indirect access, with lifetime validity enforced by the programmer rather than garbage collection.
Java1 2public class Main {3 4public static void main(String[] args) {5int[] cell={2};int[] alias=cell;alias[0]=5;System.out.println(cell[0]);6}7}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10int n=2;int *p=&n;*p=5;printf("%d\n",n);11return 0;12}Parsing with Status Results
Java regex matching can validate a whole string. C sscanf may successfully consume only a numeric prefix; full-input validation must be a separate, explicit part of the parser contract.
Java1 2public class Main {3 4public static void main(String[] args) {5System.out.println("12x".matches("[0-9]+"));6}7}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10const char *s="12x";int ok=*s!=0;for(size_t i=0;s[i];i++)if(s[i]<'0'||s[i]>'9')ok=0;printf("%d\n",ok);11return 0;12}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsCompile and Compute
6 lessonsDecisions and Loops
5 lessonsArrays and Text
5 lessonsFunctions and Interfaces
5 lessonsPointers and Structs
5 lessonsValidation and Text Buffers
5 lessonsOwned Dynamic Memory
5 lessonsTagged Data and Composition
6 lessonsProject: Stock Ledger
4 lessonsFinal Source Ports
2 lessonsFrequently asked questions
Who is C for Java Developers for?
For people who already write Java and want to learn C. Each lesson starts from Java you know and shows how C does the same thing, so you skip the beginner basics.
Do I need to know C already?
No. The course starts with your first C program. You need Java basics: variables, conditions, loops, functions and collections.
How many lessons does C for Java Developers have?
C for Java Developers contains 48 interactive lessons you can complete at your own pace.
What does C for Java Developers cover?
The course is organized into chapters covering: Compile and Compute, Decisions and Loops, Arrays and Text, Functions and Interfaces, and more.
Is C for Java Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.