SlideShare a Scribd company logo
Java Basics
Omid Sohrabi
JVM vs JRE vs JDK
JVM (Java Virtual Machine) is an abstract
machine. It is a specification that provides runtime
environment in which java bytecode can be
executed.
JRE is used to provide runtime environment. It is
the implementation of JVM. It physically exists. It
contains set of libraries + other files that JVM uses
at runtime.
JDK is an acronym for Java Development Kit. It
physically exists. It contains JRE + development
tools.
JVM vs JRE vs JDK
JVM
Function of java virtual machine
The bytecode is generated by java compiler in a JVM
understandable format.
As a programmer we develop a java application and
when we compile a java program, the compiler will
generate .class (dot class) file.
The .class file contains byte code (Special java
instructions).
To execute a java program we take the help of JVM (java
virtual machine) to the JVM we have to provide .class
file as the input.
JVM
JVM
1.Method Area:
• Java Virtual Machine Method Area can be used for
storing all the class code and method code.
• All classes bytecode is loaded and stored in this run
time area , and all static variables are created in this
area.
JVM
2.Heap Memory:
• JVM Heap Area can be used for storing all the objects that are
created.
• It is the main memory of JVM , all objects of classes :- non
static variables memory are created in this run time area.
• This runtime area memory is finite memory.
• This area can be configured at the time of setting up of
runtime environment using non standard option like
• This can be expandable by its own , depending on the object
creation.
• Method area and Heap area both are sharable memory areas.
JVM
JVM
JVM
3.Java Stack:
• For every thread, JVM creates a separate stack at the
time of thread creation. The memory for a Java Virtual
Machine stack does not need to be contiguous. The
Java virtual machine only performs two operations
directly on Java Stacks: it pushes and pops frames
• After completing all method calls the stack becomes
empty and that empty stack is destroyed by the JVM
just before terminating the thread.
Java
OOP:
• Object orientation is built on the foundations of
encapsulation, abstraction, inheritance, and
polymorphism
interface
• Apart from the inherited behavior, in interface the
derived class specializes its behavior by adding to or
overriding base class behavior.
Java
Access Modifiers
• Access modifiers determine the level of visibility
• Public , Private, Protected , Default
• One significant difference between these two access modifiers arises
when we talk about a subclass belonging to another package than its
superclass. In this case, protected members are accessible in the
subclass, whereas default members are not.
NOTE
• Use the explicit thisqualifier when accessing fields inside instance
methods or constructors to avoid ambiguity in referring to variable
names.
Override & Overload
• Polymorphism can be of two forms: static and dynamic.
• The signature of a method is made up of the method
name, number of arguments, and types of arguments.
You can overload methods with same name but with
different signatures. Since return type and exception
specification are not part of the signature, you cannot
overload methods based on return type or exception
specification alone
Nonaccess modifiers
Nonaccess modifiers change the default behavior of a Java
class and its members.
Abstract, static, final, synchronized, native ,...
A synchronized method can’t be accessed by multiple
threads
A native method calls and makes use of libraries and
methods implemented in other programming languages
such as C or C++. You can’t mark classes, interfaces, or
variables with this modifier.
Abstract
An abstract class can’t be instantiated
An abstract class may or may not define an abstract method. But a
concrete class can’t define an abstract method.
An interface is an abstract entity by default. The Java compiler
automatically adds the keyword abstract to the definition of an
interface. Thus, adding the keyword abstract to the definition of an
interface is redundant.
Final
The keyword final can be used with the declaration of a class,
variable, or method. It can’t be used with the declaration of an
interface.
A class that’s marked final can’t be extended by another class
A final variable can’t be reassigned a value. It can be assigned a
value only once
A final method defined in a base class can’t be overridden by a
derived class
Static
static variables belong to a class. They’re common to all instances
of a class and aren’t unique to any instance of a class
A static variable is shared by all the objects of a class.
static methods aren’t associated with objects and can’t use any of
the instance variables of a class. You can define static methods to
access or manipulate static variables
Static
Neither static methods nor static variables can access the non-
static variables and methods of a class. But the reverse is true:
non- static variables and methods can access
You can’t prefix the definition of a top-level class or an interface
with the keyword static. A top-level class or interface is one that
isn’t defined within another class or interface.
Data Types
Primitive vs. Reference
conversion
a primitive variable contains its value, and conversion of a primitive
variable means irreversible changes in its value
casting a reference variable doesn’t touch the object it refers to,
but only labels this object in another way, expanding or narrowing
opportunities to work with it
A reference is like a remote control to an object. The remote control
has more or fewer buttons depending on its type, and the object
itself is stored in a heap. When we do casting, we change the type
of the remote control but don’t change the object itself.
Primitive vs. Reference
Upcastingis casting a subtype to a supertype, upward to the
inheritance tree
Unlike upcasting, downcasting can fail if the actual object type is
not the target object type
Primitive vs. Reference
We can use == operators for reference comparison (address
comparison) and .equals() method for content comparison. In
simple words, == checks if both objects point to the same memory
location whereas .equals() evaluates to the comparison of values in
the objects.
Variables
Variables can have multiple scopes: class, instance, local, and
method parameters.
Instance variables are defined and accessible within an object.
They’re accessible to all the instance methods of a class.
Class variables are shared by all the objects of a class—they can be
accessed even if there are no objects of the class
Local and instance variables can be defined using the same name.
In a method,
if a local variable exists with the same name as an instance
variable, the local variable takes precedence
NOTE
When you pass a primitive variable to a method, its value remains
the same after the execution of the method. This doesn’t change,
regardless of whether the method reassigns the primitive to
another variable or modifies it.

