Posts

Showing posts from February, 2020

Java Tutorial Series - Setters and 'this' Keyword

Now we have already understood the concept of getters in Java, we will be diving deep into the concepts of setters and 'this' keyword used in Java. Setters and 'this' keyword -  Consider below example where we are using getters, setters and 'this' keyword. class Frog { private String name; private String age; public void setAge(int age) { this.age = age; } public void setName(String Name) { this.name = name; } public String getName() { return name; } public int getAge() { return age; } public void setInfo(String name, int age) { setName(name); setAge(age); } } public class App { public static void main(String[] args) { Frog frog1 = new Frog(); frog1.setName("Charlie"); frog1.setAge(22); System.out.println(frog1.getName()); } }

Java Tutorial series - Getters and Return values

Following up with the Java Tutorial series, we will be covering Getters and return values in this post. By using Getters and return type we can implement Encapsulation, one class can use the methods and values from other class by not going in details, Let's see how it is implemented in the example given below - Getters and Return Values-  Getter always have a return type Getter will never have any parameters. class Person { String name; int age; int calculateYearsLeftToRetirement() { int yearleft  = 65 - age; return yearsleft; } int getAge() { return age; } String getName() { return name; } } public class App { public static void main(String[] args) { Person person1= new Person(); person1.name = "Joe" person1.age = 25; int age = person1.getAge(); String name = person1.getName(); System.out.println("Age is :"+ age); System.out.println( "Name is "+ name); }  

Java Tutorial series - Collections - Sorting Lists

By this time, we already know how to perform sorting operations in HashMap and Sets. Now, let's have a look at Sorting operations for LinkedList and ArrayList. It can be performed with the help of the Comparator. Sorting ArrayList in Alphabetical order - public class App {  public static void main(String[] args) { List<String> fruits = new ArrayList<String>(); fruits.add("Mango"); fruits.add("Watermelon"); fruits.add("Orange"); fruits.add("Apple"); fruits.add("Banana"); Collections.sort(fruits); for(String fruit: fruits) { System.out.println(fruit); }  } } The output of the above program - Apple Banana Mango Orange Watermelon Sorting ArrayList based on String Length using Comparator -  We will be taking similar example given above, after declaring the implementation, we have to add unimplemented methods from Comparator - Class StringLengthComparator implements Com

Java Tutorial Series - collections - Using Custom Objects in Sets and as Keys in Maps

