Key Concepts

Review core concepts you need to learn to master this subject

Java objects’ state and behavior

public class Person { // state of an object int age; String name; // behavior of an object public void set_value() { age = 20; name = "Robin"; } public void get_value() { System.out.println("Age is " + age); System.out.println("Name is " + name); } // main method public static void main(String [] args) { // creates a new Person object Person p = new Person(); // changes state through behavior p.set_value(); } }

In Java, instances of a class are known as objects. Every object has state and behavior in the form of instance fields and methods respectively.

Java: Introduction to Classes
Lesson 1 of 2
  1. 1
    All programs require one or more classes that act as a model for the world. For example, a program to track student test scores might have Student, Course, and Grade classes. Our real-world concer…
  2. 2
    The fundamental concept of object-oriented programming is the class. A class is the set of instructions that describe how an instance can behave and what information it contains. Java has pre-d…
  3. 3
    In order to create an object (an instance of a class), we need a constructor method. The constructor is defined within the class. Let’s take a look at the Car class with a constructor. The constr…
  4. 4
    Our last exercise ended with printing an instance of Store, which looked something like [email protected] The first part, Store, refers to the class, and the second part @6bc7c054 refers to the insta…
  5. 5
    To create objects with dynamic, individual states, we’ll use a combination of the constructor method and instance fields. In order to assign a value to an instance variable, we need to alter our …
  6. 6
    Now that our constructor has a parameter, we must pass values into the method call. These values are referred to as arguments; once they are passed in, they will be used to give the instance fiel…
  7. 7
    Objects are not limited to a single instance field. We can declare as many fields as are necessary for the requirements of our program. Let’s change Car instances so they have multiple fields. We…
  8. 8
    Java is an object-oriented programming language where every program has at least one class. Programs are often built from many classes and objects, which are the instances of a class. Classes def…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo