An Overview of Java Programming

An Overview of Java Programming, Java Installation, Java Programming Environment Setup, Java Language Fundamentals, and Java Object-Oriented Programming.

Java Standard Edition or Core Java

Java Standard Edition or Core Java

1. Java Installation and Programming Environment Setup
2. Java Keywords and Identifiers
3. Java Syntax
4. Java Program Structure
5. Java Comments
6. Java Data Types
7. Java Variables
8. Java Operators
9. Java Control Flow – Decision Making/Conditional Statements
10. Java Control Flow – Loop Java Loop Statements
11. Java Control Flow – Branching Statements
12. Java Strings
13. Java Arrays
14. Java ArrayList
15. Java User Input
16. Java File Handling
17. Java Methods – predefined methods
18. Java Methods – user-defined methods
19. Java Exception Handling
20. Java Object-Oriented Programming Fundamentals
21. Java OOPS – Inheritance
22. Java OOPS – Polymorphism
23. Java OOPS – Abstraction
24. Java OOPS – Encapsulation

1. Java Installation and Programming Environment Setup

Download Java (JDK) software and install, set Java environment variable, No built-in editor in Java for writing programs, so Download & Extract/Install Eclipse IDE, Launch Eclipse IDE, and start writing Java Programs.

2. Java Keywords and Identifiers

Java keywords are also known as reserved words. Keywords are particular words that act as a key to a code. These are predefined words by Java so they cannot be used as identifiers.

Identifiers in Java are symbolic names used for identification. They can be a class name, variable name, method name, package name, constant name, and more.

3. Java Syntax

Every programming language has its own syntax, we have to write programs using the syntax.

Example:

i. Java is case sensitive language
ii. Java code blocks should be enclosed with {}
iii. Every Java statement should end with a semi-colon.
Etc,

4. Java Program Structure

When we are writing any program in any language we need to follow a standard structure. Java has a specific structure to write programs.

Generally, a standard Java program consists of some sections.

i. Documentation section
ii. Package Declaration
iii. Import Statements
iv. Interface Section
v. Class Definition
vi. Class Variables and Variables
vii. Main Method Class
viii. Methods and Behaviors

5. Java Comments

Comments are English words used for Code Documentation

Purpose of Comments:
To make the Code Readable
To make the code prevent from Execution

Note: Java Supports single-line comments and multiple-line comments.

Syntax:

i. Use // for Single line Syntax
ii. Use /*……………….*/ for multiline comment

6. Java Data Types

A Data type is a classification of the type of data that a variable or object can hold in Computer programming

Examples:
Character,
Integer,
Float, Double….
String
Boolean etc…

Java supports two categories of Data Types,
i. Primitive Data Types
ii. Non-Primitive Data Types / Reference Data Types

7. Java Variables

A named memory location to store or hold temporary data within a program
(RAM
ROM – HDD, CD, DVD, USB Drive, etc…)

Java Supports three types of variables,

i. Local Variables
ii. Instance Variables
iii. Static Variables/Class Variables

8. Java Operators

Operators are used to performing Mathematical, Comparison, and Logical operations

Categories of Operators in Java:
i. Arithmetic Operators
ii. Assignment Operators
iii. Relational / Comparison Operators
iv. Logical Operators
v. Bitwise Operators
vi. Miscellaneous Operators
etc…

9. Java Control Flow – Decision Making/Conditional Statements

i. Two Types of Conditional Statements

a. if statement
b. switch statement

ii. Three types of Conditions

a. Single Condition (Positive / Negative Condition)

