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

Contents

JAVA
1) Introduction to collections

2) Overview on Collections ?

3) What are the key interfaces in java ? 

4) What is Array List ? 

5) What is Vector ?

6) What are differences between ArrayList and Vector ?

7) What is LinkedList ?

8) What is Hash Map ?

9)  What is Interface?

10) what is Abstract Class ?

11) What are the different Types of Blocks available in java ?

12) What is @Override annotation in java ?

13) What is @SuppressWarnings annotation in java ?

14) Verify List is sorted or not in java ?

15) What is String Tokenizer in java ?

16) Strings in java ?

17) String Methods in Java ?

18) What is String Buffer in java ?

19) What is String Builder in java ?

20) Difference between StringBuffer and Stringbuilder ?

21) toString() in java ?

22) What are Cursors in java ?

23) What is Enumeration in java ?

24) What is Iterator in java ?

25) What is List Iterator in java ?

26) What is Multi threading in java ?

27) Difference between start() and run() in java ?

28) What is synchronized in java ?

29) What is HashSet in java ?

30) What is Linked Hashset in java ?

31) What is sortedSet in java ? 

32) What are Objects in Java ?

33) this keyword in Java ?

34) What is Constructor ?

35) What is Parameterized Constructor ?

36) What is Method Overloading ?

37) What is Static Keyword ?

38) What are the types of variables?

39) System.getenv() in Java?

40) How to pass arguments to Java programs?

41) How to get a number of files in a directory?

42) How to filter files in a directory?

43) How to Read a number of rows from files?

44) How to Read a number of rows from Multiple Excel Files?























































54) Strong Number
SELENIUM

1) What is Selenium ?

2) Locators in selenium and preferences ? 

3) How to make vedio of selenium scenario ?

4) How to use JavaScript using selenium ?

5) How Interfaces implemented in Selenium Webdriver ?

6) Different ways to handle Window Handles in selenium ?

7) How to Read Data from JSON file ?

8) How to Select last option in drop down using selenium ?

9) How to Kill opened browsers using selenium ?


CUCUMBER WITH JAVA
1) What is Cucumber ?

2) What are the Layers of cucumber ?

3) What is Gherkin ?

4) What is Cucumber junit runner Class ?

5) What is Cucumber Hooks?

6) What is Cucumber monochrome?

7) What are Cucumber Tags?

8) What are Cucumber plugins?

9) What is Cucumber dryRun?

10) How to Run cucumber scenario using Line Number?

11) What is Background in Cucumber?

12) What is Scenario Outline in Cucumber?

13) What are the methods available for Cucumber Scenario?

14) How to use getName() method in Cucumber?

15) How to use getId() method in cucumber?

16) How to use getUri() method in cucumber?

17) How to use getLine() method in cucumber?

18) How to use isFailed() method in cucumber?

19) How to use getSourceTagNames() method in cucumber?

20) What are the dependencies required for the cucumber framework?

21) Cucumber Data tables?















































PYTHON





















Please comment below to feedback or ask questions.

Parent p=new Child() parent and child object reference in java

Parent p=new Child() ?

  • By using parent reference, we can call only methods available in parent class and we can't call child specific methods.
  • we can use parent reference to hold any child class object.

class Parent {
int duplicateVariable = 10;
String parentString = "parent string value";

Parent() {
System.out.println("parent Constructor");
}

public void duplicate_method() {
System.out.println("duplicate method in Parent class");
}

public void parentMethod() {
System.out.println("Parent method");
}
}

class Child extends Parent {
int duplicateVariable = 20;
String childString = "child string value";

Child() {
System.out.println("child Constructor");
}

public void duplicate_method() {
System.out.println("duplicate method in child class");
}

public void childMethod() {
System.out.println("child method");
}
}

public class ParentChildProgram {
public static void main(String[] args) {
Parent parentObj = new Child();
System.out.println("Value=" + parentObj.duplicateVariable);// variable in parent class invoked
parentObj.duplicate_method();// duplicate method in child class is invoked
parentObj.parentMethod();
System.out.println(parentObj.parentString);
}
}
Output:
Parent p=new Child()
Parent p=new Child()

  • If we use parent reference to call specific child class specific methods we will get compile time error like below:
Parent P = new Child() compile time error
Parent P = new Child() compile time error

Child c=new Child() ?
  • By using child reference we can call both parent and class methods.
  • We can use child reference to hold only for that particular child class object only.
class Parent {
int duplicateVariable = 10;
String parentString = "parent string value";

Parent() {
System.out.println("parent Constructor");
}

public void duplicate_method() {
System.out.println("duplicate method in Parent class");
}

public void parentMethod() {
System.out.println("Parent method");
}
}
class Child extends Parent {
int duplicateVariable = 20;
String childString = "child string value";

Child() {
System.out.println("child Constructor");
}

public void duplicate_method() {
System.out.println("duplicate method in child class");
}

public void childMethod() {
System.out.println("child method");
}
}
public class ParentChildProgram {
public static void main(String[] args) {
Child childObj = new Child();
System.out.println("Value=" + childObj.duplicateVariable);// variable in child class invoked
childObj.duplicate_method();// duplicate method in child class is invoked
childObj.parentMethod();
childObj.childMethod();
System.out.println(childObj.parentString);
System.out.println(childObj.childString);
}
}
Output:
Child c=new Child()
Child c=new Child()

