As generative AI (genAI) tools like ChatGPT become increasingly integrated into
educational contexts, understanding their role in programming education is necessary.
While existing research focused largely on the technical performance of genAI tools,
there is limited insight into how such tools affect learning outcomes in code-writing
contexts. This thesis investigates how university students use genAI tools for code-
writing in programming courses. Drawing on the Technology Acceptance Model
(TAM), Self-Determination Theory (SDT), and Bloom’s Taxonomy, the research
explored three main questions: how students use AI tools, what motivates them, and
whether the AI enhance or hinder their ability to write and understand code. A mixed-
method approach was used, including a controlled user study (N = 22), a post-study
survey (N = 22), and semi-structured interviews (N = 10) with students at Jönköping
University. The findings showed that programming experience and motivation play a
key role in how students work with AI. Beginners more likely copied code without
changes, while experienced students often modified and improved the code. Students
driven by extrinsic motivation used AI more passively, while those with intrinsic
motivation engaged with it more actively. While AI tools can make coding tasks easier,
they may also reduce deeper learning if not used thoughtfully. Based on the results, a
guideline with recommendations for educators on how to support students in using AI
tools in ways that build programming skills and independent thinking was developed.