Professional Documents
Culture Documents
ARRAYS
- Type of data structure that can store a fixed-size sequential collection of elements of the
same kind.
- An ordered collection of values having the same data type and contiguous memory
locations.
- Uses:
- Maintains large data under a single variable name.
- Used for easy sorting of data elements.
- For performing matrix operations.
- Used for CPU scheduling.
- Used to implement other data structures like Stacks, Queues, Heaps, Hash tables,
etc.
- ALWAYS SUB MINUS ONE. To avoid out of bounds, the elements must not exceed
the dimensions.
Practice:
String[] honNames; - Declaration
String[39] honNames; - Dimension
Value inside the square bracket is the element
honNames[0]
honNames[1]
.
.
.
honNames[38]
1. ONE/SINGLE-DIMENSIONAL ARRAY
- A linear array whose elements can be assessed individually by specifying the
index value of each element. [int, long int, float, double]
- Made up of one row/column of array members with the same name but different
index values.
dataType[] arrayName;
dataType arrayName[];
Strings - char: ‘ ‘ ; string of text: “ “
JAVA FUNCTIONS
- It is a container for a few lines of code that accomplish a specific task. A standard
feature in all programming languages. Also known as procedure or subroutine in other
programming languages.
- DRY (Don’t Repeat Yourself)
- To not be repetitive.
PREDEFINED FUNCTIONS
- Functions that are built into the language to perform operations are stored in the
Standard Function Library.
USER-DEFINED FUNCTIONS
- With no argument and no return value
- With no argument but a return value
- With argument but no return value
- With argument and a return value
Aspects of Function:
- Function Declaration
- Telling the compiler that this function exists and what its details are.
- A function must be declared to inform the compiler of the:
- Function Name - Used to call the function.
- Parameter List - The list of values that the function needs to receive.
- Return Type - The data type of the value to be returned by the function.
- Function Definition - Programming its behavior. Where we add the function’s body, the
code to be executed when we call the function.
- Contains the actual statements which are to be executed when the function is
called (or used).
- Function Call - The actual usage of the function from somewhere else, whether in the
main or inside other functions.
- To call a function, you simply need to pass the required parameters along with
the function name, and if the function returns a value, then you can store the
returned value.