Skip to main content

Class 1 Java introduction

What is Java

Java is a programming language and a platform.

Java is a high level, robust, secured and object-oriented programming language.

Platform: Any hardware or software environment in which a program runs, is known as a platform. Since Java has its own run time environment (JRE) and API, it is called platform.

Features of Java

The Java Features given below are simple and easy to understand.

  1. Simple
  2. Object-Oriented
  3. Portable
  4. Platform independent
  5. Secured

Object-oriented

Java is Object-oriented programming language. Everything in Java is an object. Object-oriented means we organize our software as a combination of different types of objects that incorporates both data and behavior.

Basic concepts of Oops are:
  1. Object
  2. Class
  3. Inheritance
  4. Polymorphism
  5. Abstraction
  6. Encapsulation

Variable

Variable is name of reserved area allocated in memory. In other words, it is a name of memory location. It is a combination of "vary + able" that means its value can be changed.
Ex. int data=50;//Here data is variable 

Types of Variable

There are three types of variables in java:
  • local variable
  • instance variable
  • static variable

1) Local Variable

A variable declared inside the method is called local variable.

2) Instance Variable

A variable declared inside the class but outside the method, is called instance variable . It is not declared as static.

3) Static variable

A variable which is declared as static is called static variable. It cannot be local.

  1. class A{  
  2. int data=50;//instance variable  
  3. static int m=100;//static variable  
  4. void method(){  
  5. int n=90;//local variable  
  6. } }//end of class  

Data Types in Java

Data types represent the different values to be stored in the variable. In java, there are two types of data types:
  • Primitive data types
  • Non-primitive data types
datatype in java

Object in Java

An entity that has state and behavior is known as an object .

Class in Java

A class is a group of objects which have common properties. It is a template or blueprint from which objects are created. It is a logical entity. It can't be physical.
A class in Java can contain:
  • fields
  • methods
  • constructors
  • blocks
  • nested class and interface
  1. class <class_name>{  
  2.     field;  
  3.     method;  
  4. }  

Method in Java

In java, a method is like function i.e. used to expose behavior of an object.

Advantage of Method

  • Code Reusability
  • Code Optimization

Java Keywords

The following list shows the reserved words in Java. These reserved words may not be used as constant or variable or any other identifier names.
abstractassertbooleanbreak
bytecasecatchchar
classconstcontinuedefault
dodoubleelseenum
extendsfinalfinallyfloat
forgotoifimplements
importinstanceofintinterface
longnativenewpackage
privateprotectedpublicreturn
shortstaticstrictfpsuper
switchsynchronizedthisthrow
throwstransienttryvoid
volatilewhile

Java naming conventions for identifiers

1. Use CamelCase for most identifiers (classes, interfaces, variables, and methods).
2. Use an initial capital letter for classes and interfaces, and a lower case letter for variables and methods.
3. For named constants, use all capital letters separated by underscores.
4. Avoid using $ characters in identifiers.

Java Package

java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined package.


Comments

Popular posts from this blog

Eclipse New Maven Project: Could not resolve archetype

Close Eclipse Delete repository folder (you can find it in C:\Users{your user}.m2) Open Eclipse again. It will install maven repository automatically down v Open Window > Preferences Open Maven > Archetypes Click 'Add Remote Catalog' and add the following: Catalog File:  http://repo1.maven.org/maven2/archetype-catalog.xml Description: maven catalog

How to setup Appium for mobile automation

GitHub is a code hosting platform for version control and collaboration.  When a project is to be created, constant changes are made to the code. Version control systems keep these revisions straight, and store the modifications in a central repository.   A repository is a location where all the files for a particular project are stored. Each project will have its own repository, and can be accessed by a unique URL. Step 1: Install Appium-desktop-setup-1.2.6 (from the link Appium.io) Step 2: Install JDK Step 3: Install android studio-bundle (from developerandroid.com) Step 4: Go to AppData->Local->Android->Sdk Step 5: Copy the above path and set the path of a new environment variable “ANDROID_HOME” Step 6: Copy the above path, append \tools and add it in the path variable Steps 7: Copy the path from Step 5, append \platform-tools and add it in the path variable Step 8: Go to AppData->Local->Android->Sdk->tools->bin->uiautomatorview...

Setup Grid and run your test script on different Machine

1. selenium-server-standalone-3.11.0.jar should download on our local machine. we can download this from here  https://www.seleniumhq.org/download/ 2. After that open the command prompt and go in to the drive where we have downloaded "selenium-server-standalone-3.11.0.jar" file and run the command "java -jar selenium-server-standalone-3.11.0.jar -role hub " 3. Once this will execute successfully we can see on console "Selenium Grid hub is up and running" 4. Now we can see GRID console on browser by opening this url:  http://localhost:4444/grid/console 5. Now GRID is setup successfully 5. Now we have to register Node machine with GRID. For this we will open the node machine and download "selenium-server-standalone-3.11.0.jar", chrome driver, Firefox driver form here  https://www.seleniumhq.org/download/ 6. After that we have to register node machine with GRID by running this command using command prompt : For Chrome Browser run this command ...