Quick introduction to Java Programming language - Part 1
Chapters
Working with Arrays
Java supports data structure the array is used to stored fixed size collection of elements of same type. For Example if we need to store number from 1 to 10 instead of declaring individual variable we can declare one array variable having number from 1 to 10.
Declaring Array Variables:
To use an array in a program variable should be declared to reference the array and type of array should be mentioned.
dataType[] RefVararray;
double[] SalaryList;
Creating Arrays:
Array can be created by using new keyword.
RefVararray = new dataType[arraySize];
The above declaration does below things:
- Creates array using new dataType[arraySize];
- It assigns reference of newly created array to variable RefVararray.
int[] myUserList = new int[10];
The above statement creates an integer array myUserList with array of 10 elements. The index of the 10 elements will be from 0 to 9.
The Arrays Class:
The java.util.Arrays class contains few static methods for searching and sorting arrays, filling array and comparing arrays. These methods can be overloaded for all primitive types.
Methods with Description |
public static void sort(Object[] x) Sorts array of objects into ascending order. |
public static void fill(int[] x, intval) Assigns specified int value to each element of specified array of integer. |
public static boolean equals(long[] x1, long[] x2) if two specified arrays of longs are equal to one anothertrue is Returned |
public static intbinarySearch(Object[] x, Object key) Binary search algorithm is used to search the object in specified array. |
Processing Arrays:
For processing array elements for or foreach loop is used since all elements in the array are of same size and type.
public class ExampleArray { public static void main(String[] args) { int[] numList = {5,9,8,7}; for (inti = 0; i<numList.length; i++) { System.out.println(numList[i] + " "); } } }
Description
This tutorial is targetted for beginers seeking a quick get on with guide on Java programming language. 3 parts include
- Java basics
- Object oriented programming
- Advance concepts
Each part is subdivided in multiple chapters.
Java basics has the following chapters
- Introduction
- Environment Setup
- Basic Syntax
- Objects and Classes
- Basic Data Types
- Variable Types
- Modifier Types
- Basic Operators
- Loops
- Decision Making
- Numbers Class
- Character and String Class
- Arrays
- Date and Time
- Regular Expression
- Methods
- Streams, Files and I/O
- Exceptions Handling
Thanks for reading and as always, your feedback is very important to us. Let us know how we can improve and if you found any issues with this write up, send us a correction.
Audience
Beginners or students seeking a refresher on Java language
Author: Subject Coach
Added on: 9th Mar 2015
You must be logged in as Student to ask a Question.
None just yet!