Wednesday, 14 September 2016

Java Collections

import java.util.*;



public class CollectionsDemo {


public static void main(String args[])
{

List a= new ArrayList();
a.add("sri");
a.add("sahi");
a.add("teju");
System.out.print("Array : ");
System.out.print("\t"+a);



List l=new LinkedList();
l.add("nokia");
l.add("apple");
l.add("samsung");
System.out.println();
System.out.print("Linked list: ");
System.out.print("\t"+l);

Set s=new HashSet();
s.add("banana");
s.add("orange");
s.add("lemon");
System.out.println();
System.out.print("Set: ");
System.out.print("\t"+s);


Map m=new HashMap();
m.put("java", 1);
m.put("ruby",5);
m.put("html", 9);
System.out.println();
System.out.print("Map: ");
System.out.print("\t"+m);


}

}


==================================================================

Monday, 12 September 2016

Java IO operations

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyFile {

public static void main(String args[]) throws IOException {
FileInputStream in = null;
FileOutputStream out = null;

try {

in = new FileInputStream("D:/Java/MyJava/src/input.txt");
out = new FileOutputStream("D:/Java/MyJava/src/output.txt");

int c;

while ((c = in.read()) != -1) {
out.write(c);

}

} finally {

if (in != null) {
in.close();

}
if (out != null) {
out.close();

}

}

}
}


-----------------------------------------------------------------------------------------------


import java.io.*;


public class CopyFile{


public static void main(String args[])throws IOException {


FileReader in =null;
FileWriter out =null;


try{
   in = new FileReader("D:/Java/MyJava/input.txt");
   out = new FileWriter("D:/Java/MyJava/output.txt");
 
   int c;
 
   while((c= in.read())!=-1)
   {
    out.write(c);
   
   
   }
 
 
}
 finally{
 if(in!=null)
 {
in.close();
 }

 if(out!=null)
 {
out.close();

 }


 }



}



}

--------------------------------------------------------------------------------------------------



Tuesday, 6 September 2016

Accessing Godday Mysql database remotely in windows cmd

First create Database and user name in Mysql database wizard in godaddy


--------------------------------------------------------------------------------
=>

1) First go to mysql folder in  cmd (directory) in windows

C:> mysqld  --console

-> It runs the mysql server

2) open another cmd

-------------------------------------------------------------------------------

1) login with root and enter passwor



-> mysql -u root --password
 -> 1234


2)

GRANT ALL PRIVILEGES ON *.* TO  'USERNAME'@'IP'  IDENTIFIED  BY  'PASSWORD';



here user name is -> ex(srini_user)
here IP is ->  Mysql server IP address  ex(166.62.28.109)

3)

'USERNAME' is the username to be created.
'IP' is the public IP address of the remote connection.
'PASSWORD' is the password to be assigned for this username.
(IP can be replaced with % to allow this user to logon from any host or IP)
mysql> FLUSH PRIVILEGES;
mysql> exit;

-------------------------------------------------------


1)  


mysql -u srini_user -p -h 166.62.28.109


------------------------------------------------------------------------------------------
It displays the  follwing....


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20869966
Server version: 5.5.49-cll-lve MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

> mysql



------------------------------------------------------------------------------------

mysql> show databases;

Connection id:    20877375
Current database: *** NONE ***

+--------------------+
| Database           |
+--------------------+
| information_schema |
| srini_db           |
+--------------------+
2 rows in set (0.71 sec)


---------------------------------------------------








Tuesday, 30 August 2016

JUnit test cases

----------------------------------------------------------------------------------------

public class junitTest {

private String msg;
public junitTest(String msg)
{
this.msg=msg;
}

    public String printmsg()
    {
    System.out.println(msg);
    return msg;
    }
 
}
-----------------------------------------------------------------------------------


import static org.junit.Assert.*;

import org.junit.Test;




public class junitTestTest {
    
String msg="sree";
junitTest obj = new junitTest(msg);
@Test
public void testing()
{
assertEquals(msg,obj.printmsg());
}
}

=============================================================


public class MyClass {

  public int multiply(int x ,int y)

  {
  if(x>10)
  throw new IllegalArgumentException("x should be less than 10");
 
  return x*y;
 
  }
}


-------------------------------------------------------------------------------

import static org.junit.Assert.*;
import org.junit.Test;


public class MyClassTest {


@Test
  public void TestMultiply()
{
 
  MyClass test = new MyClass();
     System.out.println(test.multiply(2,3));
     assertEquals(45,test.multiply(5,9));
   
 
}  

}

=======================================================





Monday, 29 August 2016

Java.util Package Classes

Java.util.ArrayList



======================================================================

import java.util.ArrayList;



public class arrayList {


public static void main(String args[])
{
ArrayList<String> mylist= new ArrayList<String>();
mylist.add("sree");
mylist.add("krishna");
for(String str:mylist)
System.out.println(str);
}
}

