JAVA – Methods


A method can be defined as a group of instructions that is given a name and can be called up anywhere in the program code by simply calling it by its name. For instance, a statement to draw a straight line can be given a name straight_line. You can then call the straight_line statement thrice to draw a triangle or you could save the method triangle and call it as and when required.

All programming languages support methods presumably by different names such as functions or procedures. The Java language, just like the C++ language from which it originated, supports methods.  Unlike the C++ language where an object can contain methods, the Java programming language declares a program which further contains functions known as methods. As you will notice, the method is declared in a similar manner as the method paint, the only difference being that the method paint is automatically called.

The code snippet below displays a simple method, calculate.

import java.awt.*;

import java.applet.*;

public class calculate_value extends Applet

{ int first_var, answer_var_1;

public void paint_function (Graphics graph_var)

{

First_var = 34;

Calculate_value();

g.draw_String(“Twice 46 is ” + answer_var_1, 50, 75);

}

public void calculate_value ()

{ answer_var_1 = first_var * 8;

}

}

As you can see, the method calculate_value is called by the statement calculate_value();. The syntax of the method requires the use of opening and closing braces after the method name (even they don’t contain anything) followed by a semicolon at the end.

However, it is just not enough to call a method. However, it is important to define a method before it is called. Else, the Java programming language will not know what to do when it encounters a method name.  The method definition always starts with the public or private keyword. Continue reading JAVA – Methods

JAVA – Primitive Types

The Java programming language uses certain fundamental elements such as numbers, characters, and Boolean values. These programming elements are not considered as objects in this language. Java supports the concept of wrapper classes in situations where a primitive value needs to be treated as an object. This helps the Java compiler optimize the performance of these objects.

The java Virtual Machine architecture helps define the precise or exact values of the primitive types. For example, according to this architecture, int is always defined as a 32-bit signed two digit compliment number. Some other types that can be defined in this manner are

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

These primitive types resemble the scalar types of the C programming language on a 32-bit machine that is byte oriented. The new programmers of Java language can use these data types to learn the language faster and with greater ease. Continue reading JAVA – Primitive Types

JAVA – Data Elements

The term data element refers to the smallest unit of data having a specific meaning associated with it and defined using a particular syntax. Some of the characteristics of data element are:

  • A data element has its own identification and is recognized by the same, such as the name of the data element.
  • They need to be clearly defined
  • The data elements consist of one or more terms used to represent this data element, also known as the representation terms.
  • A data element has some values associated with it in detail, also known as code.

You can use data elements when developing software applications or application data files. Use the process of Application discovery and understanding to discover data elements. Next, register these data elements in the metadata registry.