Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Saturday, 31 December 2016

JVM, JRE, JDK

 

Java Virtual Machine (JVM)

jvm,jre,jdk

Java virtual machine is an abstract machine. Java virtual machine is a software and it is a specification that provides runtime environment in which java bytecode can be executed. Java virtual machine is platform dependent. JVM, JRE and JDK platform dependent because configuration of each operating system differ. But java is pure independent programming language.

Java Virtual Machine perform some main task, these are
  • Loads code
  • Verifies code
  • Executes code
  • Provide runtime environment
Java virtual machine contains classloader and memory areas(class area(method areas), heap memory, stack memory).

Java Runtime Environment (JRE)

Java runtime environment , It is used to provide runtime environment in java. JRE is an implementation of jvm which actually executes java programs. It include the jvm , core libraries and other additional components to run application and applets written in java.

                              JRE = jvm + core libraries(e.g rt.jar files etc.) + other files


Java Development Kit (JDK)

Java development kit is used to develop and execute the java programs. jdk is bundle of software components that is used to develop java based application. JDK contains everything that will be required to develop and run java application. it contains JRE and other development tools e.g javac, java, etc.

                             JDK = JRE + development tools(e.g  javac , java, etc)


Difference between Java and C++



java
  • Java is platform-independent
  • Java is mainly used for application programming. It is widely used in desktop application, mobile application, enterprise application.
  • Java does not support pointers, templates, union, operator overloading, structures.
  • Java does not support multiple inheritance through a class. It can be achieved by interface in java.
  • Java support automatic garbage collection. Java does not support destructors.
  • Java does not support goto statement.
  • Java does not support conditional compilation inclusion.
  • Java has built in support for threads. There is a thread class in java that you inherit to create new thread and override the run() method.
  • Java uses compiler and interpreter both
  • Java support call by value only. Java does not support call by reference.
  • Java has built-in support for documentation comment e.g /**-----*/
  • Java has no virtual keyword. We can override all non-static method by default.
  • Java does not supports default arguments. In java there is no scope resolution operator (::).
C++
  • C++ is platform-dependent
  • C++ is mainly used for system programming
  • C++ supports pointers, templates, union, structures, operator overloading.
  • C++ support multiple inheritance.
  • C++ support destructors, Which is automatically invoked when object is destroyed
  • C++ supports goto statement.
  • C++ supports conditional compilation and inclusion.
  • C++ has no built-in supports for thread. C++ relies on non-standard third parties libraries for thread support.
  • C++ uses compiler only.
  • C++ support call by value and call by reference both.
  • C++ has not built-in support for documentation comment.
  • C++ supports virtual keywords so that we can decide whether or not override methods.
  • C++ supports default arguments. C++ has scope resolution operator(::), Which is used to define a method outside a class and to access a global variables within from the scope where a local variable also exists with the same name.

Share:

Sunday, 25 December 2016

Comments in Java

 

Comments

Comments are statements that are not executed by compiler and interpreter. Comments in java explain the actions of particular piece of code.They are used to provide summary of code in plain english to help future developers or people to better understand the code.


Comments In Java


There are 3 types of java comments

  1. single line comments
  2. multiline  comments
  3. documentation comments 

1)  Single line comment in java

