Documente Academic
Documente Profesional
Documente Cultură
• Feature of Java, JVM, JRE, class path, classes, fields, access control,
objects creation, initialization, methods, this, overloading methods,
main method, native methods, class design, lexical elements, types
and literals, variables, array variables, naming, operators, expressions,
member access, precedence, associativity, statements & blocks, if-
else, switch, while and do-while, for, labels, break, continue, return,
goto.
Features of Java
• Simple
• Secure
• Portable
• Object-oriented
• Robust
• Multithreaded
• Architecture-neutral
• Interpreted
• High performance
• Distributed
• Dynamic
Difference between JDK, JRE, and JVM
• JDK is an acronym for Java Development Kit. The Java Development Kit
(JDK) is a software development environment which is used to develop
Java applications and applets. It physically exists. It contains JRE +
development tools.
JRE
• JRE is an acronym for Java Runtime Environment. It is also written as
Java RTE. The Java Runtime Environment is a set of software tools
which are used for developing Java applications. It is used to provide
the runtime environment. It is the implementation of JVM. It physically
exists. It contains a set of libraries + other files that JVM uses at
runtime.
JVM
• JVM (Java Virtual Machine) is an abstract machine. It is called a virtual
machine because it doesn't physically exist. It is a specification that
provides a runtime environment in which Java bytecode can be
executed. It can also run those programs which are written in other
languages and compiled to Java bytecode.
• There are three types of variables in java: local, instance and static.
Types of Variables
• There are three types of variables in java:
• local variable
• instance variable
• static variable
Example to understand the types of variables in java
• class A{
• int data=50;//instance variable
• static int m=100;//static variable
• void method(){
• int n=90;//local variable
•}
•}
Data Types in Java
• Data types specify the different sizes and values that can be stored in
the variable. There are two types of data types in Java:
• Primitive data types: The primitive data types include boolean, char,
byte, short, int, long, float and double.
Syntax:
if(condition){
//code to be executed
}
//Java Program to demonstate the use of if statement.
• private
• default
• protected
• public
private access modifier
• The private access modifier is accessible only within class.
• Role of Private Constructor
• If you make any class constructor private, you cannot create the instance
of that class from outside the class. For example:
• In this example, we have created two classes A and Simple. A class contains
private data member and private method. We are accessing these private
members from outside the class, so there is compile time error.
default access modifier
• If you don't use any modifier, it is treated as default by default. The
default modifier is accessible only within package.
• The method must have the same name as in the parent class
• The method must have the same parameter as in the parent class.
• There must be an IS-A relationship (inheritance).
Understanding the problem without method overriding
Constructor in Java
• Constructor is a special type of method that is used to initialize the object.
• Constructor is invoked at the time of object creation. It constructs the
values i.e. provides data for the object that is why it is known as constructor.
• class Bike{
•
• Bike(){System.out.println("Bike is created");}
•
• public static void main(String args[]){
• Bike b=new Bike();
•}
•}
• Rule: If there is no constructor in a class, compiler automatically
creates a default constructor.
• What is the purpose of default constructor?
• 0 null
• 0 null
• PARAMETERIZED CONSTRUCTOR
Constructor must not have return type. Method must have return type.
The java compiler provides a default Method is not provided by compiler in any
constructor if you don't have any case.
constructor.
Constructor name must be same as the Method name may or may not be same as
class name. class name.