0% found this document useful (0 votes)
6 views

Java Learning

Java notes

Uploaded by

Nathan Ombui
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Java Learning

Java notes

Uploaded by

Nathan Ombui
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Java

IntelliJ Shortcuts

Sout – system.out.println

Psvm – Public Stataic Void Main

CamelCase in Java naming conventions

Java follows camel-case syntax for naming the class, interface, method, and variable.

If the name is combined with two words, the second word will start with uppercase letter always such as
actionPerformed(), firstName, ActionEvent, ActionListener, etc.

Public – Specify how to access classes, methods, and fields

- Public access modifier


- Access level is everywhere/ allows us to access methods everywhere
1. Inside a class
2. Outside a class
3. Inside the package
4. Outside the package

Private – private access modifier

- The access level is only inside the class.

Static Non-Access Modifier – You can access fields/ methods using the class name.

Example: System.out – out is a static field of System.

Static – allows us to call the method and fields using the class Name.

Return Types

The types of data that a method returns/gives.

A method can return/ give a value.

F(x) = x + 1

X is a parameter to this function.

X + 1 = is the return value of this function.


BLOCK STYLES

Programming Errors

1. Syntax Errors – errors related to java syntax


2. Runtime Errors – Happen during execution of program. Normally invisible

3. Logical Errors – Happen due to errors by developer.

4. Common Errors

Data Types
OBJECT ORIENTED PROGRAMMING (OOP)

Object – An instance of a class that may contain attributes (Characteristics) and methods. E.g phone,
desk, computer, coffee cup etc.

We can use programming to imitate objects in the real world.

An object uses a class.

e.g object car.

Attributes – Characteristics the object has.


Methods – Actions the object does.

Constructor – Special method that is called when an object is instantiated (Created)

- Constructors allow us to build objects that have different attributes/ Characteristics that make
them uique.

Variables – Are of 2 types;

1. Local – Declared inside a method. Visible only to that method.


2. Global – Declared outside a method, bit inside a class.

Overloaded Constructors – multiple constructors within a class with the same name but have different
parameters.

Name + parameters = signature

toString() – special method that all objects inherit, that returns a string that “textually represents” an
object.

- Can be used both implicitly and explicitly

Arrays

Formula

Int[] numbers = new int[3];

Char[] characters = new char[4];

String[] strings = new string[6];

RESTASSURED WITH RAHUL

Maven – A build Management Tool.

Advantages of Maven

1. Automatic Standard Project Skeleton Creation


2. Ease of adding Project dependencies -> mvnrespository.com
3. Seamless Integration with CI/CD

TestNG - TestNG is a testing framework inspired from JUnit and NUnit but introducing some new
functionalities that make it more powerful and easier to use. It supports test configured by
annotations, data-driven testing, parametric tests, etc.

Hamcrest - Core API and libraries of hamcrest matcher framework.

//given - All input details

//when - Submit the API

//then - Validate the response

Static Packages

given() - import static io.restassured.RestAssured.*;


equalTo() - import static org.hamcrest.Matchers.*;

1. Print No of courses returned by API

2.Print Purchase Amount

3. Print Title of the first course

4. Print All course titles and their respective Prices

5. Print no of copies sold by RPA Course

6. Verify if Sum of all Course prices matches with Purchase Amount

You might also like