To swap rows into columns you could use either a self join(in the example) or
you can use CASE

SELECT name,
MAX (CASE WHEN course='Java'
THEN grade ELSE NULL END) AS Java,
MAX(CASE WHEN course='Database'
THEN grade ELSE NULL END) AS Database,
MAX(CASE WHEN course='Algebra'
THEN grade ELSE NULL END) AS Algebra
FROM exam JOIN courseGrade
ON (name=student)
GROUP BY name

You can also do the opposite of this by displaying columns as rows.

To do this you use a process that is the opposite of the swapping rows to columns one.
The coding for this process is: