
Master readable C and Java programs by applying formatting, syntax highlighting, and debugging with gdp and Eclipse. Explore IDE tools, breakpoints, and practical exercises to build robust code.
Students will understand the concept of syntax highlighting and how to add syntax highlighting if the Text Editor doesn't initially support it.
learn how to give variables clear names in C and Java by replacing x, y, a, and d with meaningful terms like heights, weights, and BMI using find and replace.
Apply the dry rule to reduce repeat code with a for loop or a function, lowering copy-paste mistakes, saving time, and increasing flexibility in C and Java.
Learn how a for loop eliminates repeated code by initializing a counter, applying a condition, and incrementing each iteration to print values and simplify BMI printing logic.
Discover how and where to add comments in C, using single-line // and multi-line /* */ styles, to explain design choices, document version info, and improve code readability without overcommenting.
Learn why keeping functions under 10 lines improves readability, with a practical example that splits a long function into three parts, highlighting testing and debugging benefits.
Learn to compile C programs with a compiler such as GCC or klong in a terminal, specify source file and output, and enable debugging and warnings with -g and -Wall.
Opening a terminal on Linux.
On Linux to open a terminal you can navigate to the folder containing the C file using the "cd" (change directory) command at the terminal. Or you can use the GUI (Graphical User Interface) and right click inside the folder where you want to open the terminal and then select "Open Terminal".
Opening a terminal on Mac.
To open a terminal in a specific folder in Mac you can open a folder anywhere and then use the "cd" command to navigate to the folder containing the source code you are looking to execute.
If you want to open a terminal from inside Finder then go into System Preferences and select Keyboard > Shortcuts > Services. Find "New Terminal at Folder" in the settings and tick the box. Then navigate to the folder containing the file you want to compile and select "New Terminal at Folder".
Opening a terminal on Windows.
To open a terminal on windows at a specific folder you can't use the "cd" command. So instead you have to navigate inside the folder containing the source code you wish to compile using the File Explorer. Then at the top of the screen where the file path is, delete the file path and type "cmd", finally hit enter to open a terminal at the folder.
As GDB was initially designed for Linux installing it there is very straightforward. Just open a terminal and give the command:
sudo apt-get install gdb
Install lldb on Mac using Homebrew, explain the challenges and differences versus other debuggers, and offer a web-based debugging option as an alternative.
Install mingw-w64 as the Windows package manager and install gcc and gdb from SourceForge. Update the system PATH to include the mingw bin folder and verify the installation.
Discover how to debug C programs online using onlinegdb.com, including compiling, running, and stepping with breakpoints, local variables, and watch expressions in your browser. Compare this online workflow to traditional IDEs, noting limitations for large multi-file projects and recommending desktop tools for bigger programs while still using online debugging for quick checks.
Learn the essential gdb commands to debug programs in C and Java, including breakpoints, run, continue, step, and print for local variables, arrays, and pointers.
Master how to use gdb commands like next, step, quit, list, and watch to navigate code, manage breakpoints, and efficiently debug broken programs.
Learn to debug c and java programs with GDP to identify infinite loops and inspect variables like count and carry on to fix initialization and loop structure.
Debug a segmentation fault in a C program by tracing memory misuse with gdb breakpoints and fix it by allocating string space or using malloc or realloc.
Debug a C program that multiplies a numbers array to produce products and hits overflow with large values. Fix by switching to a larger data type and using gdb breakpoints.
Explore using JDB as an alternative to Eclipse for debugging Java from the terminal, with installation tips, basic commands, and trade-offs with Eclipse's ease and features.
Install Java development kit and Eclipse on Mac or Windows, then set up a workspace and create a Java project with a main class to run.
Add watchpoints in Eclipse to track the global variable x with the outline view and pencil icon, and observe the debugger pausing at each access or write of x.
Set exception breakpoints to pause the program just before a pointer exception is thrown, and inspect variables and vitals; optionally add a generic exception breakpoint for broader monitoring.
Track variables and expressions in Eclipse to debug Java programs by setting breakpoints, stepping through code, and observing how x and y change, including expressions like x*y.
Explore debugging techniques in C and Java by examining a countdown example, using conditional breakpoints and break statements in a switch case to isolate and fix a default case behavior.
This course will begin by discussing how you can make clear, concise programs to make the process of debugging much easier. Then we will cover how you can use the debugging tool GDB to debug C programs from the terminal and give you the opportunity to practice your new skills with five practical exercises. In the final section we will investigate how we can use the debugging tools available within the Eclipse IDE to fix broken Java programs and like the previous section there will be five practical exercises.