Single line comment in java is used to comment only one line in java. Java single line comment starts with two forward slashes with no white space (//). If the comments exceeds one line then put two more consecutive slashes on next line and continue the comment.

Syntax:

//This is single line comment in java  
//I am single line comment in java programming language

For example:

class SingleLineComment
{
//this is main method in java
public static void main(String args[])
{
//i am single line comment
System.out.println("this is single line comment in java");
}


output: this is single line comment in java   

2) Multiple line  comment in java

Multiple line comment are used to comment multiple line in java. Java 's multi-line comment is a piece of text enclosed in slash-star (/*) and star-slash(*/) e.g /*-------*/.

Syntax:

/* this is multiple lines comment
   in java.
java is object oriented language 
java is secure programming language.
*/

For example:

class MultipleLineComment
{
public static void main(String[] args)
{
/* java is  high level
    and 
secure 
programming language */
System.out.println("multi line comment in java");
/* This is multi line comment in java 
programming language*/
}


output: multi line comment in java


3)  Documentation comment in java

The documentation comment in java is used to create document API. To create document API, you need javadoc tool. Javadoc is a tool which come with JDK and this javadoc tool is used for generating java code documentation in HTML format from the java source file(.java file). By using java documentation comments classes, fields, constructor and method are documented. Javadoc comment e.g /** documentation */.

Syntax:

/** this is documentation
  comment 
in 
java
*/


Javadoc Comments in program

Java documentation comments or Javadoc comment is placed just before the entity to be documented. It can be class, method, field, constructor

For example:

/** 
* First sentence of the comment should be a summary sentence .
* Documentation comment is written in HTML so it can contain html
* in description part.
* @author  Anurag Singh
* @since 2016
*/
public class  DemoOfJavadoc
{
/**
* main method
* @param args String[]
*/
public static void main(String[] args)
{
/**
* printing hello javadoc
*/
System.out.println("hello java doc");
}
}
  
save it DemoOfJavadoc.java

javac  DemoOfJavadoc.java

javadoc DemoOfJavadoc.java

  • now save it in particular directory or folder with extension .java file
  • compile it by javac tool (From cmd)
  • using javadoc tool, generate  html documentation file (From cmd)
  • now go to your current directory where you save java file
  • open html file


There are some Javadoc tags

  • @author
  • @version
  • @param
  • @return
  • @exception
  • @see
  • @since
  • @serial
  • @deprecated


Share:

Friday, 23 December 2016

Java Operator


Operators in java is a symbol that is used to perform mathematical , comparison, logical operations in java. java provides many operators to manipulate  variables.


Java Operator



Categories of Operators in java

 (1) Arithmetic Operators
 (2) Relation Operators
 (3) Assignment Operators
 (4) Logical Operators
 (5) Bitwise Operators etc...  


Arithmetic Operators

Arithmetic operators are used in mathemetical expression. for example 

Assume variable A holds 10 values and  variable B hods 20 value

(1)   + (Addition)

 A + B = 30; //add values on either sides of the operators

(2)  - (Subtraction)  

 A - B = -10; //subtract right hand operand from left hand operand

(3)  * (Multiplication)

 A * B = 200; //multiplies values on either sides of the operators

(4)  / (Division) 

 B / A = 2; //divides left hand operand by right hand operand

(5)  % (Modulus)

 B  % A = 0; //divides left hand operand by right hand operand and returns remainder

(6)  ++ (Increment)

 A++ = 11; //increases the value of operand by 1 

(7)  --  (Decrement)

 A-- = 9; //decreases the value of operand by 1   

 Operand here A and B is operand e.g A + B 
A is operand
B is operand 
+ is operator



Relational Operators

Relational operators return boolean or logical result(true or false)

 Assume variable A holds 10 values and  variable B hods 20 value 

(1)  == (equal to)

(A == B) is not true. //Checks if the values of two operands are equal or not . if yes then condition becomes true. 

(2)  != ( not equal to)

(A !== B) is  true. //Checks if the values of two operands are equal or not . if not then condition becomes true.

(3) >(greater than)

(A > B) is not true. Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.

(3) <(less than)

(A < B) is  true. Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true.

(4) >= (greater than or equal to)

(A >= B) is not true. Checks if the value left operand is greater than or equal to the value of right operand, if yes then condition becomes true.

3) <=(less than or equal to)

(A <= B) is  true. Checks if the value of left operand is less than or equal to value of right operand, if yes then condition becomes true.



Assignment Operators

Assume there is three variables a =10, b=20, c

(1)  = (Simple Assignment Operator)

c = a + b; //assign a value of a + b into c variable 30

(2)  += (Add AND Assignment Operator)

c += a; //c += a is equivalent to c = c + a 

(3)  -= (Subtract AND Assignment Operator)

c -= a; //c -= a is equivalent to c = c - a;

(4)  *= ( Multiply AND Assignment Operator)

c *= a; //c *= a is equivalent to c = c * a;

(5)  /= (Divide AND Assignment Operator)

c /= a; //c /= a is equivalent to c = c / a;

(6)  %= (Modulus AND Assignment Operator)

c %= a; //c %= a is equivalent to c = c % a;

(7)  <<= (Left Shift AND Assignment Operator)

c <<= 2; //c <<=2  is equivalent to c = c << 2

(8)  >>= (Bitwise AND Assignment Operator)

c >>= 2; //c >>=2  is equivalent to c = c >> 2


Logical Operators

Assume boolean variable A hold true and B hold false value

(1)  && (logical AND Operator)

(A && B) is false //if both the operand A and B are non-zero then condition becomes true.

(2)  || (logical OR Operator)

(A || B) is true //if any of the two operand A and B are non-zero then condition becomes true.

(3)  ! (logical NOT Operator)

!(A && B) is true //use to reverses the logical state of  it operand. if the condition is true logical NOT operator make it false.

 
Share:

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate