Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn Java with Projects

You're reading from   Learn Java with Projects A concise practical guide to learning everything a Java professional really needs to know

Arrow left icon
Product type Paperback
Published in Nov 2023
Publisher Packt
ISBN-13 9781837637188
Length 598 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Maaike van Putten Maaike van Putten
Author Profile Icon Maaike van Putten
Maaike van Putten
Dr. Seán Kennedy Dr. Seán Kennedy
Author Profile Icon Dr. Seán Kennedy
Dr. Seán Kennedy
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Part 1: Java Fundamentals
2. Chapter 1: Getting Started with Java FREE CHAPTER 3. Chapter 2: Variables and Primitive Data Types 4. Chapter 3: Operators and Casting 5. Chapter 4: Conditional Statements 6. Chapter 5: Understanding Iteration 7. Chapter 6: Working with Arrays 8. Chapter 7: Methods 9. Part 2: Object-Oriented Programming
10. Chapter 8: Classes, Objects, and Enums 11. Chapter 9: Inheritance and Polymorphism 12. Chapter 10: Interfaces and Abstract Classes 13. Chapter 11: Dealing with Exceptions 14. Chapter 12: Java Core API 15. Part 3: Advanced Topics
16. Chapter 13: Generics and Collections 17. Chapter 14: Lambda Expressions 18. Chapter 15: Streams – Fundamentals 19. Chapter 16: Streams: Advanced Concepts 20. Chapter 17: Concurrency 21. Index

Exercises

And that’s all theory for this chapter! So, roll up those sleeves, and let’s dive into your first day at Mesozoic Eden. Welcome aboard! Mesozoic Eden is a famous zoo where dinosaurs live that have been brought to live with high end genetic manipulation techniques. Here are some exercises for you to test your knowledge so far:

  1. Your first task involves welcoming our guests. Modify the following code snippet so that it outputs "Welcome to Mesozoic Eden":
    public class Main {
        public static void main(String[] args) {
            System.out.println("Hello world");
        }
    }
  2. Complete the following programs by filling out the blanks so that it prints out your name and the position you want to have in Mesozoic Eden 5 years from now:
    public class Main {
        public static void main(String[] args) {
            __________________________;
            String position = "Park Manager";
            System.out.println("My name is " + name + "
              and I want to be a " ______ " in Mesozoic
                Eden.");
        }
    }
  3. We’ve received some questions about opening hours. Complete the following program so that it prints the park’s opening and closing hours:
    public class Main {
        public static void main(String[] args) {
            String openingHours = "08:00";
            String closingHours = "20:00";
        }
    }
  4. Create a Java project with a package named dinosaur. You can create a package by right-clicking on the src/main/java folder, selecting “new” and choosing “package”.
  5. Modify the code from exercise 1 so that it prints out "Welcome, [YourName] to Mesozoic Eden!", where [YourName] is replaced by, surprise surprise, your name. Bonus: try to create a separate String variable as shown in the second and third exercises.
  6. Some guests reported feeling unsafe near the T-Rex. Let’s solve this by adding another System.out.println to the program of exercise 5. It should print the phrase "Mesozoic Eden is safe and secure." after the welcome message.
You have been reading a chapter from
Learn Java with Projects
Published in: Nov 2023
Publisher: Packt
ISBN-13: 9781837637188
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £16.99/month. Cancel anytime