if (a>b){
.

}
—————
if (!(a<b){

}

b. Compound / Multi Condition (Positive / Negative Condition)

if ((a>b) && (a>c) && (a>d)){
.
}

c. Nested Condition (Positive / Negative Condition)

if (a>b){
if (a>c){
if (a>d){

}
}

}

iii. Usage of Conditional statements

a. Execute a block of statements when a condition is true

b. Execute a block of statements when a condition is true otherwise execute another block of statements

c. Execute a block of statements when a compound condition is true otherwise execute another block of statements

d. Decide among several alternates (else if)

e. Execute a block of statements when more than one condition is true (nested if)

f. Decide among several alternates (using switch statement)

10. Java Control Flow – Loop Java Loop Statements

Loop Statements are used for code repetitive execution

Four types of loop statements in Java,

i. for loop
ii. while loop
iii. do while loop
iv. enhanced for loop (Array)

11. Java Control Flow – Branching Statements

• Branching statements are used to transfer control from one point to another in the code

• Branching statements are defined by three keywords – break, continue and return

12. Java Strings

• String is a sequence of characters written in “”

• String may contain Alphabytes, Numeric, Alpha-numeric and special characters.

Example:

“SELENIUM”
“selenium”
“India123”
“123”
123 //Integer
“India123*&^”
Etc…

Note: Using String predefined methods we can perform operations on strings

13. Java Arrays

• Array is a collection of similar type of elements

• In Java Array is an Object that contains elements of similar data types

• Java Array is index bases and index starts from zero

• The length of an Array is established when they are is created and Array length is fixed,

• Each item in an Array is called an Element

14. Java ArrayList

• Java Array is Static Data Structure and ArrayList is Dynamic Data Structure.

• The ArrayList class is a resizable array, which can be found in java.util package.

• The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified. While elements can be added and removed from an ArrayList whenever you want.

15. Java User Input

The Scanner class is used to get user input, and it is found in java.util package.

To use the Scanner class, create an object of the class and use any of the available methods found in the Scanner class documentation.

Input Types – Method Description

i. nextLine() – Reads a String value from the user
ii. nextByte() – Reads a byte value from the user
iii. nextShort() – Reads a short value from the user
iv. nextInt() – Reads a int value from the user
v. nextLong() – Reads a long value from the user
vi. nextFloat() – Reads a float value from the user
vii. nextDouble() – Reads a double value from the user
viii. nextBoolean() – Reads a boolean value from the user
ix. scan.next().charAt(index) – Reads a character value from the user

16. Java File Handling

File handling in Java implies reading from and writing data to a file. The File class from the java.io package, allows us to work with different formats of files. In order to use the File class, you need to create an object of the class and specify the filename or directory name.

Java FileWriter and FileReader classes are used to write and read data from text files.

Java Buffered Reader and BufferedWriter classes are used to write and write data to text files.

17. Java Methods – predefined methods

In Java, predefined methods are the method that is already defined in the Java class libraries is known as predefined methods. It is also known as the standard library method or built-in method. We can directly use these methods just by calling them in the program at any point.

Categories of predefined methods in Java:

i. Number Methods
ii. Character Methods
iii. String Methods
iv. Array Methods
Etc…

18. Java Methods – user-defined methods

What is Method?

Java Method is a block of code /set of statements/steps that are grouped together to perform certain action.

When we choose Methods?

Whenever we want to perform any operation multiple times then we choose Methods

Advantages of Methods

i. Code reusability, so that we can reduce the code size
ii. Code maintenance is easy

Java User-defined methods

i. Method with return a Value (Perform an Operation and return a Value)
Static method (we call static methods directly or using the class name)
Nonstatic method (we call nonstatic methods by invoking an object)

ii. Method without return any Value (Perform an Operation)
Static method
Nonstatic method

19. Java Exception Handling

An exception is an event that occurs during the execution of a program when the normal execution of the program is interrupted.

Exception handling is a mechanism to handle run-time errors

Common Scenarios where Exception may occur

i. A scenario where ArithmeticException occurs
ii. Scenario where NumberFormat Exception occurs
iii. Scenario where NullPointerException occurs
iv. Scenario where ArrayIndexOutOfBoundsException occurs
Etc,

20. Java Object-Oriented Programming Fundamentals

Project, Package, Class, Interface, Object, Method, Constructor, etc….

A class is a template, blueprint, or contract that defines what an object’s data fields and methods will be.

An object is an instance of a class. We can create many instances of a class. A Java class uses variables to define data fields and methods to define actions. Additionally,a class provides methods of a special type, known as constructors, which are invoked to create a new object.

Four principles of Java OOPS:

i. Inheritance
ii. Polymorphism
iii. Abstraction
iv. Encapsulation

21. Java OOPS – Inheritance

• Inheritance is a process of inheriting (reusing) Class members (Variables and methods) from one class to another

• The Class where the class members are getting inherited is called Super Class / Parent Class / Base Class

• The Class to which the class members are getting inherited is called Sub Class / Child Class / Derived Class

• The Inheritance between parent Class and Child Class is achieved using the “extends” keyword

Types of Inheritance in Java:

i. Single Inheritance
ii. Multi-Level Inheritance
iii. Hierarchical Inheritance
iv. Hybrid Inheritance
v. Multiple Inheritance (* Java doesn’t support multiple inheritances)

22. Java OOPS – Polymorphism

Polymorphism means performing a task/s in different ways.

Polymorphism was derived from two Greek words,

Poly – Many

Morphs – Forms/ways

So Polymorphism means “Many Ways”

Two types of Polymorphism in Java:
a. Compile Time Polymorphism/Method OverLoading
b. Run-time Polymorphism/Method Overriding

23. Java OOPS – Abstraction

• Abstraction is a process of hiding implementation details and showing functionality to the user

• In another way, it shows important things to the user and hides internal details Ex: Sending an Email

• Abstraction focuses on what the object does instead of how it does

Abstraction can be achieved in two ways,
i. Abstract Class
ii. Interface

24. Java OOPS – Encapsulation

• Encapsulation is a process of wrapping code and data into a single unit

Ex: capsule (Mixer of Several medicines)

• Encapsulation is the technique making the fields in a class private and providing access via public methods

• It provides control over the data

• By providing getter and setter methods we can make a class read-only or write-only


Selenium Tutorial for Beginners

0. Selenium Tutorial – 0. Prerequisites to Learn Selenium
1. Selenium Tutorial – I. Introduction – 1. Selenium Syllabus
2. Selenium Tutorial – I. Introduction – 2. An Overview of Selenium
3. Selenium Tutorial – II. Java for Selenium – 1. Introduction to Java

 

Follow me on social media: