{"id":111719,"date":"2025-09-04T12:46:23","date_gmt":"2025-09-04T07:16:23","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/?page_id=111719"},"modified":"2025-09-04T12:34:24","modified_gmt":"2025-09-04T07:04:24","slug":"java-exercise","status":"publish","type":"page","link":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/","title":{"rendered":"Java Exercises"},"content":{"rendered":"\n<style>\n        \/* General styles *\/\n        .jv-input {\n            border-bottom: 1px dashed #9CA3AF !important;\n        }\n        .jv-input:focus {\n            outline: none;\n            background-color: #E0E7FF;\n            border-bottom: 1px solid #3B82F6;\n        }\n\n        .jv-select {\n            font-family: monospace;\n            background-color: #F3F4F6;\n            border: 1px dashed #9CA3AF;\n            font-size: 0.875rem; \/* 14px *\/\n            color: #1D4ED8;\n            border-radius: 4px;\n            padding: 1px;\n        }\n        .jv-select:focus {\n            outline: none;\n            border: 1px solid #3B82F6;\n        }\n        \n        .jv-code-template {\n            background-color: #F9FAFB;\n            padding: 1rem;\n            border-radius: 0.375rem;\n            font-size: 0.95rem;\n            color: #374151;\n            line-height: 1.6;\n        }\n\n        \/* CSS class for topic buttons for cleaner HTML and hover effects *\/\n        .topic-item-btn {\n            background-color: #FFFFFF;\n            padding: 1.5rem;\n            border-radius: 0.5rem;\n            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);\n            text-align: left;\n            width: 100%;\n            border: 1px solid #E5E7EB;\n            cursor: pointer;\n            transition: all 0.2s ease;\n        }\n        .topic-item-btn:hover {\n            transform: translateY(-3px);\n            box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);\n     background-color: white;\n        }\n    <\/style>\n\n\n<div class=\"jv-ex-container\" style=\"font-family: sans-serif; background-color: #FFFFFF; color: #1F2937; max-width: 56rem; width: 100%; margin: 2rem auto; border-radius: 1rem; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); padding: 1.5rem;\">\n\n    <div id=\"jv-ex-topic-selection-view\">\n        <h1 style=\"font-size: 1.875rem; line-height: 2.25rem; font-weight: 700; text-align: center; color: #111827; margin-bottom: 0.5rem;\" style=\"font-size: 1.875rem; line-height: 2.25rem; font-weight: 700; text-align: center; color: #111827; margin-bottom: 0.5rem;\" id=\"java-practice-exercises\">Java Practice Exercises<\/h1>\n        <p style=\"text-align: center; color: #6B7280;\">Work through 90 Java practice programs, coding questions, and online exercises to improve your programming skills. Ideal for beginners and interview prep.<\/p>\n        <p style-align: center; color: #6B7280; margin-bottom: 2rem;\">Select a topic to start the exercise.<\/p>\n\n        <div id=\"jv-ex-topic-grid\" style=\"display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1.5rem;\">\n            <button class=\"topic-item-btn\" data-topic-key=\"JavaBasics\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"java-basics\">Java Basics<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"DataTypesVariables\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"data-types-variables\">Data Types & Variables<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"Operators\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"operators\">Operators<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"Strings\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"strings\">Strings<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"Arrays\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"arrays\">Arrays<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"ControlFlow\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"control-flow\">Control Flow<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"Methods\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"methods\">Methods<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"ClassesObjects\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"classes-objects\">Classes & Objects<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"OOPConcepts\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"oop-concepts\">OOP Concepts<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"ExceptionHandling\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"exception-handling\">Exception Handling<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"CollectionsFramework\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"collections-framework\">Collections Framework<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"InterfacesAbstractClasses\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"interfaces-abstract-classes\">Interfaces & Abstract Classes<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"FileIO\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"file-i-o\">File I\/O<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"Multithreading\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"multithreading\">Multithreading<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"Generics\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"generics\">Generics<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"LambdaExpressionsStreams\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"lambda-expressions-streams\">Lambda Expressions & Streams<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"JDBC\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"jdbc\">JDBC<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"EnumsAnnotations\"><h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"enums-annotations\">Enums & Annotations<\/h3><p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p><\/button>\n            <noscript>\n                <p style=\"text-align: center; background-color: #FEF2F2; color: #991B1B; padding: 1rem; border-radius: 0.5rem; grid-column: 1 \/ -1;\">\n                    The interactive exercises on this page require JavaScript. Please enable it in your browser to start practicing.\n                <\/p>\n            <\/noscript>\n        <\/div>\n    <\/div>\n\n    <div id=\"jv-ex-exercise-views-container\">\n        <\/div>\n\n<\/div>\n\n<script>\n    const exercises = {\n        \"Java Basics\": [\n            { question: \"Print 'Hello, Java!' to the console.\", template: [ \"System.\", { type: \"input\", size: 4, placeholder: \"stream\" }, \".println(\\\"Hello, Java!\\\");\" ], solution: [\"out\"] },\n            { question: \"Create an integer variable `score` and assign the value `100` to it.\", template: [ { type: \"input\", size: 4, placeholder: \"type\" }, \" score = 100;\" ], solution: [\"int\"] },\n            { question: \"Which keyword is used to define a class in Java?\", template: [ { type: \"select\", options: [\"class\", \"public\", \"void\"] }, \" MyClass { ... }\" ], solution: [\"class\"] },\n            { question: \"Write a single-line comment.\", template: [ { type: \"input\", size: 2, placeholder: \"chars\" }, \" This is a comment\" ], solution: [\"\/\/\"] },\n            { question: \"Complete the main method signature.\", template: [ \"public static void main(\", { type: \"input\", size: 12, placeholder: \"type\" }, \"[] args) { ... }\" ], solution: [\"String\"] }\n        ],\n        \"Data Types & Variables\": [\n            { question: \"Declare a variable `pi` of type double with a value of 3.14159.\", template: [ { type: \"input\", size: 7, placeholder: \"type\" }, \" pi = 3.14159;\" ], solution: [\"double\"] },\n            { question: \"A primitive type stores a value, while a wrapper class stores a...\", template: [ \"...stores a \", { type: \"input\", size: 9, placeholder: \"concept\" }, \".\" ], solution: [\"reference\"] },\n            { question: \"Convert a string `s` containing \\\"42\\\" to an integer.\", template: [ \"int num = Integer.\", { type: \"input\", size: 9, placeholder: \"method\" }, \"(s);\" ], solution: [\"parseInt\"] },\n            { question: \"Declare a constant variable `MAX_USERS` with a value of 1000.\", template: [ { type: \"select\", options: [\"final\", \"const\", \"static\"] }, \" int MAX_USERS = 1000;\" ], solution: [\"final\"] },\n            { question: \"What is the default value of a boolean variable in Java?\", template: [ \"The default value is \", { type: \"input\", size: 6, placeholder: \"value\" }, \".\" ], solution: [\"false\"] }\n        ],\n        \"Operators\": [\n            { question: \"What is the result of the modulus operator `10 % 3`?\", template: [ \"\/\/ Result is \", { type: \"input\", size: 2, placeholder: \"result\" } ], solution: [\"1\"] },\n            { question: \"Write the shorthand operator for `x = x + 5;`.\", template: [ \"x \", { type: \"input\", size: 3, placeholder: \"operator\" }, \" 5;\" ], solution: [\"+=\"] },\n            { question: \"The `instanceof` operator tests if an object is an instance of a...\", template: [ \"...of a specific \", { type: \"input\", size: 6, placeholder: \"what\" }, \".\" ], solution: [\"class\"] },\n            { question: \"For strings, `==` compares references, while `.equals()` compares...\", template: [ \"...compares the string \", { type: \"input\", size: 7, placeholder: \"what\" }, \".\" ], solution: [\"values\"] },\n            { question: \"Complete the ternary operator to check if `num` is even.\", template: [ \"String result = (num % 2 == 0) \", { type: \"input\", size: 2, placeholder: \"char\" }, \" \\\"Even\\\" : \\\"Odd\\\";\" ], solution: [\"?\"] }\n        ],\n        \"Strings\": [\n            { question: \"Given `String str = \\\"Java\\\";`, get the character 'v'.\", template: [ \"char c = str.\", { type: \"input\", size: 8, placeholder: \"method\" }, \"(2);\" ], solution: [\"charAt\"] },\n            { question: \"Get the length of a string variable `message`.\", template: [ \"int len = message.\", { type: \"input\", size: 8, placeholder: \"method\" }, \"();\" ], solution: [\"length\"] },\n            { question: \"Concatenate `s1` and `s2` with a space.\", template: [ \"String result = s1 + \\\" \\\" \", { type: \"input\", size: 2, placeholder: \"op\" }, \" s2;\" ], solution: [\"+\"] },\n            { question: \"Convert a string `text` to all uppercase.\", template: [ \"String upper = text.\", { type: \"input\", size: 12, placeholder: \"method\" }, \"();\" ], solution: [\"toUpperCase\"] },\n            { question: \"Check if a string `filename` starts with \\\"test_\\\".\", template: [ \"boolean check = filename.\", { type: \"select\", options: [\"startsWith\", \"beginsWith\", \"hasPrefix\"] }, \"(\\\"test_\\\");\" ], solution: [\"startsWith\"] }\n        ],\n        \"Arrays\": [\n            { question: \"Create an integer array `numbers` with elements 10, 20, and 30.\", template: [ \"int[] numbers = \", { type: \"input\", size: 12, placeholder: \"{val1, val2, ...}\" }, \";\" ], solution: [\"{10, 20, 30}\"] },\n            { question: \"Find the number of elements in an array called `data`.\", template: [ \"int size = data.\", { type: \"input\", size: 7, placeholder: \"property\" }, \";\" ], solution: [\"length\"] },\n            { question: \"Access the last element of an array `arr`.\", template: [ \"int last = arr[arr.length - \", { type: \"input\", size: 2, placeholder: \"num\" }, \"];\" ], solution: [\"1\"] },\n            { question: \"Declare a 2D array of integers named `matrix`.\", template: [ \"int\", { type: \"input\", size: 5, placeholder: \"syntax\" }, \" matrix;\" ], solution: [\"[][]\"] },\n            { question: \"Sort an integer array `nums` in ascending order.\", template: [ \"Arrays.\", { type: \"input\", size: 5, placeholder: \"method\" }, \"(nums);\" ], solution: [\"sort\"] }\n        ],\n        \"Control Flow\": [\n            { question: \"Write an `if` statement to check if `age` is 18 or greater.\", template: [ { type: \"input\", size: 3, placeholder: \"cond\" }, \" (age >= 18) { ... }\" ], solution: [\"if\"] },\n            { question: \"Write a `for` loop to print numbers from 1 to 5.\", template: [ \"for (int i = 1; i <= 5; \", { type: \"input\", size: 4, placeholder: \"increment\" }, \") { ... }\" ], solution: [\"i++\"] },\n            { question: \"Use a `switch` statement to handle a case for the character 'A'.\", template: [ \"switch (grade) {<br>&nbsp;&nbsp;&nbsp;&nbsp;\", { type: \"input\", size: 6, placeholder: \"keyword\" }, \" 'A':<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(\\\"Excellent\\\");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>}\" ], solution: [\"case\"] },\n            { question: \"What keyword is used to skip the current iteration of a loop?\", template: [ { type: \"select\", options: [\"continue\", \"break\", \"skip\"] } ], solution: [\"continue\"] },\n            { question: \"Write a `while` loop that runs as long as `isLoading` is true.\", template: [ { type: \"input\", size: 6, placeholder: \"loop\" }, \" (isLoading) { ... }\" ], solution: [\"while\"] }\n        ],\n        \"Methods\": [\n            { question: \"Define a simple method `sayHello` that prints 'Hello!'.\", template: [ { type: \"input\", size: 5, placeholder: \"type\" }, \" sayHello() { ... }\" ], solution: [\"void\"] },\n            { question: \"Define a method `sum` that takes two integers and returns their sum.\", template: [ \"int sum(int a, int b) {<br>&nbsp;&nbsp;&nbsp;&nbsp;\", { type: \"input\", size: 7, placeholder: \"keyword\" }, \" a + b;<br>}\" ], solution: [\"return\"] },\n            { question: \"How do you call the `sum` method with arguments 10 and 20?\", template: [ \"int result = \", { type: \"input\", size: 11, placeholder: \"method(args)\" }, \";\" ], solution: [\"sum(10, 20)\"] },\n            { question: \"A `static` method belongs to the class, not an...\", template: [ \"...not an \", { type: \"input\", size: 9, placeholder: \"object\" }, \".\" ], solution: [\"instance\"] },\n            { question: \"Method overloading is when methods have the same name but different...\", template: [ \"...but different \", { type: \"input\", size: 11, placeholder: \"signature\" }, \".\" ], solution: [\"parameters\"] }\n        ],\n        \"Classes & Objects\": [\n            { question: \"Define an empty class named `Person`.\", template: [ { type: \"input\", size: 6, placeholder: \"keyword\" }, \" Person { }\" ], solution: [\"class\"] },\n            { question: \"A special method used to initialize an object is called a...\", template: [ { type: \"input\", size: 12, placeholder: \"name\" } ], solution: [\"constructor\"] },\n            { question: \"Create an instance of the `Person` class.\", template: [ \"Person p1 = \", { type: \"input\", size: 4, placeholder: \"op\" }, \" Person();\" ], solution: [\"new\"] },\n            { question: \"The `this` keyword refers to the current...\", template: [ \"...the current \", { type: \"input\", size: 9, placeholder: \"object\" }, \" of the class.\" ], solution: [\"instance\"] },\n            { question: \"Add an integer member variable `age` to the `Person` class.\", template: [ \"class Person {<br>&nbsp;&nbsp;&nbsp;&nbsp;public int \", { type: \"input\", size: 4, placeholder: \"var\" }, \";<br>}\" ], solution: [\"age\"] }\n        ],\n        \"OOP Concepts\": [\n            { question: \"Which OOP principle involves bundling data and methods together?\", template: [ { type: \"select\", options: [\"Encapsulation\", \"Inheritance\", \"Polymorphism\"] } ], solution: [\"Encapsulation\"] },\n            { question: \"Which keyword is used for a class to inherit from another class?\", template: [ \"class Dog \", { type: \"input\", size: 8, placeholder: \"keyword\" }, \" Animal { ... }\" ], solution: [\"extends\"] },\n            { question: \"Method overriding is a feature of which OOP principle?\", template: [ { type: \"input\", size: 13, placeholder: \"concept\" } ], solution: [\"Polymorphism\"] },\n            { question: \"Declare a class `Utility` that cannot be subclassed.\", template: [ { type: \"input\", size: 6, placeholder: \"keyword\" }, \" class Utility { ... }\" ], solution: [\"final\"] },\n            { question: \"Which OOP principle hides complex implementation details from the user?\", template: [ { type: \"select\", options: [\"Abstraction\", \"Inheritance\", \"Encapsulation\"] } ], solution: [\"Abstraction\"] }\n        ],\n        \"Exception Handling\": [\n            { question: \"Write a `try-catch` block to handle an exception.\", template: [ { type: \"input\", size: 4, placeholder: \"block1\" }, \" { ... } \", { type: \"input\", size: 6, placeholder: \"block2\" }, \" (Exception e) { ... }\" ], solution: [\"try\", \"catch\"] },\n            { question: \"The `finally` block executes regardless of whether an exception...\", template: [ \"...was \", { type: \"input\", size: 7, placeholder: \"raised\" }, \".\" ], solution: [\"thrown\"] },\n            { question: \"Which keyword is used to manually throw an exception?\", template: [ { type: \"select\", options: [\"throw\", \"throws\", \"new\"] }, \" new Exception();\" ], solution: [\"throw\"] },\n            { question: \"Checked exceptions must be handled at...\", template: [ \"...\", { type: \"input\", size: 13, placeholder: \"when\" }, \".\" ], solution: [\"compile-time\"] },\n            { question: \"A method that might throw an exception must declare it using the...\", template: [ \"...the `\", { type: \"input\", size: 7, placeholder: \"keyword\" }, \"` keyword.\" ], solution: [\"throws\"] }\n        ],\n        \"Collections Framework\": [\n            { question: \"Create an `ArrayList` of strings named `names`.\", template: [ \"ArrayList<String> names = \", { type: \"input\", size: 4, placeholder: \"op\" }, \" ArrayList<>();\" ], solution: [\"new\"] },\n            { question: \"Add the element `\\\"Apple\\\"` to the `names` ArrayList.\", template: [ \"names.\", { type: \"input\", size: 4, placeholder: \"method\" }, \"(\\\"Apple\\\");\" ], solution: [\"add\"] },\n            { question: \"A `List` allows duplicates, while a `Set` does not.\", template: [ { type: \"select\", options: [\"True\", \"False\"] } ], solution: [\"True\"] },\n            { question: \"Create a `HashMap` to store String keys and Integer values.\", template: [ \"HashMap<\", { type: \"input\", size: 16, placeholder: \"KeyType, ValueType\" }, \"> map = new HashMap<>();\" ], solution: [\"String, Integer\"] },\n            { question: \"Get the value for the key `\\\"age\\\"` from a `HashMap` named `person`.\", template: [ \"person.\", { type: \"input\", size: 4, placeholder: \"method\" }, \"(\\\"age\\\");\" ], solution: [\"get\"] }\n        ],\n        \"Interfaces & Abstract Classes\": [\n            { question: \"Can you create an instance of an abstract class?\", template: [ { type: \"select\", options: [\"No\", \"Yes\"] } ], solution: [\"No\"] },\n            { question: \"Which keyword is used for a class to use an interface?\", template: [ \"class MyClass \", { type: \"input\", size: 11, placeholder: \"keyword\" }, \" MyInterface { ... }\" ], solution: [\"implements\"] },\n            { question: \"A class can extend one superclass, but it can implement many...\", template: [ \"...many \", { type: \"input\", size: 11, placeholder: \"what\" }, \".\" ], solution: [\"interfaces\"] },\n            { question: \"An `abstract` method has no...\", template: [ \"...has no \", { type: \"input\", size: 5, placeholder: \"implementation\" }, \".\" ], solution: [\"body\"] },\n            { question: \"Define an abstract method `draw` that returns void.\", template: [ \"public \", { type: \"input\", size: 9, placeholder: \"keyword\" }, \" void draw();\" ], solution: [\"abstract\"] }\n        ],\n        \"File I\/O\": [\n            { question: \"Which class is commonly used for reading character files?\", template: [ { type: \"select\", options: [\"FileReader\", \"FileStream\", \"InputReader\"] } ], solution: [\"FileReader\"] },\n            { question: \"Create a `File` object for a file named `\\\"output.txt\\\"`.\", template: [ \"File file = new File(\", { type: \"input\", size: 14, placeholder: \"filepath\" }, \");\" ], solution: [\"\\\"output.txt\\\"\"] },\n            { question: \"Wrapping a `FileReader` in a `BufferedReader` improves...\", template: [ \"...improves \", { type: \"input\", size: 12, placeholder: \"benefit\" }, \".\" ], solution: [\"performance\"] },\n            { question: \"Which class is used to write character streams to a file?\", template: [ { type: \"select\", options: [\"FileWriter\", \"FileStream\", \"OutputWriter\"] } ], solution: [\"FileWriter\"] },\n            { question: \"It is important to `close()` file streams to prevent...\", template: [ \"...to prevent resource \", { type: \"input\", size: 6, placeholder: \"problem\" }, \".\" ], solution: [\"leaks\"] }\n        ],\n        \"Multithreading\": [\n            { question: \"What are the two ways to create a thread in Java?\", template: [ \"Extend `Thread` or implement `\", { type: \"input\", size: 9, placeholder: \"interface\" }, \"`.\" ], solution: [\"Runnable\"] },\n            { question: \"Which method is called to start the execution of a thread?\", template: [ \"myThread.\", { type: \"input\", size: 7, placeholder: \"method\" }, \"();\" ], solution: [\"start\"] },\n            { question: \"The logic that a thread executes goes inside which method?\", template: [ \"public void \", { type: \"input\", size: 4, placeholder: \"method\" }, \"() { ... }\" ], solution: [\"run\"] },\n            { question: \"What does the `synchronized` keyword prevent?\", template: [ \"It prevents \", { type: \"input\", size: 12, placeholder: \"an issue\" }, \".\" ], solution: [\"race conditions\"] },\n            { question: \"The `join()` method makes the current thread wait until another thread...\", template: [ \"...another thread \", { type: \"input\", size: 6, placeholder: \"terminates\" }, \".\" ], solution: [\"dies\"] }\n        ],\n        \"Generics\": [\n            { question: \"What is the primary purpose of Generics?\", template: [ \"To provide \", { type: \"input\", size: 11, placeholder: \"a benefit\" }, \".\" ], solution: [\"type-safety\"] },\n            { question: \"Declare a generic `ArrayList` for `Integer` objects.\", template: [ \"ArrayList<\", { type: \"input\", size: 8, placeholder: \"type\" }, \"> list = new ArrayList<>();\" ], solution: [\"Integer\"] },\n            { question: \"What does the `?` (wildcard) represent in generics?\", template: [ \"It represents an \", { type: \"input\", size: 8, placeholder: \"concept\" }, \" type.\" ], solution: [\"unknown\"] },\n            { question: \"Can you use primitive types like `int` with generics?\", template: [ { type: \"select\", options: [\"No\", \"Yes\"] } ], solution: [\"No\"] },\n            { question: \"Define a generic class `Box` that can hold any type `T`.\", template: [ \"public class Box<\", { type: \"input\", size: 2, placeholder: \"Type\" }, \"> { ... }\" ], solution: [\"T\"] }\n        ],\n        \"Lambda Expressions & Streams\": [\n            { question: \"A lambda expression is an anonymous...\", template: [ \"...anonymous \", { type: \"input\", size: 9, placeholder: \"concept\" }, \".\" ], solution: [\"function\"] },\n            { question: \"Write a lambda expression that returns the sum of two integers `a` and `b`.\", template: [ \"(a, b) \", { type: \"input\", size: 3, placeholder: \"op\" }, \" a + b;\" ], solution: [\"->\"] },\n            { question: \"A functional interface has exactly one...\", template: [ \"...one \", { type: \"input\", size: 9, placeholder: \"what kind of\" }, \" method.\" ], solution: [\"abstract\"] },\n            { question: \"From a `List<String> names`, how do you start a stream pipeline?\", template: [ \"names.\", { type: \"input\", size: 7, placeholder: \"method\" }, \"()\" ], solution: [\"stream\"] },\n            { question: \"Which stream operation is used to transform each element?\", template: [ { type: \"select\", options: [\"map\", \"filter\", \"reduce\"] } ], solution: [\"map\"] }\n        ],\n        \"JDBC\": [\n            { question: \"What does JDBC stand for?\", template: [ \"Java \", { type: \"input\", size: 9, placeholder: \"D...\" }, \" Connectivity\" ], solution: [\"Database\"] },\n            { question: \"Which interface is the entry point for most JDBC operations?\", template: [ { type: \"input\", size: 11, placeholder: \"ClassName\" } ], solution: [\"Connection\"] },\n            { question: \"Which object is used to execute a static SQL statement?\", template: [ { type: \"input\", size: 10, placeholder: \"ClassName\" } ], solution: [\"Statement\"] },\n            { question: \"A `PreparedStatement` helps prevent...\", template: [ \"...prevents \", { type: \"input\", size: 14, placeholder: \"a vulnerability\" }, \".\" ], solution: [\"SQL injection\"] },\n            { question: \"Which object holds the data retrieved from a database query?\", template: [ { type: \"input\", size: 10, placeholder: \"ClassName\" } ], solution: [\"ResultSet\"] }\n        ],\n        \"Enums & Annotations\": [\n            { question: \"Define a simple enum for directions.\", template: [ \"public \", { type: \"input\", size: 5, placeholder: \"type\" }, \" Direction { NORTH, SOUTH, EAST, WEST; }\" ], solution: [\"enum\"] },\n            { question: \"An enum is used to represent a fixed set of...\", template: [ \"...set of \", { type: \"input\", size: 10, placeholder: \"values\" }, \".\" ], solution: [\"constants\"] },\n            { question: \"What is the `@Override` annotation used for?\", template: [ \"To indicate a method \", { type: \"input\", size: 9, placeholder: \"an action\" }, \" a superclass method.\" ], solution: [\"overrides\"] },\n            { question: \"Can enums have constructors and methods?\", template: [ { type: \"select\", options: [\"Yes\", \"No\"] } ], solution: [\"Yes\"] },\n            { question: \"An annotation with no members is called a...\", template: [ \"...a `\", { type: \"input\", size: 7, placeholder: \"type\" }, \"` annotation.\" ], solution: [\"marker\"] }\n        ]\n    };\n\n    document.addEventListener('DOMContentLoaded', function() {\n        const topicSelectionView = document.getElementById('jv-ex-topic-selection-view');\n        const exerciseViewsContainer = document.getElementById('jv-ex-exercise-views-container');\n\n        \/\/ --- Utility Functions ---\n        function normalizeCode(codeStr) {\n            if (typeof codeStr !== 'string') return '';\n            return codeStr.replace(\/\u201c|\u201d|\u2018|\u2019\/g, '\"').trim().replace(\/;$\/, '');\n        }\n        \n        \/\/ --- View Switching Logic ---\n        function showTopicView(topicKey) {\n            topicSelectionView.style.display = 'none';\n            document.querySelectorAll('.jv-ex-exercise-view').forEach(view => view.style.display = 'none');\n            const view = document.getElementById(`jv-ex-view-${topicKey}`);\n            if (view) {\n                 view.style.display = 'block';\n            }\n        }\n\n        function showTopicSelection() {\n            topicSelectionView.style.display = 'block';\n            document.querySelectorAll('.jv-ex-exercise-view').forEach(view => view.style.display = 'none');\n        }\n        \n        \/\/ --- Initialization ---\n        function initialize() {\n            const topics = Object.keys(exercises);\n\n            \/\/ Pre-build all Exercise Views (CSR part)\n            topics.forEach(topic => {\n                const topicKey = topic.replace(\/[^a-zA-Z0-9]\/g, '');\n                const questions = exercises[topic];\n\n                let questionsHTML = '';\n                questions.forEach((q, qIndex) => {\n                    let templateHTML = '';\n                    let inputCounter = 0;\n                    q.template.forEach(part => {\n                        if (typeof part === 'string') {\n                            templateHTML += part; \n                        } else if (part.type === 'input') {\n                            templateHTML += `<input type=\"text\" class=\"jv-input\" id=\"jv-ex-answer-${topicKey}-${qIndex}-${inputCounter}\" size=\"${part.size || 10}\" placeholder=\"${part.placeholder || '...'}\">`;\n                            inputCounter++;\n                        } else if (part.type === 'select') {\n                            const optionsHTML = part.options.map(opt => `<option value=\"${opt}\">${opt}<\/option>`).join('');\n                            templateHTML += `<select class=\"jv-select\" id=\"jv-ex-answer-${topicKey}-${qIndex}-${inputCounter}\">${optionsHTML}<\/select>`;\n                            inputCounter++;\n                        }\n                    });\n\n                    questionsHTML += `\n                        <div style=\"border: 1px solid #E5E7EB; border-radius: 0.5rem;\">\n                            <div style=\"padding: 1rem; border-bottom: 1px solid #E5E7EB;\">\n                                 <p style=\"font-weight: 500; margin:0; color: #374151;\">\n                                    <span style=\"font-weight: 700; color: #111827;\">Question ${qIndex + 1}:<\/span> ${q.question}\n                                <\/p>\n                            <\/div>\n                            <div class=\"jv-code-template\"><pre style=\"margin:0; padding:0; white-space: pre-wrap;\"><code style=\"font-family: monospace;\">${templateHTML}<\/code><\/pre><\/div>\n                            <div id=\"jv-ex-feedback-${topicKey}-${qIndex}\" style=\"margin-top: 0.5rem; padding: 0 1rem 0.5rem 1rem;\"><\/div>\n                        <\/div>\n                    `;\n                });\n\n                const exerciseViewHTML = `\n                    <div id=\"jv-ex-view-${topicKey}\" class=\"jv-ex-exercise-view\" style=\"display: none;\">\n                        <div style=\"display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem; gap: 1rem;\">\n                            <h2 style=\"font-size: 1.5rem; line-height: 2rem; font-weight: 700; color: #111827; margin:0;\" style=\"font-size: 1.5rem; line-height: 2rem; font-weight: 700; color: #111827; margin:0;\" id=\"topic\">${topic}<\/h2>\n                            <button class=\"jv-ex-back-btn\" style=\"background-color: #E5E7EB; color: #374151; font-weight: 500; padding: 0.5rem 1rem; border-radius: 0.5rem; border: none; cursor: pointer;\" onmouseover=\"this.style.backgroundColor='#D1D5DB'\" onmouseout=\"this.style.backgroundColor='#E5E7EB'\">Back to Topics<\/button>\n                        <\/div>\n                        <div style=\"display: flex; flex-direction: column; gap: 1.5rem;\">${questionsHTML}<\/div>\n                        <div id=\"jv-ex-result-container-${topicKey}\" style=\"text-align: center; margin-top: 2rem;\"><\/div>\n                        <div style=\"text-align: center; margin-top: 1.5rem;\">\n                             <button class=\"jv-ex-check-answers-btn\" data-topic-key=\"${topicKey}\" data-topic-name=\"${topic}\" style=\"background-color: #2563EB; color: #FFFFFF; font-weight: 700; padding: 0.75rem 2rem; border-radius: 0.5rem; font-size: 1.125rem; border: none; cursor: pointer; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);\" onmouseover=\"this.style.backgroundColor='#1D4ED8'\" onmouseout=\"this.style.backgroundColor='#2563EB'\">Check Answers<\/button>\n                        <\/div>\n                    <\/div>\n                `;\n                exerciseViewsContainer.innerHTML += exerciseViewHTML;\n            });\n\n            \/\/ --- Attach Event Listeners ---\n            document.querySelectorAll('.topic-item-btn').forEach(button => {\n                const topicKey = button.getAttribute('data-topic-key');\n                if (topicKey) {\n                    button.addEventListener('click', () => showTopicView(topicKey));\n                }\n            });\n\n            document.querySelectorAll('.jv-ex-back-btn').forEach(btn => {\n                btn.addEventListener('click', showTopicSelection);\n            });\n\n            document.querySelectorAll('.jv-ex-check-answers-btn').forEach(btn => {\n                btn.addEventListener('click', (event) => {\n                    const topicKey = event.currentTarget.getAttribute('data-topic-key');\n                    const topicName = event.currentTarget.getAttribute('data-topic-name');\n                    const questions = exercises[topicName];\n                    let correctCount = 0;\n\n                    questions.forEach((q, qIndex) => {\n                        const feedbackContainer = document.getElementById(`jv-ex-feedback-${topicKey}-${qIndex}`);\n                        let isCorrect = true;\n                        let inputCounter = 0;\n\n                        q.template.forEach(part => {\n                            if (typeof part === 'object') {\n                                const userInputElem = document.getElementById(`jv-ex-answer-${topicKey}-${qIndex}-${inputCounter}`);\n                                const userAnswer = normalizeCode(userInputElem.value);\n                                const correctAnswer = normalizeCode(q.solution[inputCounter]);\n                                if (userAnswer.toLowerCase() !== correctAnswer.toLowerCase()) {\n                                    isCorrect = false;\n                                }\n                                inputCounter++;\n                            }\n                        });\n\n                        if (isCorrect) {\n                            correctCount++;\n                            feedbackContainer.innerHTML = `<p style=\"color: #16A34A; font-weight: 600; margin:0;\">\u2713 Correct!<\/p>`;\n                        } else {\n                            \/\/ Reconstruct the correct answer string for display\n                            let correctAnswerHTML = '';\n                            let solutionCounter = 0;\n                            q.template.forEach(part => {\n                                if (typeof part === 'string') {\n                                    correctAnswerHTML += part.replace(\/<\/g, \"&lt;\").replace(\/>\/g, \"&gt;\");\n                                } else {\n                                    correctAnswerHTML += `<strong style=\"color: #166534;\">${q.solution[solutionCounter]}<\/strong>`;\n                                    solutionCounter++;\n                                }\n                            });\n\n                            feedbackContainer.innerHTML = `\n                                <p style=\"color: #DC2626; font-weight: 600; margin:0;\">\u2717 Incorrect.<\/p>\n                                <p style=\"color: #4B5563; margin-top: 0.25rem; margin-bottom: 0.25rem;\">The correct code is:<\/p>\n                                <div class=\"jv-code-template\" style=\"background-color: #F0FDF4;\"><pre style=\"margin:0; padding:0; white-space: pre-wrap;\"><code style=\"font-family: monospace;\">${correctAnswerHTML}<\/code><\/pre><\/div>\n                            `;\n                        }\n                    });\n\n                    const resultContainer = document.getElementById(`jv-ex-result-container-${topicKey}`);\n                    resultContainer.innerHTML = `\n                        <p style=\"font-size: 1.25rem; font-weight: 700;\">You answered ${correctCount} out of ${questions.length} questions correctly.<\/p>\n                        <p style=\"color: #6B7280; margin-top: 0.25rem;\">Review the feedback above and feel free to try again!<\/p>\n                    `;\n                });\n            });\n        }\n\n        \/\/ Run the initialization\n        initialize();\n    });\n<\/script>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>Also Check:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/java-project-ideas\/\">Java Projects<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/java-quiz\/\">Java Quiz and MCQs<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/java-interview-questions\/\">Java Interview Questions and Answers<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/data-types-in-java\/\">Java Data Types<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/top-spring-boot-projects\/\">Top Springboot Projects<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Work through Java practice programs, coding questions, and online exercises to improve your programming skills. Ideal for beginners and interview prep.<\/p>\n","protected":false},"author":41,"featured_media":111728,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"full-width-container","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36826],"class_list":["post-111719","page","type-page","status-publish","has-post-thumbnail","hentry","category-software","tag-java"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Java Practice Programs and Coding Questions for Beginners<\/title>\n<meta name=\"description\" content=\"Work through Java practice programs, coding questions, and online exercises to improve your programming skills. Ideal for beginners and interview prep.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Exercises\" \/>\n<meta property=\"og:description\" content=\"Work through Java practice programs, coding questions, and online exercises to improve your programming skills. Ideal for beginners and interview prep.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1408\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-exercise\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-exercise\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Java Exercises\",\"datePublished\":\"2025-09-04T07:16:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-exercise\\\/\"},\"wordCount\":26,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-exercise\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/java-exercise.webp\",\"keywords\":[\"java\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-exercise\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-exercise\\\/\",\"name\":\"Java Practice Programs and Coding Questions for Beginners\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-exercise\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-exercise\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/java-exercise.webp\",\"datePublished\":\"2025-09-04T07:16:23+00:00\",\"description\":\"Work through Java practice programs, coding questions, and online exercises to improve your programming skills. Ideal for beginners and interview prep.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-exercise\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-exercise\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-exercise\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/java-exercise.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/java-exercise.webp\",\"width\":1408,\"height\":768},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-exercise\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Exercises\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Java Practice Programs and Coding Questions for Beginners","description":"Work through Java practice programs, coding questions, and online exercises to improve your programming skills. Ideal for beginners and interview prep.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/","og_locale":"en_US","og_type":"article","og_title":"Java Exercises","og_description":"Work through Java practice programs, coding questions, and online exercises to improve your programming skills. Ideal for beginners and interview prep.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","og_image":[{"width":1408,"height":768,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_site":"@Great_Learning","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Java Exercises","datePublished":"2025-09-04T07:16:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/"},"wordCount":26,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise.webp","keywords":["java"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/","url":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/","name":"Java Practice Programs and Coding Questions for Beginners","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise.webp","datePublished":"2025-09-04T07:16:23+00:00","description":"Work through Java practice programs, coding questions, and online exercises to improve your programming skills. Ideal for beginners and interview prep.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise.webp","width":1408,"height":768},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/java-exercise\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Java Exercises"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise.webp",1408,768,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise-150x150.webp",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise-300x164.webp",300,164,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise-768x419.webp",768,419,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise-1024x559.webp",1024,559,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise.webp",1408,768,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise.webp",1408,768,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise-640x768.webp",640,768,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise-96x96.webp",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/java-exercise-150x82.webp",150,82,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Work through Java practice programs, coding questions, and online exercises to improve your programming skills. Ideal for beginners and interview prep.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/111719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=111719"}],"version-history":[{"count":9,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/111719\/revisions"}],"predecessor-version":[{"id":111750,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/111719\/revisions\/111750"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/111728"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=111719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=111719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=111719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}