TCM ONE · CAREER PRACTICE · 8 LEARN TOPICS

Coding interview questions, explained simply

Practice 32 common questions from the Learn library. Understand what the question is testing, study a small example, then use the sample wording as a starting point for your own answer.

01

Understand

Read the short explanation before memorising terms.

02

Practise

Run or adapt the code example and explain what changes.

03

Answer clearly

Use the sample answer as a guide, then speak in your own words.

32 questions across 8 topics

LEARN GUIDE

Python interview questions

Study the Python guide →

Start with your first Python program and progress to clean, tested applications, asynchronous programming and project packaging.

Q1What is the difference between a list and a tuple?Beginner

Simple explanation

Both keep an ordered group of values. A list can be changed after it is created; a tuple is normally used for a fixed group that should not be changed. Choose based on whether the collection needs to be editable.

Example

topics = ['Python', 'HTML']
topics.append('CSS')

point = (10, 20)
# point[0] = 5  # TypeError: tuple items cannot be reassigned

What to notice: The list changes in place; the tuple gives an error if you try to replace one of its items.

One easy way to explain it

“I use a list for values that may change, such as a task queue. I use a tuple for a fixed record, such as coordinates. Both keep order, but lists are mutable and tuples are immutable.”

Q2What is a Python dictionary, and when would you use one?Beginner

Simple explanation

A dictionary stores values under unique keys. It is useful when you want to look up a value by a meaningful name or identifier instead of remembering its position in a list.

Example

course = {'name': 'Python', 'minutes': 30}
print(course['name'])
course['minutes'] = 45

What to notice: Here name and minutes are clearer than remembering that the course title is item zero.

One easy way to explain it

“A dictionary maps keys to values. I use it when each value has a label, like a user ID mapped to a profile or a product name mapped to a price.”

Q3Why do Python functions use return instead of print for results?Intermediate

Simple explanation

return sends a value back to the code that called the function, so that code can store it, combine it or test it. print only displays text for a person and does not give the caller a reusable result.

Example

def total_with_tax(price, rate):
    return price * (1 + rate)

amount = total_with_tax(100, 0.18)
print(amount)

What to notice: The calculation can be reused in another function or a test because it returns a number.

One easy way to explain it

“I return a result when other code needs to use it. I print only when I want to show a message, usually at the user interface or command-line boundary.”

Q4What is a Python generator, and why can it save memory?Advanced

Simple explanation

A generator provides one value at a time when the caller requests the next value. It does not need to build and keep a complete result list in memory, which helps when processing a large input.

Example

def squares(numbers):
    for number in numbers:
        yield number * number

for square in squares(range(3)):
    print(square)

What to notice: yield pauses the function and resumes it when the loop asks for the next square.

One easy way to explain it

“A generator is a lazy iterable. It produces each value on demand, so I can process a large stream without holding every result at once.”

LEARN GUIDE

HTML interview questions

Study the HTML guide →

Build a web page from the beginning, then learn headings, links, images, forms, accessibility and page metadata using clear HTML examples.

Q1What is semantic HTML, and why does it matter?Beginner

Simple explanation

Semantic HTML uses elements that describe the purpose of their content, such as nav, main, article and button. Browsers, search engines and assistive technology can understand the page structure more reliably than a page made only from generic div elements.

Example

<header><a href="/">Study Hub</a></header>
<nav aria-label="Main navigation">
  <a href="/learn">Learn</a>
</nav>
<main><article><h1>HTML basics</h1></article></main>

What to notice: The elements describe page roles; they are not just visual containers.

One easy way to explain it

“I choose an element for its meaning first. Semantic landmarks make a page easier to navigate and give assistive technology useful structure; CSS can still control how it looks.”

Q2When should you use a button and when should you use a link?Beginner

Simple explanation

A link navigates to another address or page section. A button performs an action on the current page, such as submitting a form or opening a dialog. Using the right element gives users expected keyboard and assistive-technology behavior.

Example

<a href="/courses">Browse courses</a>
<button type="button" id="open-help">Open help</button>

What to notice: The link has a destination; the button performs an action.

One easy way to explain it

“If the user is going somewhere, I use an anchor with an href. If the user is asking the page to do something, I use a button.”

Q3How do you make an HTML form field accessible?Intermediate

Simple explanation

Give each input a visible label connected using matching for and id values. Explain required formats and errors in text, use the correct input type, and do not use placeholder text as the only label.

Example