======================================================================

import java.util.ArrayList;


class arrayList{
public static void main(String args[])
{
        ArrayList<Integer> mylist= new ArrayList<Integer>();
        mylist.add(9);
        mylist.add(6);
        mylist.add(1);
        
            for(int x:mylist)
        System.out.println(x);
}
}

======================================================================

import java.util.ArrayList;

class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist = new ArrayList<Integer>(5);
mylist.add(1);
mylist.add(2);
mylist.add(4);
mylist.add(5);
for(int x:mylist)
System.out.println(x);
System.out.println("===========");
mylist.add(2,3);  //index starts from zer0
for(int x: mylist)
System.out.println(x);
}
 
}

======================================================================




import java.util.ArrayList;

class arrayList{
public static void main(String args[])
{
ArrayList<Integer> list1= new ArrayList<Integer>(5);
list1.add(1);
list1.add(2);
list1.add(3);
for(Integer x: list1)
System.out.println(x);
      System.out.println("===============");
      
      
      
   
      
   ArrayList<Integer> list2 =new ArrayList<Integer>(5);
   list2.add(4);
   list2.add(5);
   list2.add(6);
   
   
      
   
   for(Integer y:list2)
    System.out.println(y);
   System.out.println("===============");
   list1.addAll(list2);
   for(Integer x: list1)
System.out.println(x);
      System.out.println("===============");
      for(Integer y:list2)
    System.out.println(y);
   System.out.println("===============");
   
}

}




======================================================================



import java.util.ArrayList;

class arrayList{
public static void main(String args[])
{
ArrayList<Integer> list1= new ArrayList<Integer>(5);
list1.add(1);
list1.add(5);
list1.add(6);
for(Integer x: list1)
System.out.println(x);
      System.out.println("===============");
      
      
      
   
      
   ArrayList<Integer> list2 =new ArrayList<Integer>(5);
   list2.add(2);
   list2.add(3);
   list2.add(4);
   
   
      
   
   for(Integer y:list2)
    System.out.println(y);
   System.out.println("===============");
   list1.addAll(1,list2);
   
   for(Integer y:list1)
    System.out.println(y);
   System.out.println("===============");
   
}

}


======================================================================

import java.util.ArrayList;

public class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist = new ArrayList<Integer>();
 
mylist.add(2);
mylist.add(5);
mylist.add(6);
System.out.println("size of the list: "+mylist.size());
mylist.clear();
System.out.println("size of the list: "+mylist.size());

}
}

======================================================================
import java.util.ArrayList;

public class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist =new ArrayList<Integer>(5);
mylist.add(5);
mylist.add(9);
mylist.add(21);
boolean isThere;
isThere=mylist.contains(9);
System.out.println(isThere);
}
}



======================================================================

import java.util.ArrayList;

public class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist =new ArrayList<Integer>(5);
mylist.add(5);
mylist.add(9);
mylist.add(21);
mylist.add(34);
boolean isThere;
isThere=mylist.contains(9);
System.out.println(isThere);
System.out.println(mylist.size());
  int res=mylist.get(2);
  System.out.println("res: "+res);
}
}


======================================================================
import java.util.ArrayList;

public class arrayList{
public static void main(String args[])
{
ArrayList<String> mylist = new ArrayList<String>(5);
mylist.add("a");
mylist.add("b");
mylist.add("c");
mylist.add("d");
int res= mylist.indexOf("b");
System.out.println(res);
}

}



======================================================================

import java.util.ArrayList;

public class arrayList{
public static void main(String args[])
{
ArrayList<String> mylist = new ArrayList<String>(5);
mylist.add("a");
mylist.add("b");
mylist.add("c");
mylist.add("d");
mylist.add("c");
mylist.add("b");
mylist.add("c");
mylist.add("d");
int res= mylist.indexOf("b");
System.out.println(res);
boolean isEmpty;
isEmpty = mylist.isEmpty();
System.out.println(isEmpty);
for(String x:mylist)
System.out.println(x);
        int lastIndex;
lastIndex=mylist.lastIndexOf("c");
System.out.println(lastIndex);
}

}


======================================================================
import java.util.ArrayList;

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

ArrayList<Integer> mylist =new ArrayList<Integer>(5);
mylist.add(5);
mylist.add(9);
mylist.add(4);
System.out.println("size of the list: "+mylist.size());
for(Integer x: mylist)
{ System.out.print(x);System.out.print(",");
}    
mylist.remove(1);
System.out.println("size of the list: "+mylist.size());
for(Integer x: mylist)
{ System.out.print(x);System.out.print(",");
}    

}

}


======================================================================

java.util.HashMap



import java.util.HashMap;

