Skip to main content

Posts

Showing posts with the label BASIC JAVA OVERVIEW

Java Exception : Exception Handling in Java

Java Exception :  Exception in Java can be defined as abnormal activity due to unwanted execution of code which should be avoided. But as we know writing too many complex logics can lead to execution of unwanted code and it can disrupt our normal flow.    To avoid such scenarios we have an option option called EXCEPTION HANDLING, by using EXCEPTION HANDLING we can make our execution normal in case of any disruption.   There are 2 ways to handle the exception. If we want the doubtful code which can throw exception and interrupt our execution flow , in this case we can use try and catch block and can do the required things and log the message that this hasn't work and can print the exact failure message with the help of stack trace. Let's understand with an example : below code is without Exception handling which will through Arithmetic exception. package C4CAMPUS ; public class ExceptionExample { public static void main (String args[]){ int a = 10 ; int

Java Program : Writing First Java Factorial Program with explanation

 NAMING CONVENTION IN JAVA : Java is an object oriented programming language , we can relate it to real life object like i mapped Java with human in my previous post JAVA OVERVIEW (SESSION 1)  and represent human properties like body parts as properties in Java and Human can dance , drive , walk , run these can be mapped as Behaviour in java.    Now To represent properties and behaviour in java , there are some standard naming conventions we should follow. Class name should always starts with Uppercase letter like class Student { //Code to be executed } Properties or any kind of variables should starts from lower case and afterwards every first letter of each next word should be in Upper case . like class Student { int studentId ; String studentName ; //Code to be executed } Methods name should also starts from lower case and afterwards every first letter of each next word should be in Upper case . like class Student { int studentId ; String studentName ;

Java Loop Tutorial

 JAVA LOOPS  :   Loops means multiple time execution of same code written inside loop blocks. Now let's understand first FOR LOOP 1. FOR LOOP  : FOR LOOP will have 3 things. Start index A terminator condition  Increment flag. if loop start index is 1 and terminator condition is index should be less than 10 and start index incremented by 1 , then code inside loop brackets will be executed 9 times. if loop start index is 1 and terminator condition is index should be less than 10 and start index incremented by 2 , then code inside loop brackets will be executed 4 times. As mentioned FOR LOOP has three parts , start index , terminator condition and incremental value . Example :  for(int i=0 ; i < 10 ; i++ ){   // Code to be executed  } All this three operator = , < and ++ already explained in my previous post JAVA OPERATORS Please go through it if you have confusion to understand. And how this for loop is getting started and executing only till terminator condition. Java

Java Operator Tutorial

 JAVA OPERATOR  : Operator are among core concept of writing logical condition and business logic in any programming language . Simplest operators are Arithmetic Operator which we all know :  +     : Addition -     : Subtraction  *    : Multiplication  /     : Division  % : Remainder Now next is Assignment operator   = : To assign any value to any reference name of any type we use this = operator . What is variable in java already explained in my previous post JAVA BASIC OVERVIEW Example:  int input1 = 10;  String name = "My name is John Cena"; Along with this operator we can add Arithmetic Operator  to make assignment  simple  Example : For int input1 = input1 + 10 ; it can be simplified by using combination of Addition and equal to operator like  int input1 += 10;   this is same as input1= input1 + 10 ;   Same way we can simplified for Subtraction, Multiplication , Division and Remainder like : -= , *= , /= , %= Relational Operator , mainly used in case of com

Java Primitive Data types & Wrapper Class Tutorial

 JAVA PRIMITIVE TYPES AND WRAPPER CLASSES : Object class, which is stored in the java. lang package is ultimate super class of all classes. and below are the methods of Object class it means behaviour of Object class as mentioned in my previous post. Just know these methods will be more useful as we will go more deeper. Object getClass(). : returns Class class object int  hashCode() : returns the hashcode number for object being used. boolean equals(Object obj) : compares the argument object to calling object. Object clone() :  Creates copy of invoking object String  toString() : returns the string representation of invoking object void  notify() : wakes up a thread, waiting on invoking object's monitor. void  notifyAll() : wakes up all the threads, waiting on invoking object's monitor. void  wait() : causes the current thread to wait, until another thread notifies. void  wait(long,int) : causes the current thread to wait for the specified milliseconds and nanosecon

Java Overview : Basic Java Overview

  JAVA BASIC OVERVIEW :  Java is high-level, class-based, robust, platform independent and object oriented programming language. Here each keyword has specific meaning which we need to understand.     How java internally works and execute our logic ?    We will need to write a file with extension .java, in which we will be writing our logics to be executed and this should be inside a class because java starts from main method of any class which is public inside the file named same as class name.    Example :  public class FirstJavaProgram {      public static void main(String[] args) {      //our logics      } }   This code should be saved in a file named as  FirstJavaProgram.java Whenever we are writing a java class, it's basically a blue print of what class has and it can do, it means characteristics  and behaviour , just like a simple real life object like human, a human has many characteristics  and behaviours , so in java we can map char