Posts

Showing posts with the label Java Stuff

Java Modifiers

  Mo difiers are Java keywords that are used to declare features in applications. They affect either the lifetime or the accessibility of a feature. A feature may be a class, a method, or a variable. Modifiers that affect the visibility of a feature are called access modifiers or visibility modifiers. The remaining modifiers do not fall into any clear categorization and may be called storage and lifetime modifiers. Java modifiers are of two types : Access Modifier   Non-Access Modifier Access Control Modifiers Java provides a number of access modifiers to set access levels for classes, variables, methods and constructors.  The four access levels are: Default Public Private Protected Default:  Visible to the package only . No modifiers are needed.  In sample code below, you can see that no access modifier is used with 'class' keyword which makes it default. Now this class is only visible/accessible to the other classes which are present in the same package along with th

Java Operators

Java Operators are symbols that perform operations on variables and values. Java provides many types of operators which can be used according to our usage. They are classified into following types: Arithmetic Operators Assignment Operators Relational Operators Logical Operators Unary Operators Bitwise Operators  Arithmetic Operators Arithmetic operators are used to perform mathematic operations on variables and data. They operate on numeric values. In simple words they  can be used to perform the mathematical operations of addition, subtraction, multiplication, and division. Operator      Description +                Performs addition –              Performs subtraction *              Performs multiplication /              Performs division %              Returns the remainder of the division Sample Code: class Arithmetic { public static void main (String[] args) { // variables int a = 10 , b = 5 ; // Print sum using addition operator System. out .

What are OOPS Concepts in Java?

We used to hear OOPS very often whenever we come across JAVA language. In this post we are going to have a look at the OOPS concepts of the Java. Some of the object oriented languages are: C#, C++, PHP, Java, Python etc. Main concepts of OOPS are: Object Class Inheritance Polymorphism Abstraction Encapsulation 1. Object:  A Java object is a combination of data and procedures working on the available data. An object has a state and behavior. The state of an object is stored in fields (variables), while methods (functions) display the object's behavior. Objects are created from templates known as classes. In Java, an object is created using the keyword "new". Syntax of creating an object: MyClass obj = new MyClass(); In above example,  MyClass is class name,  ' obj ' is the object name (object name can be anything)  ' new ' is keyword of java which instantiates the object (or in simple language it creates the object '

How to Validate Date Format using Regular Expressions in Java

In this tutorial, you will learn to match date format using Regular Expressions in Java. Regular Expression is a sequence of symbols and characters which define a search pattern, used for pattern matching with strings. Regular Expression is also known as regex. It is mainly used for finding or validating strings and also for replace string operations. It's a very handy and powerful tool which comes along in every programming language. Java Program to check Date Format package com. techlistic . javaprograms ; class ValidateDateFormat { public static void main (String[] args) { // Pass Date Format validateDateFormat( "15/12/2019" ); } // Check the Date format to be MM/dd/yyyy private static boolean validateDateFormat (String date){ // Store date format in String buffer StringBuffer sBuffer = new StringBuffer(date); String mon; String dd; String year; // Store the Date in String Buffer and Break down the date // 0,2 -

Implement code re-usability in Selenium Automation Framework

In this post, you will learn kind of coding pattern which is very helpful in maintaining our automation code. This post is written insight to help beginners. We'll learn that instead of writing a linear script, we should create page (action) methods which in general contain actions which we are going to perform on our web software. Let's say, we have a login functionality in our software and we have to automate it. In that case we'll create a method named login and write the commands like, entering username, password and click login in that method. Now we can use that method wherever we need it in other test cases as well. Benefits of using action methods are: Code Re-usability Better maintainability of code Sample Program for Re-Usable Action Methods: package com . techlistic . tute ; import org.junit.Assert ; import org.junit.Test ; import org.openqa.selenium.By ; import org.openqa.selenium.WebDriver ; import org.openqa.selenium.WebElement ; import o

What is Inheritance in Java?

Inheritance is an important feature of OOP(Object Oriented Programming). It is the mechanism in java by which one class is allow to inherit the features(fields and methods) of another class. Important terminology: Super Class:  The class whose features are inherited is known as super class(or a base class or a parent class). Sub Class:  The class that inherits the other class is known as sub class(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods. Reusability:  Inheritance supports the concept of “reusability”, i.e. when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class. By doing this, we are reusing the fields and methods of the existing class. Syntax of Inheritance: class  SubclassName  extends  SuperclassName   {       //methods and fields    }   The  ext