Blog Detail

September 23, 2023

Java Basics Exercises – Part 3

  • Use camel case convention to name this variable.

                    class Main {
      public static void main(String[] args) {
        String "" = "Yesterday";
      }
    }
  • Use numbers to define related variables.

                    class Main {
      public static void main(String[] args) {
        String securityQuestion1 = "What was the name of your first pet?";
        String securityQuestion2 = "What is your favorite book?";
        String securityQuestion"" = "In which city were you born?";
      }
    }
  • What is the output of this Java code?

                    class Main {
      public static void main(String[] args) {
        String addressLine1 = "123 Main St.";
        String addressLine2 = "Apt. 4B";
        String fullAddress = addressLine1 + addressLine2;
    
        System.out.println(fullAddress);
      }
    }
  • Complete the name of this variable by using camel case convention.

                    class Main {
      public static void main(String[] args) {
        String "" = "A4";
      }
    }
  • What’s wrong with this variable?

                    class Main {
      public static void main(String[] args) {
        String product category = "electronics";
      }
    }
  • Which variable name is more descriptive for holding a total budget value?



  • Select the variable name that is more descriptive and meaningful.

                    class Main {
      public static void main(String[] args) {
        String "" = "C:\\files\\test.txt";
      }
    }
  • What’s wrong with this code?

                    class Main {
      public static void main(String[] args) {
        String budget = "$10000";
        system.out.println(budget);
      }
    }
  • What’s wrong with this code?

                    class Main {
      public static void main(String[] args) {
        String url = "https://dejavucode.com";
        System.out.println(URL);
      }
    }
  • What does case sensitivity mean in Java?



  • Java Exercises for Variables

    • If you’ve faced difficulties with these exercises, take a look at Variables Module on my Java course.


    You can also share ‘Java Variables’ Exercises on your:
    X (Twitter)TelegramLinkedinFacebook – or on your favorite platform…




    Happy Coding!
    Behnam Khani