Please comment below to feedback or ask questions.

java8 features

Java 8 features

Below are new features that are introduced in Java 8 :
  1. Lambda expression
  2. Functional Interface
  3. Default Methods and static methods
  4. Predefined Functional interfaces (Predicate, Functional, Consumer, supplier, etc.,.)
  5. Double colon operator(::), Method reference, constructor reference
  6. Streams
  7. Date and Time API
  8. Optional class
  9. nashorn JavaScript engine
  10. StringJoiner
  11. Collectors class etc.,.

Lambda expression::
  • It is an anonymous function i.e., a lambda expression is Nameless, without return type, without modifiers.
  • It brings the benefits of functional programming into Java.
  • Lambda expression can implement an interface that contains a Single Abstract Method(SAM.)
  • Click here for details
Functional Interface::
  • Interface which contains SAM(Single Abstract Method) is called Functional Interface
  • It also contains Any number of default methods and static methods
  • In order to invoke lambda expression, we require a Functional Interface.
Default Methods:
  • Until Java 1.7, Every method present inside the interface is always public and abstract
  • In Java 1.8V, default methods and static methods are allowed
  • In Java 1.9V, private methods are allowed
Static Methods:
  • From Java 1.8, the interface can contain static methods.
  • We should call static methods in the interface by using its interface name only.
  • static methods in an interface are by default not available to implementation classes. So we have to call by using interface name only.


Verify the display of element which disappear immediately in protractor

Verify the display of element which disappear immediately in protractor ?

describe('Protractor - Verify the display of element which disappear immediately in protractor', function () {
beforeAll(async function () {
await browser.get("https://keeplearners.blogspot.com/2018/03/Angular-elements.html");
});

it('Verify the display of element which disappear immediately in protractor', async function () {
verifyBlinkMessage(2000, 0, "className");
});

function verifyBlinkMessage(totalCount, currentCount, className) {
if (currentCount < totalCount) {
return browser.executeScript("return document.getElementsByClassName('" + className + "').length").then(function (value) {
if (value > 0) {
console.log("Element displayed=" + value);
return browser.executeScript("return document.getElementsByClassName('" + className + "')[0].innerText").then(function (textPopUp) {
console.log("pop up message=" + textPopUp);
return textPopUp;
// return true;
});
} else {
console.log("Page is loading....");
return verifyBlinkMessage(totalCount, currentCount++, className);
}
});
} else {
throw new Error("element not present after Max count" + totalCount + "ms reached.")
// return false; //if element not present after Max count reached.
}
}
});
Verify the display of element which disappear immediately in protractor

Please comment below to feedback or ask questions.

Sum of individual digits of a number

Sum of individual digits of a number

  • We can find the sum of individual digits of a given number using loop , java 8 etc.,.

public class SumOfDigits {
public static void main(String[] args) {
int number = 111111;
int p;
int sum = 0;
while (number != 0) {
p = number % 10;
sum = sum + p;
number = number / 10;
}
System.out.println("sum of individual digits of given number=" + sum);


int n = 123;

//sum of individual digits of given number using java 8
int sumOfDigits = String.valueOf(n).chars().map(Character::getNumericValue).sum();
System.out.println("sum of individual digits of given number using map=" + sumOfDigits);

}
}
Output:
Sum of individual digits of a number
Sum of individual digits of a number
Please comment below to feedback or ask questions.

valueOf() in java ?

valueOf() in Java ?

  • valueOf() method will convert any type(int,float,char etc.,.) of data into a string.

##Demo program on valueOf()###
public class valueOf {
public static void main(String[] args) {
int i = 10;
System.out.println(i + 20);
String IntTostr = String.valueOf(i);
System.out.println(IntTostr + 20);
System.out.println("Type=" + IntTostr.getClass());

System.out.println("<<---------------------------------------->>");
boolean v = false;
String BooleanTostr = String.valueOf(v);
System.out.println("boolean to string=" + BooleanTostr);
System.out.println("Type=" + BooleanTostr.getClass());

System.out.println("<<---------------------------------------->>");
char c = 'L';
String CharTostr = String.valueOf(c);
System.out.println("char to string=" + CharTostr);
System.out.println("Type=" + CharTostr.getClass());

System.out.println("<<---------------------------------------->>");
float f = 10.2f;
String floatTostr = String.valueOf(f);
System.out.println("float to string=" + floatTostr);
System.out.println("Type=" + floatTostr.getClass());


System.out.println("<<---------------------------------------->>");
char[] carr = { 'A', 'B', 'C', 'D' };
String charArrToStr = String.valueOf(carr);
System.out.println("char array to string=" + charArrToStr);
System.out.println("Type=" + charArrToStr.getClass());


System.out.println("<<---------------------------------------->>");
Object o=12;
String objectTostr = String.valueOf(o);
System.out.println("Object to string=" + objectTostr);
System.out.println("Type=" + objectTostr.getClass());

}
}
Output:
valueOf() in java
Please comment below to feedback or ask questions.