Friday, 29 December 2017

4.1 Object Oriented Programming (OOPS Concept)

Class and Object Any entity that has state and behavior is known as an object. For example: table, book , building, pen etc. It can be physical and logical. The class defines the structure of an object. It is a blueprint. In java this blueprint is called a class. And every object have some behaviour and attributes. Attributes are data members such as variables. Behaviour is the member functions...
Read More »

3.3 Different ways of declaring main method

public static void main(String[] args) static public void main(String[] args) static public void main(String []args) public static void main(String args[]) public static void main(String... args) public static synchronized void main(String... args) public static strictfp void main(String... args) public static final void main(String... args) Important points about main method. ...
Read More »

3.2 Var args [Variable Arguments]

Variable Arguments - These are used when you don't know the exact number of arguments to be used in your method...
Read More »

3.1 Array

Array - An array is the collection of similar kind of element stored in a single variable. example int A[3] = {1,2,3} Array index start with 0. If you try to store/print value outside the index size, you'll get ArrayIndexOutOfBoundsException. 1. Single dimensional array int a[] = {1 , 2, 3, 4, 5, 6};            1 2 3 4 5 6 2. 2 D Array        ...
Read More »

Thursday, 28 December 2017

2.6 Basic Program for Practice

1. Palindrome class palindrome { public static void main(String args[]) { int r,sum=0,temp;     int n=12321;//It is the number variable to be checked for palindrome      temp=n;     while(n>0) {     r=n%10;  //getting remainder   sum=(sum*10)+r;     n=n/10;     }       if(temp==sum)        System.out.println("palindrome...
Read More »

2.5 Patterns printing

1. Logic to print different patterns is first loop will decide the number of rows Second loop will decide the number of columns you have to manipulate the second loop logic to get the desired pattern. public class Pattern {         public static void main(String[] args)  {                //Pattern1        ...
Read More »

2.4 For, While, Do While loop and Break statement

Loops normally use to do a repeated task by avoiding the duplicate work. All the looping control statements are easy and you can use any of them as per your understanding. class Loop { public static void main(String args[]) { //for loop for(int i=1;i<=10;i++) { System.out.println(i); } //While loop int j=1; while(j<=10) { System.out.println(j); j++; } //Do while //This loop will run at least once and  //then it will check for...
Read More »

2.3 Switch Case

Switch case in java is used when you have to use multiple if else statements. class SwitchCase { public static void main(String args[]) { int n=4; switch(n) { case 1: System.out.println("One"); break; case 2: System.out.println("Two"); break; case 4: System.out.println("Four"); break; default: System.out.println("Some number"); } // if you not use break then all the out statement after the case match will print // Switch case can...
Read More »

2.2 Trick in Java

1. Hello World without main method. This was possible before 1.7. Logic behind this is , Static block executes before main method. It will compile but it will not run in 1.7 and above. to make it run you must have a main class class Trick1 {     static {         System.out.println("Hello World");         System.exit(0);     }    ...
Read More »

2.1 If Else and Ternary operator

Below is the example of even odd , Biggest number and ternary operator. class IfElse { public static void main(String args[]) { //If else int a=5; if(a%2==0) { System.out.println("Even"); } else { System.out.println("Odd"); }    //if else if int p=4; int q=9; int r=2; if (p>q && p>r) { System.out.println(p+" is greater than "+q+" and "+r); } else if (q>p && q>r ) { System.out.println(q+" is greater...
Read More »

1.5 Operators

1. Short Hand Operators += , -=, *=,  /= int a=4; a+=1; //a=a+1 short hand operator example System.out.println(a); 2. Binary Literals  To print binary to decimal we can use "0b" or "0B" int n= 0b1001; int n= 0B1001; underscore is introduced in java 7 3. Pre-increment and Post-increment int i=5; i=i++;  Here i++ means temp=i and increment i=temp and increment value...
Read More »

Wednesday, 27 December 2017

1.4 Additional Knowledge

1. Class name can be different as the file name. class A{     public static void main(String args[])     {          System.out.println("Test");     } } Save it as B.java after compiling B.java  -----  javac B.java you'll get a class file with name A.class. To run this code you have to write java A instead of java B. 2. Comments /* Multiple line comments Multiple line comments */ // Single line comment 3. Concatenation...
Read More »

1.3 Variables and Datatype

Variable : A variable is a named storage location where you can store different values. Primitive variables : int, float, double, long, char , byte , boolean  Datatype : Type of data store in a variable is called datatype You can't store large value in small variable. Different types of variable with their size and default values class Add { public static void main(String...
Read More »

1.2 - First program in Java

Download JDK (Java Development Kit from oracle official website) NOTE : Start working in Notepad . It will help you to memorize the syntax easily. class HelloWorld { public static void main(String args[]) { System.out.println("Hello World"); } } ...
Read More »

1.1 History of Java

Java developed by Sun microsystem which lead by Mr. James Gosling. The motive to develop java is to create something which is platform independent. Initially it is developed for electronic appliances like set top boxes and called as "GREEN TALK". later it is known as "Oak(1991)" Java got patent in 1993 and later launched its first version in 1995. The main feature of this programming language...
Read More »
Page 1 of 23123...23Next »Last