Learn Java programming very fast and easily with Javaistic.

A Java Programming learning website packed with information and programs ranging from basics , arrays , string programs to 2D arrays , recursion , matrices and many more.

class BinarySearch {
	int binarySearch(int arr[], int l, int r, int x)
	{
		if (r >= l) {
			int mid = l + (r - l) / 2;

      if (arr[mid] == x)
				return mid;

      if (arr[mid] > x)
				return binarySearch(arr, l, mid - 1, x);
      
			return binarySearch(arr, mid + 1, r, x);
		}
		return -1;
	}
	public static void main(String args[])
	{
		BinarySearch ob = new BinarySearch();
		int arr[] = { 2, 3, 4, 10, 40 };
		int n = arr.length;
		int x = 10;
		int result = ob.binarySearch(arr, 0, n - 1, x);
		if (result == -1)
			System.out.println("Element not present");
		else
			System.out.println("Element found at index " + result);
	}
}

Output

  • Element to Search : 3

  • Element found at index : 1

Why Javaistic?

Our docs are designed to make learning Java easy and fun.

Javaistic Docs

Quality over quantity

We value creating high quality, 100% free Java education. Beautifully designed and well written Java Docs which is very easy to understand.

Coding is fun

Start coding immediately, or go through our step by step explanation of programs.

Javaistic Programs
Javaistic Open Source On GitHub

Open to anyone. Fork it, twist it. Flip it.

Join the community and help us build the best open source Java learning site for everyone.

  • Talk is cheap. Show me the code.

    Linus Trovalds
    Linus Trovalds
    Creator of Linux
  • The people who are crazy enough to think they can change the world are the ones who do.

    Steve Jobs
    Steve Jobs
    Founder @ Apple Inc.
  • I choose a lazy person to do a hard job. Because a lazy person will find a easy way to do it.

    Bill Gates
    Bill Gates
    Founder @ Microsoft Inc.
  • Everything that has not been hyperlinked will soon be hyperlinked.

    Guillermo Rauch
    Guillermo Rauch
    Founder @ Vercel.
  • Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

    Martin Fowler
    Martin Fowler
    Programmer
  • Truth can only be found in one place: the code.

    Robert C. Martin
    Robert C. Martin
    Clean Code: A Handbook of Agile Software Craftsmanship
  • Java is to JavaScript what car is to Carpet.

    Chris Heilmann
    Chris Heilmann
    Programmer
  • Code is like humor. When you have to explain it, it’s bad.

    Corey House
    Corey House
    Founder @ ReactJS Consulting

Support Javaistic 💖

Our maintainers devote their time, effort, and heart to ensure Javaistic keeps getting better. Support us by donating to our collective 🙏

Open Collective

Sponsor the Javaistic maintainers

GitHub Sponsors

Sponsor the Javaistic maintainers on GitHub