Friday, 30 October 2020
Java Development kits ( JDK )
Java Development kits ( JDK )
The JDK comes with a set of tools that are used for developing and running Java program . It includes:
1. Appletviewer ( It is used for viewing the applet )
2. Javac ( It is a java Compiler )
3. Java ( It is a java Interpreter)
4. Javap ( java diassembler, which convert byte code into program description )
5. Javah ( It is for java C header files )
6. Javadoc ( It is for creating HTML document )
7. Jdb ( It is java debugger )
For compiling and running the program we have to use following commands :-
(a) javac ( java compiler ) :-
In java , we can use any text editor for writing program and then save that program with "java" extension . Java compiler converts the source code or program in bytecode and interpreter convert " java " file in "class" file .
syntax :-
C:\javac filename.java
if my filename is "abc.java" them the syntax will be:
C:\javac abc.java
(b) java ( Java interpreter ) :-
We can use any text editor for writing program and then save that program with "java" extension . Java compiler converts the source code or program in bytecode and interpreter convert "java" file in "class" file .
syntax :-
C:\ java filename
if my filename is abc. java then the syntax will be:
C:\ java abc
Simple Java program
Simple Java program
Consider a simple java program below :-
class FirstProgram
{
public static void main(String args[])
{
System.out.println ("This is my first program ");
}
}
1. The file must be named " FirstProgram .java" to equivalent the class name containing the main method .
2. Java is case sensitive. This program defines a class called "FirstProgram ".
3. A class is an object oriented term . It is designed to perform a specific task . A java class is defined by its class name , an open curly brace, a list of methods and fields, and a close curly brace.
4. The name of the class is mode of alphabetical charecters and digits without spaces, the first charecter must be alphabetical.
5. The line public static void main(String args[]) shows where the program will start running . The world main means that this is the main method and the JVM starts running any program by executing this method first.
6. The main method in "FirstProgram.java" consists of a single statement :
System.out.println ("This is my first program ");
The statement outputs the character between quotes to the console.
JVM architecture
JVM architecture:-
If we start learning java , we would want to learn full details of how JVM really functioning . Here is JVM architecture .
JVM has various sub components internally .
1. Class loader sub-system : JVM 's class loader sub - system perform 3 tasks
(a). It loads class file into memory
(b). It verified byte code instructions
(c). It allots memory required for the program.
2. Run time data area : This is the memory resource used by JVM and it is divided into 5 parts :-
a. Method area - Method area stores class code and method code.
b. Heap - Objects are created on heap.
c. Java stacks - Java stacks are the places where the java methods are executed.A java stacks contains frames . On each frame, a separate method is executed.
d. Program counter registers - The program counter registers store memory address of the instruction to be executed by the micro-processor.
e. Native mathod stacks - The native method stacks are places where native methods ( for example, C language programs ) are executed . Native method is a function , which is written in another language other than Java.
Native method interface
Native method library
Execution engine
Java is not 100% pure object-oriented language
Java is not 100% pure object-oriented language because of following reasons:-
1. Everything in Java is not considered as a Object , there are primitive data types available.
example - For numbers we are using the int which is not a object type. ( only integer is object type ).
2. All feature of OOPS language is not fully supported by Java .
example - Multiple inheritance, operator overloading , etc.
For a pure object oriented language , there should be 6 features available with it . They are :-
1. Encapsulation / Information Hiding .
2. Inheritance.
3. Polymorphism/ Dynamic Binding .
4. All pre -defined type should be objects.
5. All operation performed by sending messages to Objects.
6. All user - defined type are objects .
But in java , features 4 and 5 are lacking . That 's why it is not 100% pure object oriented programming language.
JVM ( Java Virtual Machine )
What is JVM ( Java Virtual Machine ) ?
JVM ( Java Virtual Machine ) :-
All programming language compilers convert the source code to machine code . Same job done by Java Compiler to run a Java program, but the difference is that Java compiler convert the source code into intermediate code is called as bytecode .This machine is called the Java Virtual Machine and it exists only inside the computer memory .
following figure shows the process of compilation :
Java program -----Java compiler -----Virtual machine code
The Virtual machine code is not machine specific . The machine specific code is generated . By java interpreter by acting as an intermediary between the virtual machine and real machine shown below:-
Byte code ---Java interpreter---- Machine code
Java Object Framework act as the intermediary between the user programs and the virtual machine which in turn act as the intermediary between the operating system and the Java Object Framework.
Difference between C++ and JAVA
Difference between C++ and JAVA
JAVA
1. Java is true Object-Oriented language.
2. Java does not support operator overloading .
3. It supports lables with loops and statement blocks.
4. Java does not have template classes as in C++.
5. Java compiled into byte code for the java virtual machine . The source code is independent on operating system .
6. Java does not support multiple inheritance of classes but it supports interface.
7.Runs in a protected virtual machine .
8. Java does not support global variable variable .Every variable should declare in class.
9. Java does not use pointe.
10. It Strictly enforces an object oriented programming paradiam.
11. There are no header files in java.
12. De - allocation of memory will be take care of by JVM.
13. Java supports 4 access specifiers : Private ,Public, Protected and Deault.
14. Only constructors are there in java . No destructors are available.
DIFFERENCE
C++
1. C++ is basically C with Object -Oriented extension.
2. C++ supports operator overloading .
3. It supports goto statement .
4. C++ has template classes.
5. Source code can be written to be plateform independent and written to take advantage of platform . C++ typically compiled into machine code.
6. C++ supports multiple inheritance of classes.
7. Exposes low -level system facilities.
8. C++ support global variable.
9. C++ uses pointer .
10. It allow both procedural programming and object - oriented programming .
11. We have to use header file in C++.
12. De -allocating memory is the responsibility of the programmer.
13. There are 3 access specifiers in C++ : Private , Public and Protected.
14. There are constructors and deconstructors in C++.
Thank you 💖
Subscribe to:
Posts (Atom)
Student Marks Calculation app using java
import javax.swing. *; import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; public class Student { private J...
-
The Type Promotion Rules :- Java defines several type promotion rules that apply to expressions. They are as follows : all byt...
-
import javax.swing. *; import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; public class Student { private J...
-
Features of Java Java Buzzwords The following are the list of buzzwords of Java:- 1. Simple 2. Secure 3. Portable 4...