More Related Content

What's hot

Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAhmed Nobi
 
Java essentials for hadoop
Java essentials for hadoopJava essentials for hadoop
Java essentials for hadoopSeo Gyansha
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statementsİbrahim Kürce
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2Sherihan Anver
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and InterfaceHaris Bin Zahid
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classesShreyans Pathak
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1Sherihan Anver
 
Learning core java
Learning core javaLearning core java
Learning core javaAbhay Bharti
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singhdheeraj_cse
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm Madishetty Prathibha
 

What's hot (19)

Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
 
Java essentials for hadoop
Java essentials for hadoopJava essentials for hadoop
Java essentials for hadoop
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statements
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
 
inheritance
inheritanceinheritance
inheritance
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Learning core java
Learning core javaLearning core java
Learning core java
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Abap Objects for BW
Abap Objects for BWAbap Objects for BW
Abap Objects for BW
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
 
Java basic concept
Java basic conceptJava basic concept
Java basic concept
 

Similar to Java Basics Presentation

Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Fresherszynofustechnology
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questionsGradeup
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interviewKuntal Bhowmick
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobGaruda Trainings
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1SURBHI SAROHA
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdfvenud11
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview QuestionsKuntal Bhowmick
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardHari kiran G
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview QestionsArun Vasanth
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 eehomeworkping9
 
Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2eeShiva Cse
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core ParcticalGaurav Mehta
 

Similar to Java Basics Presentation (20)

1
11
1
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
Java
JavaJava
Java
 
Core java questions
Core java questionsCore java questions
Core java questions
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
Java Core
Java CoreJava Core
Java Core
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a job
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdf
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview Questions
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
C# interview
C# interviewC# interview
C# interview
 
Viva file
Viva fileViva file
Viva file
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 ee
 
Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2ee
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 

Recently uploaded

Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareinfo611746
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAlluxio, Inc.
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowPeter Caitens
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfkalichargn70th171
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockSkilrock Technologies
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?XfilesPro
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAlluxio, Inc.
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfMeon Technology
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion Clinic
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEJelle | Nordend
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...Alluxio, Inc.
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILNatan Silnitsky
 

Recently uploaded (20)

Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 