<label for="email">Email address</label>
<input id="email" name="email" type="email" required>

What to notice: Clicking the label focuses the input, and its name is announced to assistive technology.

One easy way to explain it

“I associate a real label with every control, choose a useful input type, and show instructions or validation errors in text so the field works for keyboard and screen-reader users too.”

Q4What is the purpose of alt text on an image?Intermediate

Simple explanation

Alt text communicates the useful information in an image when the image cannot be seen or loaded. Decorative images should normally use empty alt text so screen readers can skip them. The description should fit the image’s purpose in that page, not repeat nearby text.

Example

<img src="team-chart.png" alt="Support requests fell each month from January to March">
<img src="divider.svg" alt="">

What to notice: The first image conveys data; the decorative divider adds no information.

One easy way to explain it

“I write alt text for informative images and leave it empty for decoration. I describe the information the image adds, not every visual detail.”

LEARN GUIDE

CSS interview questions

Study the CSS guide →

Start with CSS selectors and spacing, then style readable pages and create responsive layouts with Flexbox, Grid, media queries and reusable colors.

Q1Explain the CSS box model.Beginner

Simple explanation

Every element is laid out as content surrounded by padding, a border and margin. By default, a declared width applies to the content only. With border-box, the declared width includes padding and border, which makes responsive sizing easier to reason about.

Example

*, *::before, *::after {
  box-sizing: border-box;
}