public class hashMap {


public static void main(String args[])
{
HashMap mymap = new HashMap();

mymap.put(1, "apple");
mymap.put(2, "samsung");
mymap.put(3,"nokia");

System.out.println(mymap);

mymap.clear();

System.out.println(mymap);

}


}


======================================================================
import java.util.HashMap;

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

    HashMap mymap = new HashMap();
    HashMap secnd = new HashMap();
 
     mymap.put(1, "english");
     mymap.put(2, "hindi");
     mymap.put(3, "telugu");
   
     System.out.println(mymap);
 
       secnd=(HashMap)mymap.clone();
   
      System.out.println(secnd);

}

}


======================================================================

import java.util.HashMap;

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

    HashMap mymap = new HashMap();

 
     mymap.put(1, "english");
     mymap.put(2, "hindi");
     mymap.put(3, "telugu");
     mymap.put(5, "");
   
      System.out.println(mymap.containsKey(2));  //checks if key present
      System.out.println(mymap.containsValue("hindi"));  // checks if value present
   
   
   
   
   
 

}

}


======================================================================
import java.util.HashMap;
import java.util.Set;


public class hashMap{


public static void main(String args[])
{

HashMap test =new HashMap();

test.put(1, "C");
test.put(2, "c++");
test.put(3,"Java");

  Set myset=test.entrySet();

  System.out.println(myset);   //entry set
   
  System.out.println(test);    // printing normal map


}



}



======================================================================



======================================================================




======================================================================


======================================================================




======================================================================












Java.util Package Classes

Java.util.ArrayList



======================================================================

import java.util.ArrayList;



public class arrayList {


public static void main(String args[])
{
ArrayList<String> mylist= new ArrayList<String>();
mylist.add("sree");
mylist.add("krishna");
for(String str:mylist)
System.out.println(str);
}
}

======================================================================

import java.util.ArrayList;


class arrayList{
public static void main(String args[])
{
        ArrayList<Integer> mylist= new ArrayList<Integer>();
        mylist.add(9);
        mylist.add(6);
        mylist.add(1);
        
            for(int x:mylist)
        System.out.println(x);
}
}

======================================================================

import java.util.ArrayList;

class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist = new ArrayList<Integer>(5);
mylist.add(1);
mylist.add(2);
mylist.add(4);
mylist.add(5);
for(int x:mylist)
System.out.println(x);
System.out.println("===========");
mylist.add(2,3);  //index starts from zer0
for(int x: mylist)
System.out.println(x);
}
 
}

======================================================================




import java.util.ArrayList;

class arrayList{
public static void main(String args[])
{
ArrayList<Integer> list1= new ArrayList<Integer>(5);
list1.add(1);
list1.add(2);
list1.add(3);
for(Integer x: list1)
System.out.println(x);
      System.out.println("===============");
      
      
      
   
      
   ArrayList<Integer> list2 =new ArrayList<Integer>(5);
   list2.add(4);
   list2.add(5);
   list2.add(6);
   
   
      
   
   for(Integer y:list2)
    System.out.println(y);
   System.out.println("===============");
   list1.addAll(list2);
   for(Integer x: list1)
System.out.println(x);
      System.out.println("===============");
      for(Integer y:list2)
    System.out.println(y);
   System.out.println("===============");
   
}

}




======================================================================



import java.util.ArrayList;

class arrayList{
public static void main(String args[])
{
ArrayList<Integer> list1= new ArrayList<Integer>(5);
list1.add(1);
list1.add(5);
list1.add(6);
for(Integer x: list1)
System.out.println(x);
      System.out.println("===============");
      
      
      
   
      
   ArrayList<Integer> list2 =new ArrayList<Integer>(5);
   list2.add(2);
   list2.add(3);
   list2.add(4);
   
   
      
   
   for(Integer y:list2)
    System.out.println(y);
   System.out.println("===============");
   list1.addAll(1,list2);
   
   for(Integer y:list1)
    System.out.println(y);
   System.out.println("===============");
   
}

}


======================================================================

import java.util.ArrayList;

public class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist = new ArrayList<Integer>();
 
mylist.add(2);
mylist.add(5);
mylist.add(6);
System.out.println("size of the list: "+mylist.size());
mylist.clear();
System.out.println("size of the list: "+mylist.size());

}
}

======================================================================
import java.util.ArrayList;

public class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist =new ArrayList<Integer>(5);
mylist.add(5);
mylist.add(9);
mylist.add(21);
boolean isThere;
isThere=mylist.contains(9);
System.out.println(isThere);
}
}



======================================================================

import java.util.ArrayList;

public class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist =new ArrayList<Integer>(5);
mylist.add(5);
mylist.add(9);
mylist.add(21);
mylist.add(34);
boolean isThere;
isThere=mylist.contains(9);
System.out.println(isThere);
System.out.println(mylist.size());
  int res=mylist.get(2);
  System.out.println("res: "+res);
}
}


