vs code shortcuts you must know

  
Some useful vscode shortcuts you must know which save your time.

1. To open vs code from the command prompt 
cmd> code .

2. To open a terminal in vs code 
ctrl + `


java naming conventions

codewithzaheer

Java naming conventions

java is a case sensitive language, that means there is a seperate recognization for uppercase letters and lower case letters.

Exampleabcis not equal to ABC(ABC != abc).

java has the following naming conventions, they are


all classes, abstract classes, and interfaces Names must be started with uppercase letters and their subsequent symbols must be uppercase letters.

Example:

String

StringBuffer


all variables must be started with lowercase letters and subsequent symbols must be uppercase letters.

Example:

nameIsZaheer


all methods must be started with lowercase letters and subsequent symbols must be uppercase letters.

Example:

additionWithTwoParameters()

additionWithThreeParameters()


all constant variables must be in uppercase letters only.

Example:

GLOBAL_VARIABLE


All the package names must be in lowercase letters.

Example:

com.zaheerintrovert.javanamingconventions



Why Java is a Platform Independent Language?


we write code in a high-level language which is human understandable language.
which is not understood by machines so the machine uses a compiler to convert 
the code from high level to machine level or low-level code.

if we take other languages like c and c++
the machine-level code differs by programming language and operating system.
i.e.,
c and c++ generate a .exe file that is not the same for two machines if they are 
running on a different os(operating system)Linux and windows.

i.e., when c and c++ files get compiled they generate the .exe file which is a directly executable file, and these are built or generated on a particular os only 
and for their execution, they will have a system call on the same os.

so if we compile the files in one os and execute them on other can't be possible in these languages.
if you compiled c and c++ files in one os you should execute those files on the same os i.e, machine-level code differs by each operating system. 
so these are platform-dependent.

whereas java is different from these languages

When we compile the java file by the command “javac filename.java” creates an intermediate code called Bytecode.

bytecode is independent of the platforms.
This is where java makes difference between all different programming languages.
 It creates a .class file, which is considered bytecode. Whereas languages 
like c and c++ will create an executable code when they are compiled and thus makes them platform dependent.

and This byte code is not executable. We need a translator for executing this bytecode. 
And JVM does this job. Generally, JVM resides in the main memory of our computer. 
JVM acts as an interpreter and executes the bytecode generated by the compiler.

reading data from keyboard

codewithzaheer

To read the input values in java

Scanner class is used to read data from keyboard, and it is from util package.

below program "addition of two numbers"

package basics;

import java.util.Scanner;

public class readFromKeyboard {

public static void main(String[] args) {

Scanner read = new Scanner(System.in);

int FirstNumber;

int SecondNumber;

int Result;

System.out.println("enter first number");

FirstNumber = read.nextInt();

System.out.println("enter second number");

SecondNumber = read.nextInt();

Result = FirstNumber + SecondNumber;

System.out.println("the result is " + Result);

}

}


note:

To know the methods present in that scanner class we have the command javap java.util.Scanner

To check it open the command prompt and enter the command, then you will get the list of methods present in the scanner Class.

Some of the methods are listed below

nextInt()

nextFloat()

nextDouble()

next()

nextLine()

nextBoolean()

nextByte()

nextShort()

nextLong()

etc...

difference between JDK,JRE and JVM

codewithzaheer

About JDK, JVM and JRE

for learn java programming we required JDK

JDK

JDKthat is java development kit used for compiling java programs or debugging etc... it consists of compiler and other tools along with JRE

Once we compiled the program we need to execute it for that we need JREjava runtime environment which is the part of jdk.

JRE it contains class libraries along with JVM.

JVM it is java virtual machine, its a part of JRE.

you can imagine like JDK is for developing and JRE for executing and for executing we required JVM which is the part of the JRE.

JVM will execute the programs

How the program gets executed means

Example:

HelloWorld.java it is a our program file.

Now, we will compile the file using the command javac HelloWorld.java

note: javac is a part of JDK, aftering compiling the program file we get the .class i.e HelloWorld.class

Now, for running this .class file i.e HelloWorld.class we have the command java HelloWorld, helloworld is the file name.

java command is nothing but jvm which is the part of JRE therefore JDK will compile and JRE will execute the program.



how to install java and set the path

JAVA

To install java go to the website java Download

its better to download the latest version. you can download the required version from the above link.

install the java into your machine.

and now check the version of the java by running the following command in the command prompt java -version

If you get the version then congratulations you have successfully downloaded the java into your machine and have already set the path.

If you doesn't get the java version and instead of version if you the message like java is not recognized as internal or external command,operable program or batch file then you need to set the path.

To set the path follow the below procedure...

we can set the path as local as well as global. the advantage of setting the path as global is we can able to use it from any location from the machine.

To set the path as local, open the command prompt set the path by running the command set path=C:\Program Files\Java\jdk-11.0.14\bin;%path%;

In my case the java is located at this location. C:\Program Files\Java\jdk-11.0.14\bin and %path% is for not to delete the other paths which have already set by default or by manually.

To set the path globally

copy the java path in my case C:\Program Files\Java\jdk-11.0.14\bin now open control panel and click on system and security

now click on the advanced system settings then you will find the Environment variables button below.

click on Environment variables and here you will find the two halfs. i.e., user settings and system settings.

In both settings you will find the Path named value click on that and then press edit option below, and now paste the java bin link and apply and close it.

Note: If you pasted the java link in user settings it is for particular user only. and if you pasted the java path in system settings then java can be used globally and any user of your system can use the java.


Tips:

  you can use the command cls in command prompt to clear the screen.



postman for beginners

codewithzaheer

POSTMAN

Postman, It is a platform for building and using API.

We can manage a complete API lifecycle with postman.

A postman help us to do.

Development
testing
Management

For more information visit

Explore Postman

a website which consist of sample dummpy API'S for the practice purpose visit Click Here

We can get a endpoint to use in postman

The common http methods are

GET To get the values

POST To create the values

PUT To update the values

DELETE To delete the Resources

PATCHTo update the particular field.

Note:

Put will replace the resources, and patch will be used for particular field updates and we can give only required fields in the body instead of whole body fields.


You can visit the link for more information about HTTP methods Click Here

Collections

It is a Group of API requests


variables

Variables are key value pairs or elements that can store different values.

we can reuse the value at Multiple locations if required.Change can be done at a single place.

Advantagewe can store URLS or etc in varaibles and we can use this variable in double curly braces {{name of the variable}}. instead of using the lengthy values. And this method can be used when some values is repeatedly used at multiple places. We can extract out all common values and keep them at one place.

POSTMAN - GET and SET Variables with scripts

Below the request section we can see the tests section in that we can add scripts to set and get varaibales.

Pre-req Scripts executes before running the requests

testScripts executes after running the request.

Setting variables with scripts

Global level: pm.globals.set("name","zaheer");

collection level: pm.collectionVariables.set("name","zaheer");

Environment Level: pm.environment.set"name","zaheer");

local level: pm.variables.set("name","zaheer");


getting variables with scripts

global level: pm.globals.get("name");

or

console.log(pm.globals.get(name);

or

we can store it in variable and then we can call exaample:

let value = pm.globals.get(name);

console.log(value);

collection level: pm.collectionVariables.get("name");

environment level: pm.environment.get("name");

local level: pm.variables.get("name");

note:
Access a variable at any scope, including local, based on priority.

priority levels

local --> data --> environment --> collection --> global

to remove: pm.enviroment.unset("name");

Environments

Environment is a set of key value pairs.

we can use it to store variables which can be used in requests and body and scripts etc...

example:

we can store a request url in a enviroment variable and instead of URL we can use that variable

endpoint=localhost:9008/rest/api/

at the reqest body: http://{{endpoint}}/user.

scripts

When we open any request, We can see pre-request script.= we can create any sctipts and this scripts
will get executed before we run And we have the test section here also we can create the scripts and the scripts get executed after the getting a response from the server.

Tests

Tests in Postman are JavaScript code that is executed after receiving response. We can add test scripts as at a request level, collection level and folder level.

debug

Debugging in the console. Every request sent by Postman is logged in the console, so you can view the detail of what happened when you sent a request. This means you can use the Postman Console to help debug your requests when an API isn't behaving as you expect.

example:

we can run and check the pre-request script

console.log("this is a log");

console.info("this is a info");

console.warn("this is warn");

console.error("this is a error");

Now, open console we can check it.

We can also get data from json file and csv files..

To get the data from CSV or Json file first we have to create a file and add a data in the file and save the file with CSV or Json Extension

Now to add this file first click on Collection then click on three dots on right top on that collection,then you will get the run collection option, select a request method Then you will get.an option like Select file option then you have to upload respected csv or json file And run.

Authorization

APIs use authorization to ensure that client requests access data securely. This can involve authenticating the sender of a request and confirming that they have permission to access or manipulate the relevant data. If you're building an API, you can choose from a variety of auth models. If you're integrating a third-party API, the required authorization will be specified by the API provider.

For more information

DocumentationClick Here

Additional information: Click Here