Java 101 for software testing (Using fruits and vehicle as example)
Tags: testing, bugs, automationtest, java
Published: 2023-01-16 16:03:42


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ojhx0xrjgx8ir7el39b.png)

I think many of you might have similar experience like me where I found myself struggle to understand of Java language.

There was a time I try to avoid myself from writing selenium testing script in Java, instead, I'm using Python to code.

And when I decided to learn and write selenium testing script using java but I'm devastated because of the endless of error seem to appear.. I can't understand the error log, the console log and etc. And I knew that was because lack of basic understanding of Java language.

Hence, I strongly recommend you to read this article before you write any selenium test scripts because you must build your foundation right before you write any scripts.

**

## First, we ask WHY ? Why Java ?
**
✅ Java is a programming language that is commonly used in combination with the Selenium web automation tool.

✅ Selenium is a powerful tool for automating web browsers, and it can be used to automate a wide variety of web-based tasks.

✅ When used with Java, Selenium allows developers to write automated tests for web applications using the Java programming language. 

✅ This can be useful for a variety of purposes, including functional testing, performance testing, and regression testing. Not only that, selenium has a number of libraries that can be used to extend its functionality or make it easier to use in certain situations.

**

## Next, what is Java ?
**

✅ Java is an object-oriented programming (OOP) language.

You may wonder what is OOP means ? Don't freak out.

Let me make this simple for you. For example:
Fruits.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fqeddvp625k6eyii99pr.png)

There are bananas, cherries, oranges, kiwis, grapes and apples in the picture.

✅ These are called Objects.
✅ And what are they categories as ? Fruits

Hence, Fruits is the **Class** and bananas, cherries, oranges, kiwis, grapes and apples is the **Objects**.

Is this sound simple ?

What about this picture ?

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zuz6e54h60k1m3n0brhm.png)


We can see trucks , ambulance, bus and car.

And what are they ? **Vehicles**

So we know **Vehicles** is **Class** and trucks , ambulance , bus and car is an **Object**.

Now, what is the color of the car ? **Blue**

Blue is the **attribute** of the Car.

How do we operate the vehicles ? **Drive**

Drive is the **method**

We can conclude 4 things from this , we know the class (vehicles), the object (car, bus, trucks, ambulance), attributes (blue, 4 tires , etc) and method (drive).

***
public class Vehicle {      **<- this is class = vehicles**

  String carBrand = honda;    **<- this is objects and attributes**
  Int numOfTires = 4;         **<- this is objects and attributes**

void Drive(){                 **<- this is drive method**
    System.out.print("Car is driving");
}

public static void main(String[]args){

Car myCar = new Car();

myCar.drive();

***  
This is just a simple java program to show you how the java structure it is. It's OK not to understand everything in the first place. Just get along with me , and I can assure you will have sufficient java knowledge to write your first selenium script with Java.


❤️

Related Articles:
    [1. Cloud Computing , let’s talk about it [Part 2]](https://dev.to/alanliew88/cloud-computing-lets-talk-about-it-part-2-2mgj)
    [2. AWS ! the terms you must know 🤫](https://dev.to/alanliew88/aws-the-terms-you-must-know-2k8p)
    [3. ISTQB 🧙🏻‍♀️The software testing Myth, do you need that?](https://dev.to/alanliew88/istqb-the-software-testing-myth-do-you-need-that-1ajj)
    [4. Why Software Testing is necessary in the first place?👀 ](https://dev.to/alanliew88/why-software-testing-is-necessary-in-the-first-place-181)

❤️


Connect with me in [Linkedin](https://www.linkedin.com/in/alan-liew/) !