Posts

Scanner class in JAVA

Image
Scanner class is used to take input from the user in java. It has many different methods to handle other task too. To use Scanner class you have to use  import java.util.Scanner;   then you have to create an object of Scanner class. After creating an object, you can use the scanner object to store variables from user. When user gives input it stores in it and later on we can assign the value in variable for further use. let't see one example of Scanner class. Here, how to calculate Simple Interest is displayed. Source code... package oop; import java.util.Scanner; public class ScannerDemo { // Scanner is a class, located inside java.util package // Scanner is used to take input from user in console public static void main(String[] args) { int t; double p, r; double si; Scanner in = new Scanner(System.in); System.out.println("Principle amount:"); p = in.nextDouble(); System.out.println("Enter rate:"); r = in.nextDouble(); System.o...

Logical operator in JAVA

Image
 Logical operators are widely used in decision making in JAVA. The Operators are used to check the given condition or expression whether they are true or false. Mostly logical operators are used to check condition if there are two or more expression and whether the expressions(two or more expressions) are returning true or not. There are three logical operator i.e. AND Operator (&&), OR Operator (||) and NOT Operator (!). Lets see below example to explore it in more convenient way.  Let's suppose we are making console application based voting system. The criteria are defined below. 1)Must be citizen of some regulatory body, lets assume Nepal. At first he or she must have proof that he       or  she crossed 16 and has citizenship card. Then only the persoin is known as citizen.  1) Must have crossed age 18. (Age defined he or she is eligible for vote or not). 2) Must have Voting Card. If all the condition is satisfied then he or she is elig...

Relational Operator in JAVA

 https://youtu.be/rSTNMxkBQgQ

Assignment Operator In JAVA

Image
This video depicts what is assignment operator and how to work with assignment operator. 

Arithmetic Operator in JAVA

 There are different types of operators in java programming language. one of them is arithmetic operator. Arithmetic operators are used to do arithmetic operations in java. The sign used on arithmetic operation are listed below. 1) Addition +  2) Subtraction - 3) Division / 4) Multiplication * 5) Modulo % ( It gives reminder after division) Example below displays the source code of performing arithmetic operation.  package operators; public class ArithmeticOperators { // basically there are 5 types of arithmetic operator // 1) addition + // 2) Subtraction - // 3) multiplication * // 4) division / // 5) modulo % public static void main(String[] args) { int a = 10; int b = 22; // lets do addition first System.out.println("Total sum = " + (a + b)); // subtraction System.out.println("b - a = " + (b - a)); // multiplication System.out.println("a * b = " + (a * b)); // division System.out.println("a / a = " +...

Install JDK on your computer

Image
   Install JDK in your computer Learning java as a programming language is better for beginners. Java is very popular programming language in the world. It is simple to learn and it has many advantages. Java is object oriented programming language. Java code is, "write once and read many times" format. When any software is developed in java, it runs in any environment. It has features like platform independent, secure, multithreading, memory allocation and many more. In this blog, how to install Java Development Kit (JDK) in your windows machine is shown. Steps      1) go to your browser and type "download JDK" and hit enter.     2) Click on Download JDK and click on download according to your operating system.      3) Install JDK      4) Go to installation folder of JDK          > C drive, OS installed drive > program files > java > jdk-15.0.1 > bin         ...

Tic Tac Toe Game in JAVA

Long time ago I read that learning programming is so fun, if you didn't find learning programming fun then you must not interested or your teacher don't know how to teach the programming. There is also written that the programming teacher must be working on industry so that he/she could be able to teach you the way how to overcome the programming obstacles. At the beginning phase of studying programming language, I used to worry about what if i couldn't able to write the code clearly and understandable. I always used to worry about it. But one day my facilitator said that now you are developing your career in software industry. Don't ever worry about the clear code. Just you do mistake as many times as it takes to get the task done. Then after the task is done, be clear what you did, what you learned from mistakes and what problem is solved. Then always make a habit of writing comment in the source code. There are a lot of things that he told us, these are few.  At...

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=cu...

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. ...

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 declar...

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...

Advance Java Application

/* Write a program in Java that takes two integer input from user then add them both and displays the output.*/ import java.util.Scanner; //program uses class scanner public class Calculator{           public static void main(String[ ] args)           {                int ,a,b,total;                 //create an Scanner object to read input from user.                 Scanner input =new Scanner(System.in);                              System.out.println("Enter first number:");                a=input.nextInt(); //read first number                 System.out.println("Enter second number:");                b=input.nextI...

First Program in Java

// WAP in Java that prints Hello World. public class HelloWorld{           public static void main(String[ ] args){                     System.out.print("Hello, World !!!!!!");           } } In above ( // ) sign represent a comment in a program. What ever we write after ( // ) symbol, it is ignored while the process is compiled. Symbol ( // ) is use to comment a single line and ( /*..........*/ ) and this symbol is used to comment a multiple lines in program. Writing a comment in the program is good habit of a programmer. It helps other programmer to read and understand the program. // WAP in Java that prints Hello World.  Note:- this line will be ignored by the compiler while compiling the process. -------------------------------------------------------------------------------------------------------------------------- // WAP in Java that prints Hello World. public ...

Primitive Data types in Java

Java programming language is very strong language. In java, all the variables and objects must have an explicit defined data type. The main role of this type is to tell the compiler that how much memory is needed to store the value of variable. In java we found that there are 2 types of data types. 1) Primitive data types. 2) Reference data types. Primitive data types are name of reserved keywords. It is special data type built into the java language. The memory space is already allocated when the variables of primitive data types are created. But in reference data types, memory space has to be allocated using the new keywords. Java supports eight primitive datatypes. They are:- Data type                     Description                              Size/Format                             ...