Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Java Module 18

Desktop GUIs with JavaFX (and Swing for legacy code) interview questions

Interview questions on desktop GUIs with JavaFX (and Swing for legacy code): warm-ups, then what each harder question tests and how a good answer starts.

27 questions: 7 warm-ups and 20 with model answers · Levels: Fresher to staff

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    What are the Stage, the Scene and the scene graph in JavaFX?

    Answered in the lesson JavaFX setup and your first window

  2. Fresher

    What is the difference between Pane and the layout panes such as HBox or GridPane?

    Answered in the lesson JavaFX panes, shapes, colours, fonts and images

  3. Fresher

    What is the difference between bind() and bindBidirectional() in JavaFX?

    Answered in the lesson JavaFX properties, binding and listeners

  4. Fresher

    What is the difference between an event filter and an event handler in JavaFX?

    Answered in the lesson JavaFX events: handlers, mouse and keys

  5. Fresher

    Why do radio buttons need a ToggleGroup in JavaFX?

    Answered in the lesson JavaFX controls: labels, buttons, text and lists

  6. Fresher to mid

    When do you use a transition, a Timeline or an AnimationTimer in JavaFX?

    Answered in the lesson JavaFX animation, audio and video

  7. Fresher to mid

    What does FXMLLoader do with fx:controller, fx:id and onAction="#name" when it loads an FXML file?

    Answered in the lesson JavaFX FXML, controllers, CSS and Scene Builder

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Fresher to mid

    A JavaFX desktop tool starts on your laptop, but on a colleague's computer it stops before main() with InvalidModuleDescriptorException: Unsupported major.minor version 69.0. Both use the same JavaFX 27 SDK. What happened, and how do you make the build catch it before anyone runs the tool?

    What it tests
    Reading class-file versions, knowing that each JavaFX release has a minimum JDK, and making the build fail early instead of the user's start-up.
    First step
    Read the number: class-file version 69 is Java 25, and JavaFX 27 is compiled with --release 25. The colleague's java is older, so check java -version on that computer: a Java 21 runtime reads class files only up to version 65, so it cannot even read JavaFX's module descriptors.
    Follow-ups

    From the lesson JavaFX setup and your first window

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Fresher to mid

    A JavaFX app reads a 200 MB catalogue file in start() before calling stage.show(), and users see nothing for eight seconds. A teammate suggests moving the loading into init(). Is that enough? Say where each part of the work belongs, and why.

    What it tests
    The Application life cycle and its threads, what init() may and may not do, and keeping the JavaFX Application Thread free so the window appears and responds.
    First step
    Name the threads first. start() runs on the JavaFX Application Thread, which also draws and handles input, so work there freezes everything. init() runs on the launcher thread before start(), so the work leaves the UI thread, but the window still appears only after init() returns.
    Follow-ups

    From the lesson JavaFX setup and your first window

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Fresher to mid

    A registration form was built in a plain Pane, with relocate() for every label and field. It looks right at 800 x 600, but at 400 pixels wide the fields run past the edge, and the longer Hindi labels overlap the fields. What do you change, and how do you prove the new layout holds at both widths?

    What it tests
    Choosing layout panes over typed positions, how a GridPane sizes columns and grows fields, and testing a layout by measuring bounds at several sizes.
    First step
    A Pane never moves its children, so nothing reacts when the window or a label changes. Replace it with a GridPane: labels in column 0, which becomes as wide as the widest label, and the fields in column 1, set to grow so that they take whatever width is left.
    Follow-ups

    From the lesson JavaFX panes, shapes, colours, fonts and images

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Fresher to mid

    A logo shows when you run the app from the IDE, but in the packaged JAR its ImageView is a blank square and the log has no exception. The code is new Image("file:src/main/resources/logo.png"). Explain what happened, fix it, and make this failure impossible to miss.

    What it tests
    How Image resolves its URL, why a relative file: path depends on the starting folder, class-path resources inside a JAR, and Image's silent error reporting.
    First step
    Start from the silence: a failed Image does not throw, so check isError() and getException() first. Then compare the folder the program starts in when the IDE runs it with the folder it starts in when it runs from the JAR.
    Follow-ups

    From the lesson JavaFX panes, shapes, colours, fonts and images

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  5. Mid to senior

    A 9 x 9 Sudoku board must fill the window and stay square while the user resizes it. Compare a GridPane with percentage constraints, a plain Pane whose cells you place yourself, and a Canvas that you redraw. Which do you choose, and what does each cost?

    What it tests
    Trade-offs between layout panes, your own layout code and immediate-mode drawing: node counts, resizing, mouse hit testing, accessibility and redraw cost.
    First step
    Count the nodes: 81 cells of two or three nodes each is a few hundred nodes, little for the scene graph. Then pin down "square": the board's side is the smaller of the width and height it is given, and each design computes and applies that side in a different place.
    Follow-ups

    From the lesson JavaFX panes, shapes, colours, fonts and images

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  6. Fresher to mid

    An editor marks a document as unsaved through an InvalidationListener on a binding of the edit count; the listener only sets a dirty flag. The first edit sets the flag, but after a save clears it, later edits never set it again. Explain why, and fix it.

    What it tests
    Lazy evaluation of bindings, when invalidation events fire, and choosing between reading the value, a ChangeListener and a binding.
    First step
    Bindings are lazy: they recompute only when someone reads them. So ask who reads the binding after the first edit, and what that means for the next invalidation event.
    Follow-ups

    From the lesson JavaFX properties, binding and listeners

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  7. Mid to senior

    A desktop app grows by about 4 MB each time a user opens and closes a report panel, and slows down after a long day. Each panel adds a ChangeListener to the application's theme property. Diagnose the leak, prove it, and fix it so that it cannot come back.

    What it tests
    How listeners keep objects reachable, proving a leak with weak references or a heap dump, and the ways to stop listening: removal, weak listeners, subscriptions and when().
    First step
    Follow the references from the long-lived object. The theme property holds its listeners, each listener is a lambda that refers to its panel, so every closed panel stays reachable from the theme for as long as the application runs.
    Follow-ups

    From the lesson JavaFX properties, binding and listeners

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  8. Fresher to mid

    A form's Submit button may be enabled only when the name is not blank, the e-mail looks valid and the terms box is ticked. A teammate wrote three listeners that each recompute a flag and enable or disable the button. What can go wrong, and how would you rewrite and test it?

    What it tests
    Replacing listeners that copy state with one binding, building boolean expressions, the initial state, and testing a model's rules without a window.
    First step
    Look for the states the listeners miss: the state before any change, a field set by code instead of by typing, and two listeners that each decide on their own. A binding of the button's disableProperty to one boolean expression has none of these gaps.
    Follow-ups

    From the lesson JavaFX properties, binding and listeners

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  9. Fresher to mid

    In a small JavaFX game the arrow keys move a ship. Once a player clicks into the name field above the board, the arrows stop moving the ship and never work again until the game restarts. Explain the cause, and give two fixes with their trade-offs.

    What it tests
    Key events go to the focus owner, text fields use and consume arrow keys, and the choice between managing focus and using a filter.
    First step
    Ask which node receives key events: the node with the keyboard focus. Then ask where the focus went when the player clicked the name field, and what a text field does with the arrow keys it receives.
    Follow-ups

    From the lesson JavaFX events: handlers, mouse and keys

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  10. Mid to senior

    Escape must close the open side panel from anywhere in the window. Inside a search field, though, the first Escape should clear the text, and only a second one should close the panel. Where do you put the code, and how do you make both rules work?

    What it tests
    Using the capturing and bubbling phases on purpose, consume(), the target and the focus owner, and letting a control keep the keys it needs.
    First step
    Decide who gets the first say. The field must see Escape before the window does, so the shortcut belongs in a handler on the scene, which runs after the field in the bubbling phase, and not in a filter, which would run before the field.
    Follow-ups

    From the lesson JavaFX events: handlers, mouse and keys

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  11. Mid to senior

    Your team wants automated tests of a JavaFX screen's mouse and keyboard behaviour that run on a build server without a display. What would you test with Event.fireEvent, what with the Robot, and how do you keep the tests fast and repeatable?

    What it tests
    Choosing between synthetic events and real input, the headless platform of JavaFX 26 and later, the JavaFX Application Thread, and controlling time and chance.
    First step
    Split the question by what each test must prove: that an event reaches the right node, as it would for a user, or what a handler does once the event is there. Then pick for each the cheapest way to produce the event.
    Follow-ups

    From the lesson JavaFX events: handlers, mouse and keys

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  12. Mid to senior

    A form keeps its model in step through a ComboBox's onAction handler. It works on screen, but a unit test that builds the form without showing it and calls setValue sees a model that never changes. Explain why, fix the design, and say how you would catch such gaps.

    What it tests
    Events versus properties, behaviour that depends on a control being shown, and testing the model instead of event wiring.
    First step
    Compare the two situations: on screen the box sits in a shown scene, in the test it does not. Ask which notifications depend on the control being shown, and which come from its value itself.
    Follow-ups

    From the lesson JavaFX controls: labels, buttons, text and lists

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  13. Fresher to mid

    An enrolment-number field must hold exactly 12 digits. Compare validating only on Submit, a listener that undoes bad text, and a TextFormatter together with a validation binding. Which do you choose, and which inputs do your tests try?

    What it tests
    Where to validate, what a TextFormatter can and cannot do, messages as bindings, and the edge cases of text input such as pasting and text set by code.
    First step
    Separate two questions: which characters may ever appear in the field, and whether the value is complete. A TextFormatter answers the first on every change; a binding answers the second and drives both the message and the Submit button.
    Follow-ups

    From the lesson JavaFX controls: labels, buttons, text and lists

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  14. Mid to senior

    A JavaFX registration form works well with a mouse, but a student who uses a screen reader and the keyboard cannot complete it. What do you check and change, and how do you keep it working in later releases?

    What it tests
    Focus order, mnemonics and labelFor, names for icon-only controls, messages that are announced, colour that is not the only signal, and testing for accessibility.
    First step
    Use the form the way the student does: keyboard only, screen reader on. Check first that Tab reaches every control in a sensible order, and that each control is announced with its label.
    Follow-ups

    From the lesson JavaFX controls: labels, buttons, text and lists

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  15. Mid to senior

    A JavaFX game moves the player 4 pixels in every AnimationTimer call. One tester says it crawls when many enemies are on screen; another, with a 120 Hz monitor, says it runs too fast. Explain both reports, fix the movement and say how you would test the fix.

    What it tests
    Per-frame against time-based movement, how JavaFX drops frames when one takes too long, limiting large time steps, and testing timing logic without waiting in real time.
    First step
    Both reports have one cause: the step is per frame, so the speed is 4 pixels times the frame rate. At 60 frames a second that is 240 pixels a second, at 120 frames 480, and when heavy frames cut the rate to 20, only 80. Give the player a speed in pixels a second and multiply it by the seconds since the last frame.
    Follow-ups

    From the lesson JavaFX animation, audio and video

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  16. Mid to senior

    A quiz app creates a new MediaPlayer for a buzzer sound on every wrong answer. In long sessions some buzzers never sound, and the thread count and memory of the process keep rising. Explain what is happening and redesign the sound code.

    What it tests
    How a MediaPlayer holds and releases native resources, what keeps a player alive, dispose(), and when an AudioClip fits better than a MediaPlayer.
    First step
    Separate the two symptoms and follow each player's life: what still refers to a player once the handler has returned, and what calls dispose() when its sound is over? Rising threads and memory say that something is never released; silent buzzers say that something is released too early. Then ask whether a short sound needs a MediaPlayer at all.
    Follow-ups

    From the lesson JavaFX animation, audio and video

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  17. Mid to senior

    A lecture player lets students open any audio or video file they have. Some files never start and show no message; others show a stack trace. Design how the player opens a file, explains problems in plain words and never hangs.

    What it tests
    The formats and protocols JavaFX plays, MediaException and its types, onError, waiting for READY, and messages a user can act on.
    First step
    List the moments at which opening a file can go wrong: while the Media and MediaPlayer objects are created, later while the media loads or plays, and the case in which no event arrives at all. Then decide for each moment what the user should see and how long the player may wait before it gives up.
    Follow-ups

    From the lesson JavaFX animation, audio and video

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  18. Mid to senior

    A JavaFX app with FXML screens runs from the IDE on the class path. Packaged as a named module, it fails when the first screen loads. A colleague proposes making every @FXML field and handler public. Explain the errors you can expect, the right fix, and why the proposal is wrong.

    What it tests
    How the module system restricts reflection, the difference between exports and opens, qualified opens to javafx.fxml, and reading LoadException chains.
    First step
    On the class path everything is reachable, so the screens worked. In a named module, FXMLLoader in the module javafx.fxml must first create the controller, which needs the package exported to it, and then set private fields, which needs the package opened to it. Read the cause at the bottom of the LoadException to see which step failed.
    Follow-ups

    From the lesson JavaFX FXML, controllers, CSS and Scene Builder

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  19. Mid to senior

    To flag an invalid field, a developer calls field.setStyle("-fx-text-fill: red") in one screen and label.setTextFill(Color.RED) in another. After a designer adds a theme stylesheet, the second one stops working and the first one breaks the dark theme. Explain the JavaFX CSS cascade and redesign the error state.

    What it tests
    The precedence of user agent stylesheets, values set in code, scene and parent stylesheets and inline styles, !important, and pseudo-classes as the bridge between code and styles.
    First step
    Find every source that sets the text colour of those two controls: the theme's stylesheet, Modena, the code and the inline style. Then look up how JavaFX ranks these sources against each other, and ask what the code is really trying to say: a colour, or a state of the field.
    Follow-ups

    From the lesson JavaFX FXML, controllers, CSS and Scene Builder

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  20. Senior to staff

    A 40-screen JavaFX app needs a light theme, a dark theme that follows the operating system, and a high-contrast theme users can pick, all without changing screen code. Design where colours live, how themes switch, and how you keep every theme readable as screens change.

    What it tests
    Looked-up colours and naming, media queries and conditional imports, Scene.Preferences, contrast requirements, and automated checks that scale to many screens.
    First step
    Separate naming from use. Every rule uses colour names such as -ink, -page and -brand, defined once in .root; each theme only redefines the names. Then decide the switch: the operating system's scheme through a media query, and a user's high-contrast choice through a style class on the root or an extra stylesheet.
    Follow-ups

    From the lesson JavaFX FXML, controllers, CSS and Scene Builder

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All Java interview questions · The Java track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.