MainMenu

Home Java Overview Maven Tutorials

Saturday, 14 January 2017

Core Java for selenium Introduction



Hello Friends this section will cover the core java tutorial which is enough to learn selenium automation tool.


For Video Tutorial : Move on Youtube Channel


Note : Select the playlist as per your need & move with number sequence




Video Tutorial for this article : CLICK HERE


History of Java?

Stack and heap in Java?

Why is Java platform independent ?

What is Java ?

Access Specifier in java

Data Types in Java



History of Java?



Java का पहला नाम 'Oak' इस पेड़ से रखा गया | ये रखने का मतलब 'James Gosling' और उनके सहकारी जहा पर Java के लिए काम करते थे, वहा पर 'Oak' का पेड़ था और 'Oak' ये कई देशों का राष्ट्रीय पेड़ भी है | इसी लिए 'Oak' ये नाम रखा गया |

ये 'Oak' नाम 1991 में रखा गया | लेकिन ये 'Oak' नाम पहले से ही 'Oak Technologies' का था |

उसके बाद 'Oak' का नाम बदलकर 'Java' रखा गया |

Java ये नाम रखने की एक ही वजह थी कि, जब 'James Gosling' और उनके सहकारी जब काम करते थे तब 'Java' नाम के बीज की Indonesian coffee पीते थे और 'Java' ये नाम काफी नया भी था | इसीलिए 'Java' नाम रखा गया |

अभी 2010 में Sun Microsystem ने 'Oracle' को ये बेच दी |

जब java का प्रारंभ हुआ तब उसका पहला नमूना '1995' में आया |

Introduction for Java/Core Java

Java ये दुनिया भर में बहुत ही प्रसिध्द programming Language है | Java के लिए तीन प्रकार बनाये गए है |
Java SE (Standard Edition)
Java EE (Enterprise Edition)
Java ME (Micro Edition)

1. Java SE
Java SE ये Basic Programming के लिए इस्तेमाल किया जाता है, इसे Core Java भी कहा जाता है |

2. Java EE
Java EE ये Advanced Programminng है , इसे Advanced Java भी कहते है |

3. Java ME
Java ME ये mobile programming के लिए उपयुक्त है, लेकिन इसका android से कोई सम्बन्ध नहीं है |





Stack and heap in Java?



Where does everything live ?

Before we create an object it makes sense to understand where things live and how long they live for.
Two areas of memory to care about : one where objects live(The Heap) and the one where methods invocations and local variables live(the stack).


What is JDK, JRE & JVM

The Java Development Kit (JDK) is one of three core technology packages used in Java programming, along with the JVM (Java Virtual Machine) and the JRE (Java Runtime Environment). It's important to differentiate between these three technologies, as well as understanding how they're connected:
The JVM is the Java platform component that executes programs.
The JRE is the on-disk part of Java that creates the JVM.
The JDK allows developers to create Java programs that can be executed and run by the JVM and JRE.
Developers new to Java often confuse the Java Development Kit and the Java Runtime Environment. The distinction is that the JDK is a package of tools for developing Java-based software, whereas the JRE is a package of tools for running Java code.


What happens when a JVM Starts Up?

1).When a JVM starts up, it gets a chunk of memory from the underlying OS and it uses it to run your java program.
2).How much memory dows it get? That depends on your version of the JVM(and on which platform).
3).Usually you won't have to care about how much menory it gets.
4).All objects are garbage-collectable on the heap.

Instance Variable

Instance varibales are declared inside a class but not inside a method. They represent each individual field that an object has.
Example :-
public class House
{
int table;
}



Local Variable

Local variables are declared inside a method, including method parameters. They are temporary, therefore they only live as long as the method is on the stack --in other words, as long as method has not reached the closing curly brace.
Example :-
public void g(int x)
{
int i = x+3;
boolean b = true;
}

Memory management can be better understand by below image :-



Why is Java platform independent ?



First understand the concept of other language c/c++ processing



prepocessor use to process the source file and the lines which start from #(like include studio etc) and now after preprocessing all the lines which starts from # will be replaces by some code. Now compiler will read this temporary file and will convert it in object file, and then linker will come into existence and it will link library files to object file and will create .exe file.

Remember : All the functions are coded with in library file and declaration is in header file.


Now in JAVA how the source file will be processed



The best feature of java is that it is platform independent. Platform independent means writing codes in one operating System "Windows XP" and executing that code on another platform 'Linux'.

OR

WORA : Write Once and Run Anywhere

Bytecode : Bytecode is the machine language of the Java Virtual Machine by using bytecode execution java proves it's a platform Independent Language.

Source code : Actual java code

