Posts

Showing posts from November, 2017

Simple Bank Application in Java console

Image
Before you start to work, you should know about the classes and object. Here, we are going to make a simple Bank Application in java console. Here we can find two objects i.e. bankAccount and customer. Bank Account has account number, customer , balance etc and Customer has name, address, contact etc.  Now, Here we made BankAccount class which have attributes like account number, customer, balance. Here, customer is an object because customer has also name, address, contact etc. Another class named Customer and attributes are name and address. Again another class we made BankApplication in which we have implemented main method.  The code of Bank Account has shown below:- public class BankAccount { //attributes //the attributes must be in private because in a bank there are many customers; private int acc_no; private Customer customer; private float balance; BankAccount(int custAcc_no, Customer cust, float deposit){ this.acc_no=custAcc_no; this.customer=cust; th

Class and Object in Java

To understand the Class and Object in java, first you simply you imagine the real world. Suppose you have a house. In house we stay, before we stay we build a house. Before we build house, we design it. We make a sketch or blue print of that house. In that sketch we determine structure of house in form of architectural drawing. We all know that we can't stay in that architectural drawing. We have to built a house to stay in it. Here, class is like a sketch and the object is house. \ A class is like the architectural drawing of a house from which the house object is built.  Just as you can’t stay in an architectural drawing of a house, you cannot ‘stay’ in a class.  Just as someone has to build a house from its architectural drawing before you can  actually stay in it, you must build an object of a class before you can get a program to  perform the tasks defined in the class. In a housing estate, there are many houses built  from the same architectural design. Each of these houses

Array in Java

Array is a collection of similar types of multiple data. In java variable and object are of single space which means only one value can be stored at a time. If  we have to store more than one value than multiple variables have to assigned which is so boaring and consume more time to assign. So, to overcome the problem all most of programming language use array data structure. Array can store multiple data in a single variable. Each of the space that hold the value is known as element and these elements are arranged in next to one another in contiguous area of memory space. So, we can easily access the elements by assigning the numerical index to the main reference point. In java, the index starts from  0. So the the index of element is 0. example:- int[] a={1,2,3,4,5}; here, a[0]=1; a[1]=2 and so on. Declaration of array we generally declare array variable to use same type of data. Secondly we can declare array object also. Java treat array as an object. When we declare an arra

Loop Structure

Image
It is aslo known as repetitive structure. Loop structure is used to run the block of codes until the condition is satisfied. While in execution, the if the condition is true then it is executed if the condition is false then the loop is terminated and follows the next statement of loop. Loop structure continue to execute until the condition is satisfied and it is very useful in many areas because of this feature.  In java programming language, there are three options to use repetitive structure. 1) ' while ' statement 2)' do-while' statement 3)' for ' statement 1)'while' statement In while statement, certain code of block runs which is inside the while loop structure until the condition becomes false. After being the condition false, the loop will terminate itself. Syntax:- while(<condition expression>) {      //program code } 2)'do-while '  statement It is also a type of statement. In this type of structure, while exp

Decision making Structure

Decision Making Structure:- It is very common control flow statement in order to apply different conditions to program. If the condition is true, the statements that comes after the condition will be executed. In java there are 4 types of decision making structure. They are: 1)The 'if' statement 2) The 'if-else' statement 3)The 'nested if-else statement 4)The 'switch' statement 1) The 'if' statement if statement is the most basic decision making structure. This statement tells the computer system to execute the certain block of code  only if the condition id true. If the certain code is not true then it skips that code and starts to execute next block of code. Syntax:- if(<conditional expression>) {   //Block of code executes if the condition is true. } for example :- if(a>b) {       System.out.println("largest number is: "+a); } 2)The 'if-else' statement It is same as if statement. if statements ru