Sunday, 27 December 2015

Click all linkspresent in a webpage

Click  all linkspresent in a webpage


private static String[] links = null;

private static int linksCount = 0;



@Test  

public void demo()

{
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com");
List<WebElement> linksize = driver.findElements(By.tagName("a"));
linksCount = linksize.size();
System.out.println("Total no of links Available: "+linksCount);
links= new String[linksCount];
System.out.println("List of links Available: ");
// print all the links from webpage
for(int i=0;i<linksCount;i++)
{
links[i] = linksize.get(i).getAttribute("href");
System.out.println(linksize.get(i).getAttribute("href"));
}
// navigate to each Link on the webpage
for(int i=0;i<linksCount;i++)
{
driver.navigate().to(links[i]);
Thread.sleep(5000);


driver.navigate().to("https://www.google.co.in");
}


Sunday, 26 April 2015

Maven Project

Steps to Start Maven Project


Step 1: Go to File options & New & other options




Step 2 : Click on "other.." u can see one child popup appear..inside u can see "Maven"  folder..expand ...





Step 3: Click on "Maven" Project & Click on Next



Step 4: One more window wil open click on Next



Step 5: once again one more window click on Next


Step 6: type Group Id & Artifact id- textbox give any name & click finish















































































Saturday, 25 April 2015

Maven Installation

Steps to Install Maven


Step 1: Go to Help in eclipse 




Step 2:click on Eclipse Marketplace




Step 3: Type in search as "Maven integration eclipse juno(your eclipse name which one u r using tat name u hve 2 mention)




Step 4: Click on Install..(takes 1hr or 30 min hardley to install.. Network should be gud thn only download fast..)





Step 5: Once download finish thn u can check whether downloaded or Not. 
1.Go to Eclipse 
2.Click File option 
3.Click new ...u see Custom Menu 
4.Go to "Others" options






5.It opens child popup.. Inside u can see "Maven" Folder



Thursday, 23 April 2015

Headless Browser(HtmlunitDriver)

If u r using Linux machine...use below code....other OS also u can use same code.....mostly working fine...check it once...


DesiredCapabilities cap=DesiredCapabilities.htmlUnit();
cap.setBrowserName("firefox");
cap.setPlatform(Platform.LINUX);
 
  HtmlUnitDriver driver=new HtmlUnitDriver(cap);
  driver.setJavascriptEnabled(true);
  Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
     
driver.get("http://arun-pc/login.do");

//print and check whether working or not
System.out.println("hi");

driver.findElement(By.name("username")).sendKeys("admin");

System.out.println("hi");

driver.findElement(By.name("pwd")).sendKeys("manager");

System.out.println("hi");

Monday, 20 April 2015

Java mock Questions

1. What is JDK?
2. Which is the latest Version of Java?
3. What is the Advantage of Java?

4. Javac and Java commands are available in which folder?
5. What is the signature of main method?
6. What is keyword?List some keywords
7. What is an identifier?
8. what are literals?
9. Java is Platform independent.Explain
10. What is JRE?
11. What is a Variable?
12. Mention all the primitive data types in java
13. What are primitive variables?
14. What are Reference Variables?
15. What is String in java?
16. What is a method?
17. General Syntax for a method?
18. What is Method Overloading?
19. Why Method Overloading?
20. What are members?
21. What are static members?
22. what are non static members?
23. List out the differences between static and non-static members?
24. what is an Object?
25. What is a class?
26. What are Global variables?
27. How can you access static global variable of a class?
28. How can you accesss non-static global variables of a class
29. what will be the default value for global variables?
30. What will be the default value for reference variables?
31. what is the default value for boolean variable?
32. What are the differences between local and global variable?
33. How can you declare constant variables in java?
34. can we just declare a final global variable?
35. What is an SIB?
36. When does SIB's get Executed?
37. How many times SIB's will be executed in one execution cycle?
38. What is an IIB?
39. When IIB's will be executed?
40. How many times IIB's will be executed in one execution cycle?
41. What does a method's return type signifies?
42. Can we Develop a method w/o return type?
43. What is call by value and call by reference?
44. What is a constructor?
45. What are two types of constructors?
46. What is a default constructor?
47. What is this() calling statement?
48. What is Recursion?
49. Recursion while constructor overloading will result in compile time or run time error
50. What is "this" keyword?
51. What is instance variable hiding?
52. What is the use of this Keyword?
53. What is Inheritance?
54. What are the different types of inheritance?
55. What is extends?
56. Does Java support multiple inheritance?
57. What is Diamond Problem?
58. Why Java Doesn’t support Multiple inheritance?
59. What is super() calling statement?
60. What is "super" keyword?
61. What is the difference between super() and this() calling statement?
62. what is the differnce between "super" and "this" keyword?
63. What is Method Overriding?
64. Can we Override static methods?
65. What is an abstract method?
66. What is an abstract class?
67. Can we instantiate an abstract class?
68. What is the rule to be followed by the sub class of an abstract class???
69. Can a abstarct class inherit from another abstract class
70. Is abstract class 100% abstract? Explain
71. What is an interface?
72. What is the difference between an abstract class and interface?
73. Does abstarct class have constructors? If Yes Why?
74. Does interfaces have constructors?
75. can we instantiate an interface?
76. What is implements keyword?
77. can an interface inherit from another interface?
78. What is casting?
79. what is primitive casting?
80. What is auto Widening and Explicit Narrowing?
81. What is derived or Object casting?
82. What is Auto Upcasting and Explicit Downcasting?
83. Can we Achieve Object casting Without inheritance?
84. Can we achieve downcasting without upcasting?
85. what is polymorphism?
86. Explain differernt types of polymorphism?
87. What is abstarction?
88. What are packages?
89. Why Packages?
90. What are the different access levels in java? Explain
91. What is SingleTon class?
92. What is encapsulation?
93. Which is the supermost class for all the classes in java?
94. Explain "toString()" of Object class
95. Explain "hashCode()" of Object class
96. Explain "equals()" of Object class
97. Can a subclass override all these above methods?
98. What is a final method in java?
99. What is a final class in java?
100. What is the use of finalize() method in java?
101. What is the use of clone() method?
102. What is a marker interface? Explain and mention atleast two available marker interface
103. Strings are immutable in java. Justify
104. Can we have inherit the String class. Justify
105. Explain the behavior of toString(),hashCode() and equals() method of string class
106. What is a String constant pool and non-constant pool?
107. What are arrays?
108. What is a primitive array?
109. What is a derived array?
110. What is Boxing and Unboxing?
111. What are Wrapper classes?
112. What is a collection API/Framework?
113. Explain List type of collection?
114. Explain Set Type of collection?
115. Explain Queue Type of collection?
116. list out the differences between List,Set and Queue type of collections? What are exceptions?
117. How to handle exception?
118. What is checked exceptions?
119. What are unchecked exceptions?
120. Differents ways of handling checked exceptions?
121. What is differece between final, finalize() and finally in java
122. How to Write the data into a text file?
123. How to read data from a text file?
124. What is the use of Scanner class in java?
125. How to read the String from the console?
126. What are Threads?
127. What is the use of sleep() method in Threads?
128. Can we develop final methods in interface?
129. can we develop a final abstract class?
130. can we develop a static method in abstract class?
131. can we just declare a variable in interface without initializing?

Sunday, 12 April 2015

TestNG- (NG)-Installation in Eclipse


How to add testNg in Eclipse

1.Go to Help 




2.Click on Eclipse Market Place u wil get popup below...



3.Type testng in Find search box ....enter..see below screen..




4.click on Install...it wil install under eclipse folder inside plugins folder u can see testng plugins...





5.Now u want add testng in yr project -Right click on yr project - see properties down screen



6.click properties u wil get one  child popup-click on Add Library



7.U can see one more popup with Testng option



8.Click on Next & Finish







9.U can  see Testng is added in Libraries below screen




10.click on ok-u can see inside yr project TestNG is added..




Friday, 27 March 2015

JAVA INTERVIEW PROGRAMS

duplicate string remover without using string method

 TreeSet<String>a=new TreeSet<String>();

a.add("a");
a.add("b");
a.add("d");
a.add("b");
a.add("d");
a.add("b");
a.add("b");


Iterator<String>t=a.iterator();

while(t.hasNext())
{
System.out.print(t.next());
}

duplicate String Finder  or Repating string character


  String t="BBbbnNNaill";
Multiset<Character>d=HashMultiset.create();
for(int i=0;i<t.length();i++)
   {
d.add(t.toLowerCase().charAt(i));
   }
for(Character ch:d.elementSet())
   {
System.out.println(ch+"----"+d.count(ch));
   }



repeating array INDEX(Number)using (Multiset)

int data[]={3,5,5,6,6,6,9}; Multiset<Integer>d=HashMultiset.create(); for(int i=0;i<data.length;i++) { d.add(data[i]); } for(Integer i:d.elementSet()) { System.out.println(i+"-------"+d.count(i)); }


Duplicate array Remover using for loop


String str[]={"3","2","3","2","1"}; for(int i=0;i<str.length-2;i++) { for(int j=i+1;j<str.length;j++) { if(str[i].equals(str[j])) { str[j]=""; } } } for(String s:str) { System.out.println(s); } }