.card { width: 100%; padding: 1rem; border: 1px solid #ccc; }

What to notice: The card stays within its parent width instead of growing by the padding and border amount.

One easy way to explain it

“The box model is content, padding, border and margin. I usually use box-sizing: border-box so the width I declare includes the inner spacing and border.”

Q2When would you choose Flexbox instead of CSS Grid?Beginner

Simple explanation

Flexbox is designed to arrange items primarily along one direction at a time, such as a row of controls. Grid is designed to coordinate rows and columns together. They can work together; choose the one that matches the relationship between the items.

Example

.toolbar { display: flex; align-items: center; gap: 1rem; }

.dashboard { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }

What to notice: The toolbar flows in one line; the dashboard defines a two-column structure.

One easy way to explain it

“I use Flexbox for a one-dimensional alignment, like a toolbar. I use Grid when I need to control both columns and rows, like a dashboard.”

Q3What is CSS specificity?Intermediate

Simple explanation

Specificity is part of how the browser decides which matching rule wins when declarations conflict. In general, an ID selector outweighs a class selector, which outweighs an element selector. The cascade also considers origin, importance and source order, so adding more selectors is not always the right fix.

Example

.card { color: #222; }
.featured { color: #0759a5; }
/* Both are class selectors; if both match, later cascade rules apply. */

What to notice: A single class is easier to override safely than a long chain of nested selectors.

One easy way to explain it

“Specificity helps resolve competing selectors. I keep selectors simple and use component classes so the cascade stays predictable instead of escalating selector weight.”

Q4How do media queries help create responsive layouts?Intermediate

Simple explanation

A media query applies styles when a condition such as viewport width or user preference matches. A responsive layout should adapt to the available space and keep content readable, rather than merely target a list of device names.

Example

.cards { display: grid; grid-template-columns: 1fr; gap: 1rem; }

@media (min-width: 48rem) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

What to notice: Small screens get one column; when there is enough width, cards use two columns.

One easy way to explain it

“I start with a flexible layout, then use a media query when the content needs a different arrangement at a particular width. I also check zoom and keyboard focus.”

LEARN GUIDE

Sass / SCSS interview questions

Study the Sass / SCSS guide →

Learn Sass and SCSS step by step: store design values, reuse style patterns, split code into modules, and compile your work into browser-ready CSS.

Q1What is Sass, and how is SCSS different from CSS?Beginner

Simple explanation

Sass is a stylesheet language with features such as variables, mixins and modules. SCSS is its CSS-like syntax: most valid CSS can be written in an SCSS file. A build step compiles SCSS into standard CSS that browsers can use.

Example

$brand: #1458a6;

.button {
  color: white;
  background: $brand;
}

What to notice: The Sass variable is replaced during compilation; it is not a browser runtime variable.

One easy way to explain it

“SCSS is Sass written with CSS-style braces and semicolons. It adds authoring features, then a compiler turns the result into browser-ready CSS.”

Q2When should you use a Sass mixin?Intermediate

Simple explanation

A mixin packages reusable declarations and can accept parameters. It is useful when a group of styles repeats and should stay consistent. Avoid creating a mixin for every tiny rule; Sass functions are more suitable for calculations that return a value.

Example

@mixin focus-ring($color) {
  outline: 3px solid $color;
  outline-offset: 2px;
}

.button:focus-visible {
  @include focus-ring(#1458a6);
}

What to notice: One shared focus style can be reused while each include can supply its own color.

One easy way to explain it

“I use a mixin for reusable groups of declarations, especially when a few options change. If I only need a computed value, I use a function instead.”

Q3Why use Sass modules with @use instead of old @import?Intermediate

Simple explanation

@use loads a Sass module with a namespace, so it makes dependencies explicit and avoids placing every variable and mixin into one global scope. @forward can expose selected module members from a package entry point. This makes larger style systems easier to maintain.

Example

// _tokens.scss
$brand: #1458a6;

// button.scss
@use 'tokens';
.button { background: tokens.$brand; }

What to notice: The tokens namespace tells you exactly which module owns the value.

One easy way to explain it

“I use @use to import a module through a clear namespace. That reduces naming collisions and makes it easier to see where a token or mixin comes from.”

Q4How are Sass variables different from CSS custom properties?Advanced

Simple explanation

Sass variables are resolved while the stylesheet is compiled. CSS custom properties remain in the generated CSS and can change at runtime, inherit through the DOM and respond to themes. Use Sass for build-time organization and custom properties when the browser needs to switch values dynamically.

Example

$brand-at-build: #1458a6;
:root { --brand: #{$brand-at-build}; }

.dark-theme { --brand: #8bb8ff; }
.button { background: var(--brand); }

What to notice: Sass inserts the initial color; the CSS custom property can then change with the theme.

One easy way to explain it

“Sass variables help while building the CSS. Custom properties exist in the browser, so they are better for runtime theming or values that change by element.”

LEARN GUIDE

Bootstrap interview questions

Study the Bootstrap guide →

Use Bootstrap to build responsive web pages with a grid, ready-made buttons, cards, forms and menus, then adjust the design for your project.

Q1What is Bootstrap, and what does its grid system do?Beginner

Simple explanation

Bootstrap is a front-end toolkit with CSS, components and optional JavaScript behavior. Its grid uses containers, rows and responsive columns to arrange content at defined breakpoints. It speeds up common interface work, but it does not replace semantic HTML or accessibility checks.

Example

<div class="container">
  <div class="row">
    <main class="col-12 col-md-8">Article</main>
    <aside class="col-12 col-md-4">Related links</aside>
  </div>
</div>

What to notice: Below the medium breakpoint both columns span the row; at wider sizes they use eight and four grid columns.

One easy way to explain it

“Bootstrap gives a project a consistent starting system. The grid lets me arrange columns responsively, while I still choose meaningful markup and verify that the page works for users.”

Q2How do Bootstrap responsive breakpoints work?Intermediate

Simple explanation

Responsive class infixes apply styles at a breakpoint and larger widths. For example, col-12 applies at all widths while col-md-6 takes effect from the medium breakpoint upward. The exact breakpoint values belong to the Bootstrap version and can be customized in a Sass build.

Example

<div class="col-12 col-lg-6">
  Half-width from the large breakpoint upward
</div>

What to notice: The column uses the full row first, then half the row on larger screens.

One easy way to explain it

“Bootstrap’s breakpoint infix applies a layout from that width upward. I use the smallest layout as a base, then add breakpoint classes where the content needs more columns.”

Q3What is the difference between a Bootstrap utility and a component?Intermediate

Simple explanation

A utility class applies a small focused style such as spacing, display or text alignment. A component combines markup and styles into a repeated interface pattern such as a card or alert. Utilities are quick for small adjustments; repeated complex patterns are clearer as named components.

Example

<article class="card h-100">
  <div class="card-body d-flex flex-column">
    <h2 class="h5 card-title">Java</h2>
    <a class="btn btn-primary mt-auto" href="/learn/java">Open guide</a>
  </div>
</article>

What to notice: card is the component pattern; h-100, d-flex and mt-auto are individual utilities.

One easy way to explain it

“A utility is one small styling choice; a component is a reusable UI pattern. I use utilities for simple layout adjustments and components for consistent repeated structures.”

Q4Why should Bootstrap components still be checked for accessibility?Advanced

Simple explanation

A framework can provide useful defaults but cannot know whether a page’s labels, heading order, keyboard flow and content are correct. Interactive components need the right JavaScript, accessible names and state behavior. Test with keyboard and assistive technology instead of assuming a class name guarantees accessibility.

Example

<button class="btn btn-primary" type="button"
        aria-expanded="false" aria-controls="help-panel">
  Show help
</button>
<div id="help-panel" hidden>Keyboard tips</div>

What to notice: An interactive control should expose its state and identify the content it controls.

One easy way to explain it

“Bootstrap helps with implementation, but accessibility depends on how I use it. I verify labels, focus behavior, contrast and component state in the finished interface.”

LEARN GUIDE

Java interview questions

Study the Java guide →

Start with your first Java program, then learn variables, methods, classes, collections, error handling and testing through practical code examples.

Q1What is the difference between the JDK, JVM and Java bytecode?Beginner

Simple explanation

The JDK is the developer kit with tools such as the compiler. The compiler turns Java source into bytecode. The JVM runs that bytecode on a platform, which is why a compiled Java program can run on compatible systems with a JVM.

Example

// Compile source
javac Hello.java

// Run the generated bytecode
java Hello

What to notice: javac produces a .class file; java starts it using the Java Virtual Machine.

One easy way to explain it

“I write source code and compile it with the JDK into bytecode. The JVM executes that bytecode on the target machine.”

Q2What is encapsulation in object-oriented programming?Beginner

Simple explanation

Encapsulation keeps an object’s internal state behind a clear interface. A class controls how its state changes, which helps stop callers from putting the object into an invalid condition. It is not simply making every field private; the public methods should express useful behavior.

Example

final class Counter {
    private int value;

    public void increment() { value++; }
    public int value() { return value; }
}

What to notice: Other code can increment the counter or read it, but cannot directly assign an arbitrary value.

One easy way to explain it

“Encapsulation means an object protects its own state and exposes deliberate operations. I validate changes at that boundary so callers cannot bypass the class rules.”

Q3When would you use an interface in Java?Intermediate

Simple explanation

An interface defines behavior that different classes can provide. Code can depend on that behavior instead of one concrete implementation, which makes alternatives easier to substitute and tests easier to isolate. Use an interface when there is a real boundary or more than one useful implementation, not automatically for every class.

Example

interface Notifier { void send(String message); }

final class Reminder {
    private final Notifier notifier;
    Reminder(Notifier notifier) { this.notifier = notifier; }
    void remind() { notifier.send("Study today"); }
}

What to notice: Reminder only needs something that can send a message; it does not need to know the delivery method.

One easy way to explain it

“I use an interface to express a capability or dependency boundary. The caller uses the contract, so implementations can change without rewriting the caller.”

Q4How do List, Set and Map differ?Beginner

Simple explanation

A List keeps items in sequence and can contain duplicates. A Set represents unique members. A Map associates keys with values so you can look up a value by its key. Pick the structure based on the questions the program needs to answer.

Example

List<String> order = new ArrayList<>();
Set<String> unique = new HashSet<>();
Map<String, Integer> minutes = new HashMap<>();
minutes.put("loops", 25);

What to notice: Each collection models a different rule about ordering, uniqueness or lookup.

One easy way to explain it

“I use List for an ordered sequence, Set when membership must be unique, and Map when I need to find a value by a key.”

LEARN GUIDE

GitHub CI/CD interview questions

Study the GitHub CI/CD guide →

Learn how GitHub Actions checks every code change, runs tests and publishes an approved website, with simple examples and a safe release flow.

Q1What is the difference between CI and CD?Beginner

Simple explanation

Continuous integration (CI) automatically builds and checks changes so teams find problems early. Continuous delivery (CD) keeps a tested change ready to release, usually with an approval step. Continuous deployment goes further and automatically releases every change that passes its checks.

Example

name: checks
on:
  pull_request:
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: echo "Run project checks here"

What to notice: The pull request event starts an automated job before the code is merged.

One easy way to explain it

“CI verifies changes continuously. Delivery keeps a verified release ready; deployment automatically sends passing changes to users.”

Q2What is a GitHub Actions workflow, and what triggers it?Beginner

Simple explanation

A workflow is a YAML file stored in .github/workflows. Its on section lists events such as a push, pull request or manual dispatch that start the workflow. A workflow contains jobs, and each job runs steps on a runner.

Example

name: test
on:
  push:
    branches: [main]
jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Verify the app"

What to notice: A push to main starts the verify job on a temporary GitHub-hosted runner.

One easy way to explain it

“A workflow is an automation recipe. The event starts it, a runner executes its jobs, and steps perform the build, test or deployment actions.”

Q3How should you protect credentials used by a workflow?Intermediate

Simple explanation

Store credentials as GitHub Actions secrets or environment secrets, then pass them only to the step that needs them. Never commit secrets to the repository or print them in logs. Limit token permissions and use protected environments for sensitive deployments.

Example

permissions:
  contents: read

steps:
  - name: Deploy
    env:
      DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
    run: ./deploy.sh

What to notice: The token comes from repository settings at runtime, not from a value committed in the YAML file.

One easy way to explain it

“I keep credentials in GitHub’s secret store, scope access to the smallest job, avoid logging them and restrict deployment permissions.”

Q4Why use artifacts in a CI/CD workflow?Advanced

Simple explanation

An artifact is a file produced by a workflow that can be retained or passed to another job. For example, one job can build a site and upload its output; a deployment job can download and publish that exact build. This avoids rebuilding different files at each stage.

Example

- uses: actions/upload-artifact@v4
  with:
    name: site-build
    path: dist/

What to notice: The generated dist folder is saved as an artifact for a later workflow job.

One easy way to explain it

“Artifacts let workflow jobs share the build output. I can test and deploy the same generated files, which makes the release process easier to trace.”

LEARN GUIDE

Spring Boot interview questions

Study the Spring Boot guide →

Learn Spring Boot with Java: create a backend, build REST APIs, validate data, connect a database, write tests and prepare a secure application for deployment.

Q1What is Spring Boot, and how is it different from Spring Framework?Beginner

Simple explanation

Spring Framework provides building blocks for Java applications, including dependency injection and web support. Spring Boot uses those building blocks with conventions, dependency starters and auto-configuration so an application can start with less manual setup. Boot complements Java and Spring; it does not replace them.

Example

@SpringBootApplication
public class StudyApplication {
    public static void main(String[] args) {
        SpringApplication.run(StudyApplication.class, args);
    }
}

What to notice: The main method starts Spring and the embedded server using the project configuration.

One easy way to explain it

“Spring Framework provides the core application tools. Spring Boot adds convenient defaults and an application launcher, so I can build and run a Spring application with less configuration.”

Q2What is dependency injection in Spring?Intermediate

Simple explanation

Dependency injection means a class receives the collaborators it needs instead of constructing them itself. Spring manages application objects called beans and supplies dependencies through constructors or other supported injection points. Constructor injection makes requirements explicit and makes unit tests easier to set up.

Example

@Service
class CourseService {
    private final CourseRepository repository;

    CourseService(CourseRepository repository) {
        this.repository = repository;
    }
}

What to notice: The service does not call new CourseRepository(); Spring supplies the repository bean.

One easy way to explain it

“A service declares what it needs in its constructor. Spring provides those dependencies when it creates the service, which keeps construction and business logic separate.”

Q3What does @SpringBootApplication do?Intermediate

Simple explanation

@SpringBootApplication combines application configuration, auto-configuration and component scanning. Scanning normally begins in the package containing the main class and includes its child packages. Putting controllers and services under that root package helps Spring discover them.

Example

package in.tcm.study;

@SpringBootApplication
public class StudyApplication {
    public static void main(String[] args) {
        SpringApplication.run(StudyApplication.class, args);
    }
}

What to notice: A controller in in.tcm.study.api is under the root package, so component scanning can find it.

One easy way to explain it

“It marks the application entry point, enables Boot’s conditional defaults and tells Spring where to find application components.”

Q4Why separate controller, service and repository responsibilities?Intermediate

Simple explanation

A controller handles HTTP details, a service coordinates application rules, and a repository handles persistence. The separation keeps each class focused and allows business rules to be tested without sending a web request or connecting to a real database. Keep the design proportional to the application rather than adding empty layers.

Example

@RestController
class CourseController {
    private final CourseService service;
    CourseController(CourseService service) { this.service = service; }

    @GetMapping("/api/courses")
    List<CourseDto> all() { return service.findAll(); }
}

What to notice: The HTTP handler delegates the actual use case rather than implementing database and business rules itself.

One easy way to explain it

“The controller translates the request, the service applies the use-case rules, and the repository loads or saves data. Each layer has one clear reason to change.”

Turn practice into a strong answer

Use a simple structure: define the idea, explain when you would use it, then show a small example or trade-off. Be honest when you do not know something; explain how you would investigate it.