Posts

Showing posts with the label Java Stuff

What are Java Modifiers and Operators?

Image
1. 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 1.1. 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 1.1.1. Default Accessible  within the same package only . No modifiers are needed.

What are OOPS Concepts in Java?

Image
Introduction Object-Oriented Programming (OOP) is a programming paradigm that is based on the concept of objects, which can contain data and code to manipulate that data. Java is a fully object-oriented programming language, and as such, it provides several key concepts that make up the foundation of OOP. In this tutorial, we will explore the main OOP concepts in Java, along with examples and code. It is based on the principles of: Encapsulation Inheritance Polymorphism Abstraction In OOPs, everything is treated as an object, which can have properties and methods that operate on those properties. Advantages of using OOPs: There are several advantages of using OOPs in programming: Modularity: OOPs allows breaking down the code into smaller, more manageable pieces known as objects. This makes the code more modular, easier to understand, and maintain.

Java Date Format Validation with Regular Expressions: A Step-by-Step Guide

Image
1. Introduction Validating date formats is an essential aspect of many software applications. It ensures that the user inputs a date in the correct format, reducing the risk of errors and inconsistencies in data. Regular expressions are a powerful tool for validating date formats. In this tutorial, we will explore how to validate date formats using regular expressions in Java.

Implement Code Re-usability in Selenium Automation Framework

Image
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

What is Encapsulation in Java?

Encapsulation is a mechanism of binding code and data together in a single unit. Let’s take an example of Capsule. Different powdered or liquid medicines are encapsulated inside a capsule. Likewise in encapsulation, all the methods and variables are wrapped together in a single class. However if we setup public getter and setter methods to update (for example  void setAge(int age) )and read (for example   int getAge() ) the private data fields then the outside class can access those private data fields via public methods. This way data can only be accessed by public methods thus making the private fields and their implementation hidden for outside classes. That’s why encapsulation is known as  data hiding.  Lets see an example to understand this concept better. Example of Encapsulation: /* Create a class Encapsulation.java */ public class Encapsulation { private String name ; private int age ; public int getAge () { return age ; } publ

What are Java Variables and Data Types?

Image
1. What is a Java Variable? A variable can be called a container that holds some value in a Java program.  The variable has assigned a data type that defines what type of value the variable can hold.  The variable has a name which locates in the memory.  If you want to use a variable in a program, there are two steps associated with it you have to perform: Variable Declaration Variable Initialization i. Variable Declaration