Java Compiler : Java Compiler convert the Source code to Byte code.

Java Virtual Machine (JVM) : JVM have Java Interpreter & JIT Compiler and JVM converts byte code .class to executable code object file(.obj file), this .obj file use to generate the Output.

Different types of JVM available on different operating System.

Using this JVM same .class file can run on various platforms.

What is meant by JIT Compiler ?
JIT Compiler is a compiler that converts program source code into native machine code just before running the program. It is Faster and more efficient to perform huge application.

What is java ?



C is procedure oriented language.
Java is object oriented Language.
Java was created by James Gosling from Sun Microsystems (Sun) in 1991.
The first publicly available version of Java (Java 1.0) was released in 1995.
Sun Microsystems was acquired by the Oracle Corporation in 2010.
In 2006 Sun started to make Java available under the GNU General Public License (GPL). Oracle continues this project called OpenJDK.
Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java 1.0 [J2SE]).

Sun Microsystems has renamed the new J2 versions as Java SE, Java EE and Java ME respectively. Java is guaranteed to be Write Once, Run Anywhere.

Java is:
Object Oriented: In Java, everything is an Object. Java can be easily extended since it is based on the Object model.
Platform independent: Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual Machine (JVM) on whichever platform it is being run.

Simple: Java is designed to be easy to learn. If you understand the basic concept of OOP Java would be easy to master.

Secure: With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.

Architectural-neutral :Java compiler generates an architecture-neutral object file format which makes the compiled code to be executable on many processors, with the presence of Java runtime system.

Portable:Being architectural-neutral and having no implementation dependent aspects of the specification makes Java portable. Compiler in Java is written in ANSI C with a clean portability boundary which is a POSIX subset.

Robust:Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking.

Multithreaded: With Java's multithreaded feature it is possible to write programs that can do many tasks simultaneously. This design feature allows developers to construct smoothly running interactive applications.


Interpreted:Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and light weight process.

High Performance: With the use of Just-In-Time compilers, Java enables high performance.

Distributed:Java is designed for the distributed environment of the internet.

Dynamic: Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.

Access specifier in Java





Public , Private & protected Keywords :

private - Only the current class will have access to the field or method.

protected - Only the current class and subclasses (and sometimes also same-package classes) of this class will have access to the field or method.

public - Any class can refer to the field or call the method.

PrivateNon modifierProtectedPublic
Same package sub classNoYesYesYes
Same package non sub classNoYesYesYes
Different package subclassNoNoYesYes
Different package non subclassNoNoNoYes

Why Java is platform independent language:


Javac – compiler that converts source code to byte code.

JVM- interpreter that converts byte code to machine language code.

As we know java is both compiler & interpreter based language. Once the java code also known as source code is compiled, it gets converted to native code known as BYTE CODE which is portable & can be easily executed on all operating systems. Byte code generated is basically represented in hexa decimal format.

After compilation, the interpreter reads the generated byte code & translates it according to the host machine. . Byte code is interpreted by Java Virtual Machine which is available with all the operating systems we install. so to port Java programs to a new platform all that is required is to port the interpreter and some of the library routines.

Source code -> javac ->Universal byte code

Universal byte ->jvm/java -> execute them on a particular machine.


Data Types in Java:


Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory.

There are two data types available in Java:

• Primitive Data Types

• Reference/Object Data Types

Primitive Data Types:

byte: • Byte data type is an 8-bit signed two's complement integer.
• Minimum value is -128 (-2^7)
• Maximum value is 127 (inclusive)(2^7 -1)
• Default value is 0

short: • Short data type is a 16-bit signed two's complement integer.
• Minimum value is -32,768 (-2^15)
• Maximum value is 32,767 (inclusive) (2^15 -1)

int: • Int data type is a 32-bit signed two's complement integer.
• Minimum value is - 2,147,483,648.(-2^31)
• Maximum value is 2,147,483,647(inclusive).(2^31 -1)

long: • Long data type is a 64-bit signed two's complement integer.
• Minimum value is -9,223,372,036,854,775,808.(-2^63)
• Maximum value is 9,223,372,036,854,775,807 (inclusive). (2^63 -1)

float: • Float data type is a single-precision 32-bit IEEE 754 floating point

double: • double data type is a double-precision 64-bit IEEE 754 floating point.

boolean: • boolean data type represents one bit of information.
• There are only two possible values: true and false.

char: • char data type is a single 16-bit Unicode character.


Reference Data Types or non-primitive data type:
• Reference variables are created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed.
Non primitive data type mainly include "Class", "Interface" and "arrays"








Tags :

Core java introduction, overview of core java, access specifier in core java, data types in core java

No comments:

Post a Comment