Friday, 17 April 2020

SE - 54 - Types of repositories in Maven

There are basically 3 types of repositories in Maven :

1) Local Repository : Local repository is created in .m2 folder

2) Central Repository : Maven central repository is located on the web. It has been created by the apache maven community itself.

3) Remote Repository : Maven remote repository is located on the web. Most of libraries can be missing from the central repository such as JBoss library etc, so we need to define remote repository in pom.xml file.

SE - 53 - DryRun in CucumberOptions

Dryrun is an option present in CucumberOptions  which is used to check cucumber feature files and step definitions corresponding to it. It does not do actual execution rater it just checks the settings and configurations. Syntax Below :

@CucumberOptions(
  features = "Feature"
  ,dryRun = true
  )

dryRun accepts values as true and false . If set to true it will check the step definitions against each step of feature file.

Thursday, 16 April 2020

SE - 52 - Primitive Vs non-Primitive data types

In Java data-types are divided into 2 sections : Primitive and non-Primitive data types

Primitive data-types : 
A primitive data type specifies the size and type of variable values, and it has no additional methods. It doesn't references a object or we need not to create a new object for primitive data types.
There are 8 primitive data types :

  • byte
  • short
  • int
  • long
  • double
  • float
  • char
  • boolean

Non-Primitive data types :
Non-primitive data types are also called reference types as they refer to a object. They are not predefined as Primitive ones. Eg : String , Array , Class, Interface , etc



Note :
String is a special type of non-primitive data type in which we can use without creating object too.


Difference :

1. Primitive types are predefined (already defined) in Java having fixed size. Non-primitive types are created by the programmer and is not defined by Java (except for String).

2. Non-primitive types can be has additional methods to perform certain operations, while primitive types does not has any methods.

3. A primitive type has always a value, while non-primitive types can be null.

4. A primitive type starts with a lowercase letter, while non-primitive types starts with an uppercase letter.

5. The size of a primitive type depends on the data type, while non-primitive types have all the same size.

6. Primitive types does not refer to any object while non-primitive  types are refered to objects


SE - 51 - Throw Vs Throws Vs Throwable !

As we saw in last blogs that the Throwable is parent Class of all the Exceptions/Errors.

Now we need to see difference between Throw and Throws :


Throws :
It is used to declare an exception to inform and to ensure the programmer that the exception might hit and it needs a handling. Throws is only for checked exceptions

  1. public void name() throws exception_class_name{ 
  2. //code
  3. }  
It is followed by a class.
It is given in method signature
We can give multiple exception in method signature



Throw :
It is used to explicitly throw an exception :

  1. throw new IOException("sorry device error);  
It is followed by instance of Exception class.
It is given in method body
There can be only 1 throw statement at once

SE - 50 - try-catch-finally notes !


  1. Nested try catch is possible
  2. Finally block is always executed even if exception is not handled. If try blocks give exception which is not handled then finally will be executed and exception will be thrown.
  3. Finally block in java can be used to put "cleanup" code such as closing a file, closing connection etc. 
  4. If there is return statement in try block , then also finally will be executed
  5. If there is return statement in try and finally both the blocks then finally will override the return statement of try block. Only return statement of finally will be considered.
  6. With finally block we can skip catch block. Only try and finally will work.
  7. When Finally is not executed - If the JVM exits while the try or catch code is being executed, then the finally block may not execute. If the thread executing the try or catch code is interrupted or killed, the finally block may not execute even though the application as a whole continues. The try block runs to the end, and no exception is thrown.
  8. All checked and unchecked exceptions can be handled by try-catch block. But we generally handle checked exception because most of unchecked exception should be handled by programmer itself like NullpointerException
  9. we can write multiple try blocks to handle exceptions or we can write multiple exceptions in single catch : 

catch(SQLException | IOException e)

SE - 49 - Difference between Errors and Exceptions in JAVA

Errors is some serious problem in code which should not be handled in try catch while Exception is something which can be handled by try-catch block.

Major Differences :

1. All Errors are Unchecked but not all exceptions are unchecked

2. Errors can not be recovered or handled by try-catch but exceptions can be handled.

3. Exceptions are related to application where as Errors are related to environment in which application is running.

4. Checked Exceptions are known to compiler but errors are not

Wednesday, 15 April 2020

SE - 48 - Checked Vs Unchecked Exceptions!

Checked Exceptions are also called as Compile Time Exceptions as these are checked by compiler during compilation. It just ensures to get the error handled by user during coding. Few of the major compile time exceptions are : 

IOException -  Its subclasses are  : FileNotFoundException, EOFException, UnsupportedEncodingException, SocketException, and SSLException

SQLException - Its subclasses are  : SQLClientInfoException , SQLDataException , SQLFeatureNotSupportedException ,SQLIntegrityConstraintViolationException
SQLInvalidAuthorizationSpecException ,SQLSyntaxErrorException , SQLTransactionRollbackException ,SQLTransientConnectionException

DataAccessException
ClassNotFoundException
InvocationTargetException


UnChecked Exceptions are also called as Run Time Exceptions as these are identified during runtime. All Errors are Unchecked also. Runtime exception is superclass of all the run-time exceptions :  Few of the major compile time exceptions are : 

  • ArithmeticException
  • ArrayStoreException
  • ClassCastException
  • ConcurrentModificationException
  • EnumConstantNotPresentException
  • IllegalArgumentException - IllegalThreadStateException,NumberFormatException
  • IllegalMonitorStateException
  • IllegalStateException
  • IndexOutOfBoundsException - ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException
  • NegativeArraySizeException
  • NullPointerException
  • SecurityException
  • TypeNotPresentException
  • UnsupportedOperationException