December 21, 2023 • Reading time: 909 minutes

C vs Java - WOW!

My experience with learning C (so far) and why it is still a relevant language today

Programming


Last year in my Computer Science class at Eastern Suffolk BOCES, I began my development journey. I began by learning the proven programming language, Java. Since then I have created hundreds of individual applications, some even for customers as you may read my experience about. I have formed an inner love for Java, however this love has evolved to more of a comfort. It is my experience in life that being comfortable is a blessing, but also a curse, as while you may feel content in life of where you are currently at, you sort-of put a pause on learning, whether that be temporary or permanently. While this may not be true for all, it seemingly is for me! With this in mind, I have decided with my mentors direction, Mr. Myers, that it would greatly benefit me to learn another programming language and breakout of the comfort that I experience. 

With learning another programming language in mind, picking the right language was difficult. I considered various languages such as Python, C++, and even Fortran! But, throughout all of these languages, another language massively appealed to me: C. The C programming language was created in the 1970s by Dennis Ritchie and is still massively used today in various use-cases such as device drivers, operating systems, and more. This is due to its capability to directly manage memory, also known as "bare metal". Thus, I set off to learn the C Programming language with the help of the first book ever covering C, named "The C Programming Language" by Brian W Kernighan & Dennis M. Ritchie. This book was originally copyrighted in 1978, and was provided to me by my mentor to read. It is the same book that he had originally learned C from over 30 years ago during an internship. The excitement that I felt in preparation of learning C was greatly comparative to paving a completely new path in life; almost the same as if you're learning a whole new language to speak, and communicate to others with.

This week I set off to begin learning C. Something that I learned fairly fast, is that many elements and concepts that I have been taught in Java are mostly synonymous with C. For example, Java and C both have the same loop control statements (while, do-while, for) and control statements (if, else, switch). The way that these operate are almost the exact same. As this is the only other programming language that I have learned so far, I would make the assumption that other modern languages such as Python and C++ also feature the same, however I think that it is pretty cool for such an old language to be fairly similar in this regard to modern languages.

With some basic concepts of the language learned, I decided that I would like to put performance to the test and see what I was really learning the language for. It is a well known concept that C is an extremely fast and efficient language due to the nature of it being a low level programming language as well as access to direct memory (ram) management. In opposition, Java is a higher level language with no access to memory management, but instead a garbage collector which performs automatic memory management -- greatly decreasing efficiency of applications as well as resource usage. To my dismay, this would prove to be exactly right! To test such, I made a simple application containing three effective lines of code in both C and Java: a (for) loop that would iterate forever, and print a count to console that would increment by each iteration.

While performance may vary in different situations, this is a simple benchmark that would work, and the results were absolutely stunning. After only a few minutes of running the code, and providing Java a one second head start, the application written in C was over 1.8x as fast as the Java application and utilized 50% less CPU usage. This was an absolutely stunning result, and displayed the true use of C to me. WOW! I absolutely cannot wait to dive further into C and further report my results here.

 

(Java left, C right)