Menu
CoddyTech
Course

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.

  1. 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…

    C
    1#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}
    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

    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…

    C
    1#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}
    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

    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…

    C
    1#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}
    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

    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…

    C
    1#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}
    Java
    1public 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}
  5. 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…

    C
    1#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}
    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

    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…

    C
    1#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}
    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 C developers

Learn Java from another language

Frequently 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.

Coddy programming languages illustration

Start Java for C Developers for free

Get started