Modeling Entities in Java: Methods, Method Overloading, & Constructors

Java    |    Intermediate
  • 12 videos | 1h 32m 17s
  • Includes Assessment
  • Earns a Badge
Rating 4.4 of 43 users Rating 4.4 of 43 users (43)
Modeling complex entities involves defining and invoking methods and constructors. Furthermore, defining robust and reusable code requires learning important mechanisms for code re-uses, such as constructor chaining and method overloading. Use this course to delve into these important techniques that are required to write clean and maintainable Java code. Learn how to define methods with the same name but different signatures (i.e., different order and type of input arguments), invoke overloaded methods, and add constructors to a class. This course will also enable you to use the 'this' keyword to invoke multiple constructors, also known as constructor chaining. By the time you are done with this course, you will have the skills to use important code re-use mechanisms such as method overloading and constructor chaining in java.

WHAT YOU WILL LEARN

  • Discover the key concepts covered in this course
    Implement return values and types correctly
    Create objects of a java class and use getters and setters to edit fields
    Overload methods with the same name in java
    Recall how overloaded methods work and how they can invoke one another
    Use the default, no-argument constructor to create objects
  • Initialize fields in constructor definitions
    Create and use parameterized constructors in java
    Create multiple constructors with different signatures
    Initialize fields using the 'this' keyword
    Reuse code using constructor chaining
    Summarize the key concepts covered in this course

IN THIS COURSE

  • 1m 51s
    Explore how to define methods with the same name but different signatures. You’ll see how overloaded methods can invoke each other and how it’s not permissible to overload methods purely on the return type alone. You’ll also learn the correct way of adding constructors to a class. You’ll see how multiple constructors can invoke each other using the keyword. FREE ACCESS
  • 10m 5s
    Further explore methods in Java. You’ll remember that in Java every class must match the name of the Java file in which it is hosted. Onscreen, you’ll see a class called Employee, so it is in a file called Employee.java. You’ll see this Employee class is a public class. FREE ACCESS
  • Locked
    3.  Using Getters and Setters
    10m 46s
    Here, you’ll watch a demo. In this demo, you’ll pick up where you left off in the last demo. You’ll continue experimenting with different types of methods inside your employee class. You’ll begin by deleting the unreachable statement on line 25. This causes the compiler error to go away. You’ll then reintroduce some other compiler Errors. incompatible types. FREE ACCESS
  • Locked
    4.  Defining Multiple Functions Using Method Overloading
    12m
    Discover that methods are functions that are different inside a class and which operate on the member variables of that particular object of the class. Watch a demo, and continue working with methods as they’re an important building block of Java. You’ll switch back to your employee class, and return to the update method defined in the previous demo. FREE ACCESS
  • Locked
    5.  Working with Method Overloading and Code Reuse
    9m 28s
    Here, you’ll watch a demo. You ended the last demo on the subject of method overloading onscreen. Here, you have three overloaded versions of the update method in your employee.Java file. Java is perfectly fine with methods that have the same name, provided they differ in their signatures. You’ll switch over to the main.Java file and use some overloaded methods. FREE ACCESS
  • Locked
    6.  Understanding and Using Default Constructors
    8m 20s
    Here, you’ll learn to understand and use default constructors. You’ll learn these are special methods that help create an object and bring it to life by assigning memory and values to fields and the state of the object. This demo will highlight the capabilities and finer points of working with constructors. You’ll start with the Project Explorer Open. FREE ACCESS
  • Locked
    7.  Initializing Fields in Constructors
    6m 38s
    Continue working with constructors of different types in Java. Set up a simple helper method called PrintCarInfo. This will help you examine the contents of different objects. This method is defined onscreen. It simply prints out the state of an object. This means it prints out the values of the four member variables contained within each object. FREE ACCESS
  • Locked
    8.  Creating Parameterized Constructors
    7m 22s
    Explore creating parameterized constructors. A parameterized constructor that takes in input arguments and assigns those input arguments to the values of the objects fields. Onscreen, you’ll see modified code. You can see this has the features of a constructor. First, it has the same name as the class. And, it has no return value. Constructors never have a return value. FREE ACCESS
  • Locked
    9.  Overloading Constructors
    9m 2s
    Explore overloading constructors. Take a look at overloaded constructors in your car.Java file. Notice the car class has no less than five constructors. Discover the default no argument constructor. It doesn't take in any input arguments and it simply prints out a message Default no - argument constructor. FREE ACCESS
  • Locked
    10.  Using 'this' Keyword in Field Initializations
    6m 4s
    Here, you’ll learn to use ‘this’ keyword in field initializations. In the previous demo, you implemented all ordered and parameterized constructors and made use of those constructors to build and instantiate different objects of the class. There are some aspects of the implementations of those constructors that can be improved upon, and you’ll focus on those here. FREE ACCESS
  • Locked
    11.  Reusing Code through Constructor Chaining
    8m 30s
    You’ll learn to reuse code through constructor chaining in this video. This refers to the practice of having multiple overloaded constructors that accept differing numbers of input arguments. They then call each other to minimize copy-pasting of code. There are some guidelines and rules to be kept in mind while chaining constructors. You’ll explore those in this demo. FREE ACCESS
  • Locked
    12.  Course Summary
    2m 10s
    Here, you’ll summarize what you’ve learned in this course. You’ve learned type-safety restrictions in Java. You then learned about method overloading. You learned how to invoke overloaded functions by specifying different input arguments, and learned you can’t define two different functions with the same name and signature. You also learned constructor chaining and the rules around this. FREE ACCESS

EARN A DIGITAL BADGE WHEN YOU COMPLETE THIS COURSE

Skillsoft is providing you the opportunity to earn a digital badge upon successful completion on some of our courses, which can be shared on any social network or business platform.

Digital badges are yours to keep, forever.

YOU MIGHT ALSO LIKE

Rating 4.3 of 78 users Rating 4.3 of 78 users (78)
Rating 4.6 of 25 users Rating 4.6 of 25 users (25)
Rating 4.6 of 128 users Rating 4.6 of 128 users (128)

PEOPLE WHO VIEWED THIS ALSO VIEWED THESE

Rating 4.6 of 60 users Rating 4.6 of 60 users (60)
Rating 4.4 of 38 users Rating 4.4 of 38 users (38)
Rating 4.5 of 86 users Rating 4.5 of 86 users (86)