Sort array  INDEX  using (Arrays)

   int  data[]={2,6,7,8,9};
Arrays.sort(data);
for(int c:data)
{
System.out.println(c);

}


Sort array  INDEX using --for loop



  int arr[]={20,40,50,30,10};
int temp=0;
for(int i=0;i<=(arr.length)-1;i++)
{
for(int j=0;j<=(arr.length)-1;j++)
{
if(arr[i]<arr[j])
{
temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
System.out.println("hh"+arr[j]);
}
}
}

for(int i=0;i<=(arr.length)-1;i++)
{

//for displaying the sorted array
System.out.println(arr[i]);
}

}



Sort String-- using (Arrays)

String data1[]={"b","c","j","a","d"}; Arrays.sort(data1); for(String c:data1) { System.out.println(c); }



//fibonaaci series int l=0; int j=1; for(int i=0;i<=5;i++) { l=l+j; j=l-j; System.out.println(l); }

//palindrom String t11="MAdam"; String nw=new StringBuilder(t11).reverse().toString(); if(t11.equals(nw)) { System.out.println("palidrom"); } else { System.out.println("NoT a Palindrom"); }


String Reverse (how is she - she is how)


String str = "He is the one"; String temp = ""; String finalString = ""; for(int i =str.length()-1;i>=0;i--){ temp +=i!=0?str.charAt(i):str.charAt(i)+" "; if(str.charAt(i) == ' '||i==0){ for(int j=temp.length()-1;j>=0;j--){ finalString += temp.charAt(j); } temp = ""; } } System.out.println(finalString);

SingleTon class example program


rules of singleton class

1.private constructor should be thr
2.static method should be thr
3.It returns an object which is already created


class singleton()
{
private Static singleton single=null;

//private constructor
private singleton()
{

}

//static method
public static singletongetInstance()
{
if(single==null)
{
single=new single();
}

//return obj which is created above same colour
return single;
}
}




Method over loading ......



 class test
  {
   public void A(char s)
   {
    System.out.println(s);
   }
   public void A(char s,int c)
   {
    System.out.println(c+"  "+s);
   }

  }
  class main
  {
   public static void main(String[] args)
   {
    test tt=new test();
    tt.A("arun");
    tt.A("arun", 10);
   }
  }

Method Override




class qpsider
{
   public void A()
   {
      System.out.println("Selenium");
   }
}
class java extends qspider
{
   public void A()
    {
      System.out.println("Webdriver");
    }
   public static void main( String args[])
   {
      java obj = new java();
      obj.eat();
   }
}


Upcasting



class Bike
{
void run()
{
System.out.println("running");} }
class Splender extends Bike
{ void run()
{
System.out.println("running safely with 60km");
} public static void main(String args[])

{  //upcasting
Bike b = new Splender(); b.run(); } }