Java Tutorial

Naming Convention

Hungarian Notation:

Hungarian Notation is the naming convention followed by SUN (Stanford University Network) micro system to develop their predefined classes, interfaces, methods and data members.

Hungarian rule for Class or Interface:

If a class object interface contains more than one word then we must write all the first letters must be capital.

For example:

System, Number Format Exception, Array Index Out Of Bound Exception

Hungarian rule for Method:

If a method name contains more than one word then first word letter is small and rest of the words first letters must be capital.

For example:

println (), actionPerformed (), adjustmentValueChanged ()
            

Hungarian rule for Data Members:

All the data members are the predefined classes and interfaces must be represented used as capital letters.

For example:

PI, MAX_VALUE, and MIN_VALUE
            

All the data members in the predefined classes and interfaces are belongs to public static final XXX data members. XXX represents data type, variable name and variable value. Every final data member must belong to static data member but reverse may or may not be applicable.

Write a JAVA program to generate the multiplication table for the given number?

Answer:

class Mul //Business Logic Class (BLC)
{
	int n;
	void set (int x)
	{
		n=x;
	}
	void table ()
	{
		for (int i=1; i<=10; i++)
		{
			int res=n*i;
			System.out.println (n + "*" + i + "=" + result);
		}
	}
};

class MulDemo //Execution Logic Class (ELC)
{
   Public static class main (string k [])
	{
		Mul mo = new Mul (); mo.set (4);
		mo.table ();
	}
};
            

Note:

The data members of a class can be used in all the functions of the class.

The variable which we use as a part of function heading is known as formal parameters and they can be used within the function only.

The variables which we use as a part of function definition/body then those variables known as local variables and they can be used within its scope i.e., function definition.

The variables which we use within the function call then those variables are known as actual parameters.

For example:

int n=4; 
mo.set (n);
            

Where 'n' is the actual parameter.

The following table gives the details about those classes and methods used for converting storing data to fundamental data:

S.noData TypesWrapper classConversion Method from String Data to Fundamental Data Type
1byteBytepublic static byte parseByte (string)
2shortShortpublic static short parseShort (string)
3intIntegerpublic static int parseInt (string)
4longLongpublic static long parseLong (string)
5floutFloatpublic static float parseFloat (string)
6doubleDoublepublic static double parseDouble (string)
7charCharpublic static char parseChar (string)
8booleanBooleanpublic static boolean parseBoolean (string)

Whenever we develop a JAVA program it is recommended to write 'n' number of business logic classes and single execution logic class. A business logic class is one which contains 'n' number of user defined methods in which we write business logic. Business logic is one which is provided by JAVA programmer according business rules (requirements) started by customer. Whatever data we represent in JAVA runtime environment it is by default treated as objects of string data. As a programmer when we start any JAVA program an object of string class is created depends on number of values we pass.

Wrapper classes are basically used for converting the string data into fundamental data type. Each and every wrapper class contains the following generalized parse methods.

public static Xxx parseXxx (String);

here, Xxx represents fundamental data type.

Length is an implicit attribute created by JVM to determine number of elements or size of the array.

For example:

int a [] = {10, 20, 30, 40};
System.out.println (a. length); //4 
String s1 [] = {10, 20, 30};
System.out.println (s1.length); //3

class Data
{
	public static void main (String s [])
	{
		int noa=s.length;
		System.out.println ("NUMBER OF VALUES ="+noa);
		System.out.println (s [0] +s [1]);
		int x=Integer.parseInt (s [0]); //8 
		int y=Integer.parseInt (s [1]); //9 
		int z=x+y;
		System.out.println ("SUM ="+z);
	}
};
            

8 and 9 lines used for converting string into int data type.