The Java Programming Language offers great benefits to developers, software vendors, and tech-gadget manufacturers. Everything in the language is handled as an object that descends from the root object classes. Java also has a rich standard library. It has hundreds of methods and classes which are divided into six main functional areas: utility classes, language support classes, I/O Classes, networking classes, the Applet class, and the Abstract Window Toolkit.
When writing a program the first steps involves designing algorithms on how to tackle the problem at hand, one of these algorithms is subdividing the task into subtasks and subdividing these subtasks even further into smaller subtasks until they are trivial to execute in a programming language. Java facilitates a way to solve these subtasks, in other languages these are known as functions, procedures or modules in java they are referred to as Methods. They are like small programs which are combined to make up one large program. In these paper will explore some of java predefined methods and where possible show some examples
Use your promo and get a custom paper on
"Java Predefined Methods".
Predefined methods in java are organized in what is known as class libraries, each class library contains related methods and classes which are organized into packages
1 Class Character
Class character is contained in the package java.lang and includes the following methods for character
• Character.isUpperCase() – returns true if the character is in uppercase
• Character.isSpaceChar() – returns true if the character is a space.
• Character.isDigit() – checks if a character is a digit.
• Character.toLowerCase()- sets the given character to lowercase.
• Character.toUpperCase()-sets the given character to uppercase.
Example 1
char char1 = ‘G’, char2 = ‘7’;
boolean check;
check = Character.isUpperCase(char1); // ‘G’ is upper-case, so returns true
check = Character.isSpaceChar(char1); // a space char is ‘ ‘, so returns false
check = Character.isDigit(char2); // ‘7’ is a digit, so returns true
char char3;
char3= Character.toLowerCase(char1); // method returns ‘G’, received in ch3
char3= Character.toUpperCase(char1); // ch1 is already upper-case; ‘G’ is returned (as is)
In order to use the methods in a class one must import the package containing the class
2 The System Class
System class facilitates natives operating system functionality such as input, output and error streams for example System.currentTimeMillis() which retrieves the system clock as at January 1, 1970.
Other methods included in these are:
• getOSName()
• getenv(String var)
• exit(int exitCode)
3 The Locale Class [java.util library]
The locale class is used to produce objects according to geographical, political and cultural region, by default the location is provided by the operating system
Some of the methods in this class are:
• getAvailableLocales()
• getDisplayCountry()
• setDefault(loc_obj)
In conclusion, for software reusability, every method should be created to perform a single, well defined task, and a naming convention according to the method’s functionality should be observed.