Skip to content

Java attributes and methods

Rashmika_Harshamal edited this page Jul 20, 2026 · 27 revisions

Java Attributes and Methods in the HMIS System

Java attributes and methods are essential parts of HMIS development.

Attributes store information such as:

  • Patient name
  • Patient code
  • Bill total
  • Created date
  • Department
  • Investigation
  • Report status
  • Retired status

Methods are used to:

  • Read attribute values
  • Change attribute values
  • Validate data
  • Calculate totals
  • Process reports
  • Search database records
  • Clear filters
  • Format information for display

A simple HMIS-style example is:

private String patientCode;

private double total;

private boolean retired;

public String getPatientCode() { return patientCode; }

public void setPatientCode(String patientCode) { this.patientCode = patientCode; }

public double calculateNetTotal(double discount) { return total - discount; }

In this example:

  • patientCode, total, and retired are attributes.
  • getPatientCode(), setPatientCode(), and calculateNetTotal() are methods.

1. Java Attributes

An attribute stores data inside a Java component. Attributes are also called:

  • Fields
  • Member variables
  • Instance variables
  • Properties, especially when accessed through getters and setters

General syntax : accessModifier dataType attributeName;

private String patientName;

  • private is the access modifier.
  • String is the data type.
  • patientName is the attribute name.

Exmples

  • private Long id;
  • private String patientCode;
  • private Date createdAt;
  • private Department department;
  • private Investigation investigation;
  • private boolean retired;
  • private List results;

Attribute Declaration

An attribute can be declared without an initial value.

private String patientName;

It can also be declared with an initial value.

private boolean retired = false;

A collection should often be initialized immediately.

private List results = new ArrayList<>();

This is safer than:

private List results;

because using an uninitialized list may cause a NullPointerException.

For example :

results.clear();

will fail when results is null.

Attribute Data Types

Attributes may use primitive types or reference types.

Primitive attributes

private int patientCount;

private long recordCount;

private double total;

private boolean retired;

private char categoryCode;

  • Primitive types cannot contain null.

Reference attributes

private String patientName;

private Date createdAt;

private Department department;

private Investigation investigation;

private List bills;

  • Reference attributes can contain null.

Primitive and Wrapper Attributes

Primitive

  • int
  • long
  • double
  • boolean
  • char
  • float
  • short
  • byte

Wrapper

  • Integer
  • Long
  • Double
  • Boolean
  • Character
  • Float
  • Short
  • Byte

Example:

private boolean retired;

private Boolean approved;

retired can contain:

  • true
  • false

approved can contain:

  • true
  • false
  • null

Use primitive types when a value must always exist. And use wrapper types when the value may be unknown or nullable. For database query projections and DTO attributes, wrapper types are often safer.

Clone this wiki locally