A "Hello, World" Example for Java Beans - Java Object Oriented Design

Java examples for Object Oriented Design:Java Bean

Introduction

Methods beginning with set and get are termed as setter and getter methods.

The Main Program

public static void main(...) is used from within a public class to denote the entry point of a Java program.

Demo Code

 
 
public class Main {
    /* The main method begins in this class */
 
    public static void main(String[] args) {
         /*from w w  w  . jav  a  2 s.  co m*/
        HelloMessage hm;     
        hm = new HelloMessage();
         
        System.out.println(hm.getMessage());
         
        hm.setMessage("Hello, World");
         
        System.out.println(hm.getMessage());    
    }
}
 
class HelloMessage {
    private String message = "";
    
    public HelloMessage() {
        this.message = "Default Message";
    }
         
    public void setMessage (String m) {
        this.message = m;
    }
    
    public String getMessage () {
        return this.message.toUpperCase();
    }   
}

Result


Related Tutorials