Javappt
Javappt
A programming language
Fully buzzword-compliant:
do/while
switch
if/else
int i=5;
do { char
If(x==4) { // act1 c=IN.getChar();
// act1 i--; switch(c) {
} else { } while(i!=0); case ‘a’:
// act2 case ‘b’:
} for // act1
break;
int j;
default:
for(int i=0;i<=9;i++)
// act2
{
}
j+=i;
}
WHAT IS JDK
Java Development Kit is the core component of Java Environment and
provides all the tools, executables and binaries required to compile, debug
and execute a Java Program. JDK is a platform-specific software and that’s
why we have separate installers for Windows, Mac, and Unix systems. We
can say that JDK is the superset of JRE since it contains JRE with Java
compiler, debugger, and core classes. The current version of JDK is 11 also
known as java 11.
WHAT IS JVM?
A Java virtual machine (JVM) is a virtual machine that enables a computer to run
Java programs as well as programs written in other languages that are also compiled
to Java bytecode. The JVM is detailed by a specification that formally describes what
is required in a JVM implementation.
WHAT IS JRE?
JRE is the implementation of JVM, it provides a platform to execute java
programs. JRE consists of JVM and java binaries and other classes to execute
any program successfully. JRE doesn’t contain any development tools like java
compiler, debugger etc. If you want to execute any java program, you should
have JRE installed but we don’t need JDK for running any java program .
MAIN CONCEPTS
Object
Class
Inheritance
Encapsulation
OBJECTS
An object has identity
(each object is a distinct individual).
An object has state
(it has various properties,
which might change).
An object has behavior
(it can do things and
can have things done to it).
CLASS
Class is a blue print which is containing only list of variables and method and no
memory is allocated for them. A class is a group of objects that has common properties.
A class in java contains:
Data Member
Method
Constructor
Block
class Hello {
public static void main(String[] args) {
System.out.println(“Hello World !!!”); }
}
Is:
• In Java
Animal[][] arr=
new Animal[2][2]
NOTE:
An abstract class is not required to have an abstract method in it.
But any class that has an abstract method in it or that does
not provide an implementation for any abstract methods declared
in its superclasses must be declared as an abstract class.
Example
ABSTRACT - EXAMPLE
package java.lang;
public abstract class Shape {
public abstract void draw();
public void move(int x, int y) {
setColor(BackGroundColor);
draw();
setCenter(x,y);
setColor(ForeGroundColor);
draw();
}
}
package java.lang;
public class Circle extends Shape {
public void draw() {
// draw the circle ...
}
}
STATIC KEYWORD
The static keyword in Java is used for memory management mainly. We
can apply java static keyword with variables, methods, blocks and nested
class. The static keyword belongs to the class than an instance of the class.
It is used for a constant variable or a method that is the same for every
instance of a class.
The main method of a class is generally labelled static.
THIS KEYWORD
refers to “this” object (object in which it is used
Usage
with an instance variable or method of “this” class
as a function inside a constructor of “this” class
as “this” object, when passed as parameter
SUPER KEYWORD
reference variable that is used to refer parent class object. Super is an
implicit keyword created by JVM and supply each and every java program
for performing important role in three places.
At variable level
At method level
At constructor level
INTERFACE
*
- The correct term is “to implement” Example
an interface
INTERFACE
interface IChef {
void cook(Food food);
}
2) Unchecked Exception
The classes which inherit RuntimeException are known as unchecked exceptions e.g.
ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc.
Unchecked exceptions are not checked at compile-time, but they are checked at runtime.
3) Error
Error is irrecoverable e.g. OutOfMemoryError, VirtualMachineError, AssertionError etc.
Java Exception Handling Example
public class JavaExceptionExample{
public static void main(String args[]){
try{
//code that may raise exception
int data=100/0;
}
catch(ArithmeticException e)
{
System.out.println(e);
}
//rest code of the program
System.out.println("rest of the code...");
}
}
Output:
Exception in thread main
java.lang.ArithmeticException:/ by zero rest of the
code...
ANY
QUERIES