Java Basics Presentation

  • 2. JVM vs JRE vs JDK JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed. JRE is used to provide runtime environment. It is the implementation of JVM. It physically exists. It contains set of libraries + other files that JVM uses at runtime. JDK is an acronym for Java Development Kit. It physically exists. It contains JRE + development tools.
  • 3. JVM vs JRE vs JDK
  • 4. JVM Function of java virtual machine The bytecode is generated by java compiler in a JVM understandable format. As a programmer we develop a java application and when we compile a java program, the compiler will generate .class (dot class) file. The .class file contains byte code (Special java instructions). To execute a java program we take the help of JVM (java virtual machine) to the JVM we have to provide .class file as the input.
  • 5. JVM
  • 6. JVM 1.Method Area: • Java Virtual Machine Method Area can be used for storing all the class code and method code. • All classes bytecode is loaded and stored in this run time area , and all static variables are created in this area.
  • 7. JVM 2.Heap Memory: • JVM Heap Area can be used for storing all the objects that are created. • It is the main memory of JVM , all objects of classes :- non static variables memory are created in this run time area. • This runtime area memory is finite memory. • This area can be configured at the time of setting up of runtime environment using non standard option like • This can be expandable by its own , depending on the object creation. • Method area and Heap area both are sharable memory areas.
  • 8. JVM
  • 9. JVM
  • 10. JVM 3.Java Stack: • For every thread, JVM creates a separate stack at the time of thread creation. The memory for a Java Virtual Machine stack does not need to be contiguous. The Java virtual machine only performs two operations directly on Java Stacks: it pushes and pops frames • After completing all method calls the stack becomes empty and that empty stack is destroyed by the JVM just before terminating the thread.
  • 11. Java OOP: • Object orientation is built on the foundations of encapsulation, abstraction, inheritance, and polymorphism interface • Apart from the inherited behavior, in interface the derived class specializes its behavior by adding to or overriding base class behavior.
  • 12. Java Access Modifiers • Access modifiers determine the level of visibility • Public , Private, Protected , Default • One significant difference between these two access modifiers arises when we talk about a subclass belonging to another package than its superclass. In this case, protected members are accessible in the subclass, whereas default members are not. NOTE • Use the explicit thisqualifier when accessing fields inside instance methods or constructors to avoid ambiguity in referring to variable names.
  • 13. Override & Overload • Polymorphism can be of two forms: static and dynamic. • The signature of a method is made up of the method name, number of arguments, and types of arguments. You can overload methods with same name but with different signatures. Since return type and exception specification are not part of the signature, you cannot overload methods based on return type or exception specification alone
  • 14. Nonaccess modifiers Nonaccess modifiers change the default behavior of a Java class and its members. Abstract, static, final, synchronized, native ,... A synchronized method can’t be accessed by multiple threads A native method calls and makes use of libraries and methods implemented in other programming languages such as C or C++. You can’t mark classes, interfaces, or variables with this modifier.
  • 15. Abstract An abstract class can’t be instantiated An abstract class may or may not define an abstract method. But a concrete class can’t define an abstract method. An interface is an abstract entity by default. The Java compiler automatically adds the keyword abstract to the definition of an interface. Thus, adding the keyword abstract to the definition of an interface is redundant.
  • 16. Final The keyword final can be used with the declaration of a class, variable, or method. It can’t be used with the declaration of an interface. A class that’s marked final can’t be extended by another class A final variable can’t be reassigned a value. It can be assigned a value only once A final method defined in a base class can’t be overridden by a derived class
  • 17. Static static variables belong to a class. They’re common to all instances of a class and aren’t unique to any instance of a class A static variable is shared by all the objects of a class. static methods aren’t associated with objects and can’t use any of the instance variables of a class. You can define static methods to access or manipulate static variables
  • 18. Static Neither static methods nor static variables can access the non- static variables and methods of a class. But the reverse is true: non- static variables and methods can access You can’t prefix the definition of a top-level class or an interface with the keyword static. A top-level class or interface is one that isn’t defined within another class or interface.
  • 20. Primitive vs. Reference conversion a primitive variable contains its value, and conversion of a primitive variable means irreversible changes in its value casting a reference variable doesn’t touch the object it refers to, but only labels this object in another way, expanding or narrowing opportunities to work with it A reference is like a remote control to an object. The remote control has more or fewer buttons depending on its type, and the object itself is stored in a heap. When we do casting, we change the type of the remote control but don’t change the object itself.
  • 21. Primitive vs. Reference Upcastingis casting a subtype to a supertype, upward to the inheritance tree Unlike upcasting, downcasting can fail if the actual object type is not the target object type
  • 22. Primitive vs. Reference We can use == operators for reference comparison (address comparison) and .equals() method for content comparison. In simple words, == checks if both objects point to the same memory location whereas .equals() evaluates to the comparison of values in the objects.
  • 23. Variables Variables can have multiple scopes: class, instance, local, and method parameters. Instance variables are defined and accessible within an object. They’re accessible to all the instance methods of a class. Class variables are shared by all the objects of a class—they can be accessed even if there are no objects of the class Local and instance variables can be defined using the same name. In a method, if a local variable exists with the same name as an instance variable, the local variable takes precedence
  • 24. NOTE When you pass a primitive variable to a method, its value remains the same after the execution of the method. This doesn’t change, regardless of whether the method reassigns the primitive to another variable or modifies it.