Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

OOPS-Object Oriented Programming System




JAVA: 

        Java language is based on  Object oriented programming.Means in java we will be dealing with Class and Objects.


Principles of Java:

  1. Objects
  2. Class
  3. Encapsulation
  4. Abstraction
  5. Polymorphism
  6. Inheritance

0

Basics of Java Programming


Java Program Contains:

Java Program mainly contains 7 parts:
  1. Package declaration
  2. Import Statements
  3. Class declaration
  4. Variable declaration
  5. Constructor declaration
  6. Method declaration
  7. Static blocks.

Package Declaration:


0

Pyramid Pattern in Java


Example:



package patterns;

public class pyramid {
public static void main(String[] args) {


int spacecounter=4,starcounter=1;
for(int i=1;i<=5;i++)
{
System.out.println();
for(int j=1;j<=spacecounter;j++)
{
System.out.print(" ");
}

for(int k=1;k<=starcounter;k++)
{
System.out.print("*");
}

spacecounter--;
starcounter=starcounter+2;
}

}

}

Output:


     *
   ***
  *****
 *******
*********




0

Finding Largest,Second Largest,Lowest Number in ArrayList




Example:

package largestnumber;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Scanner;

import org.apache.commons.collections.IteratorUtils;

public class highestnumber {

public static void main(String[] args) {
int i = 0;

ArrayList<Integer> arraylist = new ArrayList<>();
Scanner s = new Scanner(System.in);
System.out.println("Enter size of array:");
int n = s.nextInt();

System.out.println("You have to enter  " + (n - i) + " values:");
for (; i < n; i++)
 {
arraylist.add(s.nextInt());

}

Collections.sort(arraylist);
System.out.println("All Elements in the Array List are: " +arraylist);
System.out.println("Lowest Number in the  Array is:"
+ arraylist.get(0));
System.out.println("Second Largest Number in the Array is: "
+ arraylist.get(arraylist.size() - 2));
System.out.println("Largest Number in the Array is: "
+ arraylist.get(arraylist.size() - 1));

}

}


Output:

Enter size of array:
5
You have to enter  5 values:
3452
7865
9783
1748
9934

All Elements in the Array List are: [1748, 3452, 7865, 9783, 9934]
Lowest Number in the  Array is:1748
Second Largest Number in the Array is: 9783
Largest Number in the Array is: 9934


0

Pattern Example in Java :Pattern2




Pattern Design Format in Java


Example: 

0

Pattern Example in Java


Patterns Designing in Java Programming Most Easy Way To Design Pattern .















Example:

0

Armstrong number using java









An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 153 is an Armstrong number since 1*1*1+ 5*5*5 + 3*3*3=153 .
Example:

import java.util.Scanner;

public class Amstrong 
    {


 public static void main(String[] args) 
           {

0

Prime Number or Not using Java

Prime Number or Not using Java

A prime number is a naturalnumber greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number.
1

Factorial Number Using Java


Factorial means multiplying the given number by decreasingly value by 1.
0

palindrome Number in Java







Palindrome Means is a word ,number,etc.which  reads the same backward and forward.

Ex:   "151"  is palindrome.after reversing number we are getting same number.so It's a palindrome                number.

         "152" is not palindrome.


Example:
0

Regular Expression in Java

Regular Expression in java are very important because when we are using strings then it conatins numbers,characters,special chracters etc. so by using this regular expression we can easily can extract the things from the string whatever we needed.

Ex:   String s =  "This is $100 Dollars % * ^";


  1.    To extract '$' from the string can be done using regular expressions.
  2.    To extract '100' from the String .
  3.    Only to get characters.
  4.    Excluding the spacing in the above string.
0

Extracting only characters from the string contains both integer and characters

Extracting only Non Digit By Excluding Integers


Example:

0

Extract Integer from a String using java

Extracting Only Integers From the String

Example:

0

Data Types




Data Types:dd 
          
                    Data type means it represents which type of value to store in a variable.In java programming we are data types like int,char,float,double,short,string,boolean.


















Example:

0

Abstract class

Abstract Class:
                       
                      A class which is declared abstract  then that class is abstract class.Abstract class can have both abstract method and non abstract method.



Step1: Created an abstract class
0

Interface

Interface:

            An interface contains only abstract methods. All methods are incomplete.

ex:
           Interface i
         {
               public abstract void test();

         }

   In above example we have one method "test" but
0

Wrapper Classes in Java



Wrapper Class:

In wrapper class we have Objects which stores primitive data type or which wraps primitive data types.

Advantages:


  1. We cannot pass Primitive data type data between two application over the Internet.So Wrapper class needed in that case.
  2. When we send data to server then the server expects data to be in object format rather than primitive type of data.
  3. Objects in wrapper class can hold primitive data types.

    Syntax:

                    Integer  i = new Integer(123);
                    Float f = new Float(45f);

same for the  remaining wrapper classes.


Primitive Data Types
Wrapper Classes

int
Integer
byte
Byte
char
Character
short
Short
long
Long
float
Float
double
Double
boolean
Boolean


Wrapper  classes have boxing and unboxing.


Boxing:

          boxing means converting primitive data type to objects is boxing. 

 Ex:
                    int i=10;   // primitive type
           

               Integer obj=new Integer(i);   //coverting to objects
          

                System.out.println(obj);


Output:

           10


UnBoxing:

              unboxing means converting objects to corresponding primitive data type is unboxing.

Ex:


               int i=10;   // primitive type
           

               Integer obj=new Integer(i);   //coverting to objects

                int  j = obj.intValue();  //converting to primitive type:unboxing
   

                System.out.println(j);

Output:

          10















0

Reverse String in Java



public class reverseString
{


public static void main(String[] args)
{


String original="java";
String reverse="";

int length=original.length();

for(int i=length-1;i>=0;i--)
{
reverse=reverse+original.charAt(i);
}

System.out.println(reverse);




 }
}

Output:

avaj
0

DoWhile


public class dowhileconcepts {


public static void main(String[] args) {
int i=1;
do
{
System.out.println(i);//first print i =1
i++;                            //then increment
}while(i<=10);                  //checking for condition. loop continue until condition fails.
}
}

Output:

1
2
3
4
5
6
7
8
9
10
0

Character Array to String

public class stringexp1 {


public static void main(String[] args) {


char arr[]={'J','A','V','A'};

String s=new String(arr,0,4);

System.out.println(s);
}

}

Output:

JAVA
0