Skip to main content

Java Beginner Tutorials


Slide Chapter 1 Complex Control Structure

Slide Chapter 2 Java Method

Example Method 1 – Min, Max, Average of 3 numbers

//  Demonstrates the use of methods in Java.

import java.util.Scanner;

public class MinOfThree
   //  Reads three integers from the user and determines the smallest
   //  value.
   public static void main (String[] args)
      int num1, num2, num3, min = 0, max=0;
      float average;

      Scanner scan = new Scanner (;


      System.out.println ("Enter three integers: ");
      num1 = scan.nextInt();
      num2 = scan.nextInt();
      num3 = scan.nextInt();

      //min=minimum(num1, num2, num3);
      System.out.println ("Minimum value: " + minimum(num1, num2, num3));

      //call maximum method
      max=maximum(num1, num2, num3);
      System.out.println ("Maximum value: " + max);

      //call average method
      findaverage(num1, num2, num3);

   }//end main

   public void findaverage(int num1, int num2, int num3){
      float average=(num1+num2+num3)/3;
      System.out.println ("Average value: " + average);

   public static void  displayinfo(){
      System.out.println ("************************************");
      System.out.println ("A Program to find min and max number");
      System.out.println ("Author:");
      System.out.println ("************************************");
   }//end displayinfo

   public static int minimum(int num1, int num2, int num3){
         int min;
         if (num1 < num2){
         if (num1 < num3)
            min = num1;
            min = num3;
         if (num2 < num3)
            min = num2;
            min = num3;
      return min;

   }//end minimum

   public static int maximum(int num1, int num2, int num3){
         int max;
         if (num1 > num2)
         if (num1 > num3)
            max = num1;
            max = num3;
         if (num2 > num3)
            max = num2;
            max = num3;
      return max;

}//end class

Example Method 2 – Grade Method

import java.util.Scanner;

public class grademethod
   public static void main (String[] args)
      Scanner scan = new Scanner (;
      System.out.println ("Enter your score: ");
      float score = scan.nextInt();
      //call printGrade here

   }//end main

   //Call the printGrade method from main
    public static void printGrade(double score) {
        if (score >= 90.0)
        else if (score >= 80.0)
        else if (score >= 70.0)
        else if (score >= 60.0)
  }//end printGrade
}//end class

Slide Chapter 3 Arrays in Java

Sample 1:

public class AverageArray {

    public static void main(String[] args) {
        //int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10;
        //int[] num = new int[10];
        int num[]={23,34,13,12,32,10,11,31,45,67};
        float total=0,average;
        //float average=(num1+num2+num3+num4+num5+num6+num7+num8+num9+num10)10;
        for (int i=0; i<10;i++){


        //Exercise: List all values that bigger than the average
        for (int i=0; i<10;i++){
            if (num[i]>average){
                System.out.println(num[i]+" is bigger than average");

    }//end main


Exercise 1: Get 15 numbers from user, and store the values inside an array variable. Evaluate the biggest and smallest number among the values.

Slide Chapter 4 Class in Java

Slide Chapter 5 File IO in Java

Example: Class and Method


//the file name is
public class MidsemAverageArray {

    private static double[] num = new double[10];
    private static double total_val=0, average_val;
    private static DataInputStream io=new DataInputStream(;

    //method to receive 10 numbers from the user2
    public static void input10num() throws IOException{
        for(int i=0; i<10; i++){
            System.out.println("Input number "+(i+1));

    //method to calculate the sum of numbers
    public static void calculate_total(){
        //use for loop to receive sum the 10 numbers from the array
        //store the sum in total_val
        for(int i=0; i<10; i++){

    //method to calculate the average of numbers
    public static void calculate_average(){
        //calculate the average of the 10 numbers
        //store the sum in average_val

    //main method
    public static void main(String[] args) throws IOException {
        //display the program name and what it does
        //call method input10num()
        //call method calculate_total()
        //display the sum of the 10 numbers
        System.out.println("Sum of 10 numbers= "+total_val);
        //call method calculate_average()
        //display the average of the 10 numbers
        System.out.println("Average of 10 numbers= "+average_val);

        //initiate class MinMax and declare mm object
        MinMax mm = new MinMax();
        double min_val = mm.min(num);
        System.out.println("Min among 10 numbers= "+min_val);
        double max_val = mm.max(num);


class MinMax {

    public MinMax() {

    public double min(double num[]){
        double min_process=num[0];
        for(int i=0; i<10; i++){
            if (num[i]<min_process){
        return min_process;

    public double max(double num[]){

        return 0;


Found this website and has a easy, simple Java Tutorial, thanks to the author.

Install Java The first step to programming Java is to get it running on your computer. This easy-to-follow guide will show you how to set up Java and Eclipse, complete with screenshots to help you follow along.

Your First Program Got Java and Eclipse installed? Let's make sure everything is set up properly and begin your introduction to Java by starting you with coding your very first program!

Java Output Learn how to easily get Java to display text on the screen. It'll be your proof that you can make a computer do what YOU want it to do!

Java Variables Without variables, there's no way to store values in your program. Learn the basics about creating and using Java's variables so your programs can do more than just display stuff on the screen.

Java Input Want to make your programs interactive? Learning to get input from a user is crucial if your program will ever be used by a human. Java has an easy way of doing this, and that's by using a Java Scanner.

Conditionals ( The If Statement ) Your program is doomed to do exact same thing every time it runs unless you let it know about different conditions. Learn the power of if statements and how to use them to produce different results based on what you tell the code to do.

Loops - For Loops And While Loops If you've been trying out your own programs, you must be getting fed up with having to copy and paste code you want done over and over again. But, there is a better way! Read on to learn how you can make a program do something over and over without having to write it over and over.

Intro To Java Methods The final tutorial in Java For Beginners! Learn a little bit about what Java methods are, how to write them, and how to use them. This tutorial won't cover everything, but it'll be just enough to get you to use them and serves as a jump-off point to the more advanced tutorials.

The tools

1. JDK - download here.
2. Eclipse IDE - download here.


Popular posts from this blog

Several English proverbs and the Malay pair

Or you could download here for the Malay proverbs app – English proverbs and the Malay pair Corpus Reference: Amir Muslim, 2009. Peribahasa dan ungkapan Inggeris-Melayu. DBP, Kuala Lumpur CTRL+F to search Proverbs in English Definition in English Similar Malay Proverbs Definition in Malay 1 Where there is a country, there are people. A country must have people. Ada air adalah ikan. Ada negeri adalah rakyatnya. 2 Dry bread at home is better than roast meat home's the best hujan emas di negeri orang,hujan batu di negeri sendiri Betapa baik pun tempat orang, baik lagi tempat sendiri. 3 There's no accounting for tastes We can't assume that every people have a same feel Kepala sama hitam hati lain-lain. Dalam kehidupan ini, setiap insan berbeza cara, kesukaan, perangai, tabia

WebDev PHP DEVELOPMENT TOOLS Download the XAMPP latest version from . This installation file contains the Apache web server, PHP 5 and 4 interpreter, and the MySQL 5 Community edition. - download latest version MozillaFireFox (OpenSource web browser firefox) – download latest version Google Chrome – fastest web browser on earcth – fast download chrome here TEACHING PLAN Download the teaching plan here for Web/Internet Programming ( download ) NOTES HTML references HTML Editor - Lab 1: HTML Basics - Lab 2: Responsive Design: Lab 3: HTML Forms Lab 4: HTML 5 Lab 5: Bootstrap for responsive Web -

Contact Us at

Powered by EMF HTML Contact Form

Bootstrap Template for PHP database system - MyCompanyHR

HTML without framework is dull. Doing hard-coded CSS and JS are quite difficult with no promising result on cross platform compatibility. So I decided to explore BootStrap as they said it is the most popular web framework. What is BootStrap? - Bootstrap is the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first web sites. (   ) Available here - Why you need Flat-UI? Seems like a beautiful theme to make my site look professional. Anyway you could get variety of BootStrap theme out there, feel free to select here Flat-UI is from DesignModo - Web Programming MyCompanyHR – PHP & MySQL mini project (with Boostrap HTML framework) Template 1: Template for the Lab Exercise. This is a project sample of a staff record management system. It has the PHP structured co

Login JSON Android using Login Activity

I’ve been trying to release this tutorial quite a while. At last after a long hard effort. Since HttpClient is not supported any more in Android SDK 23, I have to resort to org.json.JSONObject and library to do online database with JSON. The objective of this tutorial is to log-in from a mobile client with the username and password stored in an online database facility. STEP 1: Create a new Android project, this time choose the LoginActivity .