======================================================================
import java.util.ArrayList;

public class arrayList{
public static void main(String args[])
{
ArrayList<String> mylist = new ArrayList<String>(5);
mylist.add("a");
mylist.add("b");
mylist.add("c");
mylist.add("d");
int res= mylist.indexOf("b");
System.out.println(res);
}

}



======================================================================

import java.util.ArrayList;

public class arrayList{
public static void main(String args[])
{
ArrayList<String> mylist = new ArrayList<String>(5);
mylist.add("a");
mylist.add("b");
mylist.add("c");
mylist.add("d");
mylist.add("c");
mylist.add("b");
mylist.add("c");
mylist.add("d");
int res= mylist.indexOf("b");
System.out.println(res);
boolean isEmpty;
isEmpty = mylist.isEmpty();
System.out.println(isEmpty);
for(String x:mylist)
System.out.println(x);
        int lastIndex;
lastIndex=mylist.lastIndexOf("c");
System.out.println(lastIndex);
}

}


======================================================================
import java.util.ArrayList;

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

ArrayList<Integer> mylist =new ArrayList<Integer>(5);
mylist.add(5);
mylist.add(9);
mylist.add(4);
System.out.println("size of the list: "+mylist.size());
for(Integer x: mylist)
{ System.out.print(x);System.out.print(",");
}    
mylist.remove(1);
System.out.println("size of the list: "+mylist.size());
for(Integer x: mylist)
{ System.out.print(x);System.out.print(",");
}    

}

}


======================================================================

java.util.HashMap



import java.util.HashMap;

public class hashMap {


public static void main(String args[])
{
HashMap mymap = new HashMap();

mymap.put(1, "apple");
mymap.put(2, "samsung");
mymap.put(3,"nokia");

System.out.println(mymap);

mymap.clear();

System.out.println(mymap);

}


}


======================================================================
import java.util.HashMap;

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

    HashMap mymap = new HashMap();
    HashMap secnd = new HashMap();
   
     mymap.put(1, "english");
     mymap.put(2, "hindi");
     mymap.put(3, "telugu");
   
     System.out.println(mymap);
 
       secnd=(HashMap)mymap.clone();
     
      System.out.println(secnd);

}

}


======================================================================

import java.util.HashMap;

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

    HashMap mymap = new HashMap();

   
     mymap.put(1, "english");
     mymap.put(2, "hindi");
     mymap.put(3, "telugu");
     mymap.put(5, "");
   
      System.out.println(mymap.containsKey(2));  //checks if key present
      System.out.println(mymap.containsValue("hindi"));  // checks if value present
     
     
   
   
   
   

}

}


======================================================================




======================================================================













Wednesday, 24 August 2016

Java methods

1)


-----------------------------------------------------------------


public class Employee {

String name;
int age;
String desg;
double sal;

   
public Employee(String name)
{
this.name=name;

}
public void empAge(int age)
{
this.age=age;
}

public void empDesg(String desg)
{
this.desg=desg;

}

  public void empSal(double sal)
  {
  this.sal=sal;

  }


void printEmployee()
{
System.out.println("Name : "+name);
System.out.println("Age : "+age);
System.out.println("Desg : "+desg);
System.out.println("Salary : "+sal);

}




}

------------------------------------------------------------



public class EmployeeTest{

public static void main(String args[])
{

Employee empOne=new Employee("sree");

empOne.empAge(24);
empOne.empDesg("developer");
empOne.empSal(11280.50);
empOne.printEmployee();

Employee empTwo=new Employee("krishna");

empTwo.empAge(21);
empTwo.empDesg("soft developer");
empTwo.empSal(11580);
empTwo.printEmployee();

}



}



----------------------------------------------------------------------------------------------------------------------

2)


public class FindMin {

public static void main(String args[])
{
int a,b,c;
a=5;
b=9;
c=minfn(a,b);
System.out.println("in main:"+c);

}

public static int minfn(int x, int y)
{
int min;
if (x>y)
min =y;
else min=x;
System.out.println(min);
return min;

}


}


--------------------------------------------------------------------------------------------------------------


3)



public class methodOver {

public static void main(String args[])
{
int a=3,b=4;

double c=1.3,d=3.5;


int res=minfn(a,b);

double resy=minfn(c,d);

System.out.println("int:"+res);
System.out.println("double: "+resy);
}
 public static int minfn(int x,int y)
  {
 int min;
 if (x>y)
 min=y;
 else min=x;
 
 return min;
 
  }

public static double minfn(double a,double b)
{
double min;
  //a>b?min=b:min=a;
if(a>b)
min=b;
else min=a;
return min;
}
}


-------------------------------------------------------------------------------------------

4)