CSCI 127 Joy and Beauty of Data · Unit 4: Data science · on Final exam (Exam 3)
4.4 Python vs C vs Java, and the final
Study notes for Python vs C vs Java, and the final in CSCI 127 Joy and Beauty of Data at Montana State University: the big ideas, code you should know, a worked example, common mistakes and an exam tip. The same topic has endless practice questions and flashcards in Mathub.
Big ideas
- Python is interpreted and dynamically typed: you run source code directly and a variable can hold any type. C and Java are compiled and statically typed: every variable declares a type and mistakes are caught before running.
- Speed: compiled C runs many times faster than Python; Java sits between (compiled to bytecode, run by a virtual machine). Python wins on writing speed and libraries, which is why data science lives there.
- Memory: C makes you manage memory by hand (malloc/free); Java and Python collect garbage automatically. Python indents blocks; C and Java use braces and semicolons.
- Same idea, three spellings: a for loop, a function, a class look alike once you know one language. CSCI 132 continues in a compiled language.
- Final exam prep: it is the third equally weighted exam and centers on Unit 4 (NumPy, matplotlib, pandas), but the reading-code skills from Units 1–3 are assumed.
Code you should know
The same loop in three languages (only Python runs here)
# Python
total = 0
for i in range(1, 6):
total += i
print(total)
# C
# int total = 0;
# for (int i = 1; i <= 5; i++) { total += i; }
# printf("%d\n", total);
# Java
# int total = 0;
# for (int i = 1; i <= 5; i++) { total += i; }
# System.out.println(total);Output
15
Worked example
Name two advantages of Python over C and two of C over Python.
Show the solution
Python: shorter code, no compile step, dynamic typing and huge libraries (NumPy, pandas). C: much faster execution, control over memory and hardware, errors caught at compile time.
Common mistakes
- Calling Java “interpreted” or Python “compiled” without qualification: Python compiles to bytecode internally but is run by an interpreter; Java compiles to bytecode for the JVM.
Exam tipFor the final, redo Labs 11–14 and Program 5, then run through the Unit 4 flashcards and the practice quiz in the Exam prep page.
Keep going in Mathub
Mathub is free for Montana State students: an endless quizzer with worked explanations, one-question lessons, flashcards, exam prep checklists, the class calendar with every deadline, a grade calculator and a study board for CSCI 127.