By this tutorial you know already know the concepts of collections framework in Java - ArrayList, LinkedList, HashMap, LinkedHashMap, TreeHashMap, HashSet, LinkedHashSet, TreeSet. Now we will learn how to using custom objects in Sets and keys in maps. Please consider below piece of code for reference - Using Custom Objects in Sets and Keys in Maps -  public class Person { private int id ; private String name ; Person( int id , String name ) { this . id = id ; this . name = name ; } public String toString() { return ( " ïd : " + id + "Name :" + name ); } } public class App {                public static void main(String[] Args) { Person p1 = new Person(0,"Bob"); Person p2 = new Person(1,"Sue"); Person p3 = new Person(2,"Mike"); Person p4 = new Person(3,"Sue"); Map<  Person ,Integer> map = new HashMap<  Person , Integer>

Java Tutorial Series - Collections -Sets

Having covered ArrayList, LinkedList, HashMap, LinkedHashMap, TreeMap, we have come with another Collection called Sets. It is one of the dominant collection. Sets is a kind of collection that only stores unique elements. Syntax of Set Set<String> ele = new HashSet<String>(); ele.add("Apple"); ele.add("Banana"); ele.add("Orange"); ele.add("Watermelon"); ele.add("Grapes"); System.out.println(ele); //Output -  [Apple, Grapes, Watermelon, Orange, Banana] HashSet doesn't retain any order. LinkedHashSet remembers the order elements are inserted. TreeSet sorts the elements in natural order. How to iterate through each element in Sets using for each loop -  for (String element : ele) { System.out.println(element) ; } Another awesome feature of using Set is we can search for a particular element and perform some action, for example - If(ele.contains("Orange") { Sys

Java Tutorial Series - Collections - HashMap

In the series of Collection, we have already covered ArrayList, LinkedList, the difference between the two. Now we will be covering HashMap in this article. HashMap Syntax - HashMap<Integer,String> map = new Hashmap<Integer,String>(); map.put(5,"Five"); map.put(8,"Six"); map.put(4,"Four"); map.put("2","Two"); map.put("4","Hello"); String text = map.get(4); System.out.println(text) // will give output "Hello" For Loop for HashMap -  for(Map.Entry<Integer,String> entry: map.entrySet()) { int key = entry.getKey(); String value = entry.getValue(); System.out.println(key + ": " + value) ; HashMap doesn't maintain any order as you would be able to see from the output. To overcome this issue, LinkedHashMap comes into play which has the same syntax as of HashMap. Another way of using for loop in HashMap is shown below - for(String key:

Java Tutorial Series - Collections - LinkedList

We have already covered ArrayList topic from Collections in previous tutorial of Java series, in this article we will be covering LinkedList and its advantage over ArrayList. LinkedList Syntax -  To begin with the syntax of LinkedList, it can be defined the same way as that of ArrayList LinkedList<Integer> number = new LinkedList<Integer>(); OR List<Integer> number = new LinkedList<Integer>(); Advantage of LinkedList on ArrayList - LinkedList consists of elements where each element has a reference to the previous and next element. [0] -> [1] -> [2] If we want to add or remove the elements in beginning or the middle of the List, we would be using LinkedList instead of ArrayList since it is fast when adding elements in middle or the beginning. Contrary, if we want to add or remove the elements from the end, then ArrayList is most efficient option to do so and not the LinkedList. Adding to it, LinkedList is slower when traversi

Java Tutorial Series - Data Structures

Image
Data structures were introduced to manage the huge amount of java in an order. Choosing the appropriate Data structure is the most important and difficult part for any programmer.  Big corporate companies require candidates who are having extensive knowledge in data structures. Having said that, none of the interview completes without data structures principles asked. The Need of the Data structures - As the applications are getting complex and the data is increasing significantly, there may come a time where everyone can face below problems - Processor Speed - New processors are getting introduced in the market, consider an example of Smartphones which are having cutting-edge competition in bringing a new processor each and every 6 months in the year because of growing data. Data Search - Consider an example if you are searching for a friend's name in Facebook, how it's algorithm beings you the results out of like millions of its users in fractions of seconds, that

Python introduction - Tutorial 1

Python is burgeoning these days! We are covering a series of Python programming on our blog, will cover from basics to automating different applications in Python. Before we begin let's understand the basics first. What is a programming language? A programming language is written by human beings to perform some operation in an electronic machine. In other words, A programming language is a set of instructions that is given to a translator, where a translator can be Interpreter or Compiler. A Machine understands the binary language that is in the form of 0's and 1's. To convert the programming language into Binary language, either Interpreter or Compilers are used. Now, what is the basic difference between a compiler and an interpreter? - An Interpreter converts the programming language line by line, whereas compiler converts all at once. Which interpreter is good to use - Well, there are plenty of interpreters available both offline and online, we would recommend to

Response Codes in API Testing

While performing API testing we come across various response codes that have some hidden meaning and they defined the standard HTTP response codes. In this article, we will be looking at some of the response codes one must have some sound knowledge of - Response Codes in API Testing To Begin with, Response codes are basically divided in 5 categories and then subcategories - 1xx - Informational 2xx - Success 3xx - Redirection 4xx - Client error 5xx - Server error Having said that, now we will be adding subcategories below  - Informational -  100 - Continue Success -  200 - Ok 201 - Created 202 - Accepted 204 - No Content Redirection - 301 - Moved permanently 302 - Found 303 - See other 304 - Not modified 307 - Temporary redirect Client error - 400 - Bad Request 401 - Unauthorized 403 - Forbidden 404 - Not found 405- Method not allowed 406- Not acceptable 412-Precondition failed 415-Unsupported media type Server erro