JAVA Language and Programming
JAVA Language and Programming
AND
PROGRAMMING
CONTENTS
◦ For setting the permanent path of JDK, you need to follow these steps:
Go to MyComputer properties -> advanced tab -> environment variables -> new tab of user
variable -> write path in variable name -> write path of bin folder in variable value -> ok -> ok -
> ok
JDK, JRE, and JVM
JDK: Java Development Kit
JRE: Java Runtime Environment
JVM: Java Virtual Machine
1) A variable declared inside
the body of the method is
called local variable. You
can use this variable only
within that method and the
other methods in the class
aren't even aware that the
variable exists.
2) A variable declared inside
the class but outside the
body of the method, is
called instance variable. It
is not declared as static.
3) A variable which is
declared as static is called
static variable.
Data Types
In programming languages,
loops are used to execute a set
of instructions/functions
repeatedly when some
conditions become true. There
are three types of loops in Java.
JAVA Object Class
◦ An entity that has state and behavior is known as an object e.g., chair, bike, marker, pen, table, car, etc. It can be physical or
logical (tangible and intangible). The example of an intangible object is the banking system whereas 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.
Naming Convention
By using standard Java naming conventions, you make your code easier to read for yourself and other programmers.
Readability of Java program is very important. It indicates that less time is spent to figure out what the code does.
◦ The following are the key rules that must be followed by every identifier:
◦ The name must not contain any white spaces.
◦ The name should not start with special characters like & (ampersand), $ (dollar), _ (underscore).
◦ Let's see some other rules that should be followed by identifiers.
Class
◦ It should start with the uppercase letter.
◦ It should be a noun such as Color, Button, System, Thread, etc.
◦ Use appropriate words, instead of acronyms.
Continue
Method
◦ It should start with lowercase letter.
◦ It should be a verb such as main(), print(), println().
◦ If the name contains multiple words, start it with a lowercase letter followed by an uppercase letter such as actionPerformed().
Variable
◦ It should start with a lowercase letter such as id, name.
◦ It should not start with the special characters like & (ampersand), $ (dollar), _ (underscore).
◦ If the name contains multiple words, start it with the lowercase letter followed by an uppercase letter such as firstName,
lastName.
◦ Avoid using one-character variables such as x, y, z.
Continue
CamelCase in java naming conventions
◦ Java follows camel-case syntax for naming the class, interface, method, and variable.
◦ If the name is combined with two words, the second word will start with uppercase letter always such as actionPerformed(),
firstName, actionEvent, actionListener, etc.
OOPs Concepts
◦ Object means a real-world entity such as a pen, chair, table, computer, watch, etc. Object-Oriented Programming is a
methodology or paradigm to design a program using classes and objects. It simplifies software development and maintenance
by providing some concepts:
◦ Object
◦ Class
◦ Inheritance
◦ Polymorphism
◦ Abstraction
◦ Encapsulation
Types of Inheritance
Continue…
Polymorphism
◦ Polymorphism in Java is a concept by which we can perform a single action in different ways. Polymorphism is derived from
2 Greek words: poly and morphs. The word "poly" means many and "morphs" means forms. So polymorphism means many
forms.
◦ There are two types of polymorphism in Java: compile-time polymorphism and runtime polymorphism. We can perform
polymorphism in java by method overloading and method overriding.
◦ Runtime polymorphism or Dynamic Method Dispatch is a process in which a call to an overridden method is resolved at
runtime rather than compile-time.
◦ In this process, an overridden method is called through the reference variable of a superclass. The determination of the method
to be called is based on the object being referred to by the reference variable.
Continue…
Upcasting
◦If the reference variable of Parent class refers
to the object of Child class, it is known as
upcasting. For example:
◦class A{}
◦class B extends A{}
◦A a=new B();//upcasting
Continue…
Method Overloading...
◦ If a class has multiple methods having same name but different in parameters, it is known as Method
Overloading.
◦ If we have to perform only one operation, having same name of the methods increases the readability of the
program.
◦ Suppose you have to perform addition of the given numbers but there can be any number of arguments, if
you write the method such as a(int,int) for two parameters, and b(int,int,int) for three parameters then it may
be difficult for you as well as other programmers to understand the behavior of the method because its name
differs.
There are two ways to overload the method in java
◦ By changing number of arguments
◦ By changing the data type
Continue…
◦ 1) Method Overloading: changing no. of arguments
◦ 2) Method Overloading: changing data type of arguments
◦ 3) Why Method Overloading is not possible by changing the return type of method only?
◦ 4) Can we overload java main() method?
Yes, by method overloading. You can have any number of main methods in a class
by method overloading. But JVM calls main() method which receives string array as
arguments only. Let's see the simple example.
◦ public static void main(String[] args){System.out.println("main with String[]");}
◦ public static void main(String args){System.out.println("main with String");}
◦ public static void main(){System.out.println("main without args");}
Instance Initializer Block
Inheritance:
◦ When one object acquires all the properties and behaviors of a parent object, it is known as inheritance. It provides code
reusability. It is used to achieve runtime polymorphism.
Continue
Polymorphism
◦ If one task is performed in different ways, it is
known as polymorphism. For example: to
convince the customer differently, to draw
something, for example, shape, triangle,
rectangle, etc.
◦ In Java, we use method overloading and method
overriding to achieve polymorphism.
◦ Another example can be to speak something; for
example, a cat speaks meow, dog barks woof,
etc.
THANK YOU!!!