After learning the basics of programming with C++ at my university, seeing mostly data structures, algorithms, file management, validations, functions, methods, in general, the basics of programming.
However, due to university issues, the next subject I have to take is Java, and due to my background as a Tester, I decided to learn how to use Selenium with Java, since it is one of the most used frameworks currently (last update in February 2024) and its use with Java especially, is perfect for both cases, I would kill 2 birds with one stone as we would say in my country! 🐦🐦
So I'm getting deep into OOP concepts, which are also essential in test automation.
Since I came from C++ and the basics, the first thing I did was learn Java syntax, how it works, logical operators, relational operators, try
and catch
, functions, methods, statements. The good thing about learning the basics well is that when you switch from one language to another, it doesn't become so difficult, since you only have to learn the syntax and some actions that are different from other languages.
This took me maybe the first day and the second day practicing with basic exercises that I've done in C++ and trying to solve them in Java, to familiarize myself with the syntax and some details that work differently, such as statements, access modifiers or reading data in the console.
Then I moved on to object-oriented programming, which has been a few days full of material, however, I feel that I have made a lot of progress with the concepts, a key is not to rush to learn, and to practice a lot when learning different concepts.
I would like to talk about how artificial intelligences serve to be your own teacher, how?: ask questions, make comparisons with concepts, ask exercises to see if you understood the logic of the concept or not, and much more, which I want to talk about in a separate blog, since there is a lot to talk about.
Java, being object-oriented, is ideal to start with these concepts:
- Encapsulation
- Inheritance
- Polymorphism
- Method overloading and overwriting
- Abstract classes
- Interfaces
These terms are quite complex, and it took me a lot of practice to be able to differentiate one from the other, I hope I'm not the only one! 😅
I still have a lot to improve, but I've tried to implement it in many exercises, and it's been quite useful to see how you can modulate the code with these techniques and save lines of code that in C++ I made it through functions or methods, which in the end, clearly is not the same.
Also, a big part of understanding OOP is contextualizing everything as an object. Thinking about something and being able to ask yourself:
- What attributes does that object have?
- What does this object do?
From here come the attributes and methods of a class. For example, the example that is always used:
A car:
- What attributes does a car have? Tires, doors, brand, model, color, and so many more attributes
- What actions can a car do? Accelerate, brake, park, reverse, turn and much more
The attributes and methods are derived from these, as well as any other object that is needed.
After learning these terms, I then moved to collections, which are structures that can grow without having to be defined like vectors and matrices, these collections grow as data is added.
Types of collections that I have seen these days:
- ArrayList
- LinkedList
- Stack
- HashMap
Each one has different functions and can be very useful, the one I have used the most so far has been the ArrayList, I love it for creating objects and adding them with the .add()
method.
Something that I loved and learned about these collections, is the iteration over them, and the forEach method. I had seen it and I never even knew what it was, until now that I learned to use it, I have not used the conventional method again! This forEach method has a little more simplicity in the steps to go through the ArrayList, for example, you do not need to use list.get(i)
.
Creating an arrayList:
`ArrayList<String> list = new ArrayList<>();
// Adding items to the list
list.add("test");
list.add("another");
list.add("third");`
Normal for method:
`for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}`
forEach method:
`for (String element : list) {
System.out.println(element);
}`
I thought that OOP was not going to be so complicated, since I had some knowledge, but seeing it from a programmer's side, it is quite complex and requires critical thinking to be able to use it in the best way.
I still have quite a few things to see, such as:
ENUMS, threads, generics, JPA
In total I have more than 50 packages in my repository, each one including approximately 3/4 classes, which means that in a quick estimate I have a little more than 200 classes created from pure exercises and learning with all this that I have mentioned, I plan to upload it to a repository soon with statements so that others can practice with the same!
I am almost done with this beautiful OOP topic, I will document how I did this week with the missing topics, and then fully carry out projects applying all the concepts studied, which is the most important thing.
Resources:
I have used courses in Spanish (TodoCode and Programacion ATS on YouTube), apart from a lot of Stack Overflow and official Java documentation.
If anyone is studying these topics and would like to exchange opinions on them, please feel free to contact me!
Thanks for reading, happy coding/testing!💻
Top comments (0)