Friday, 15 December 2017

Operators in Java

Operators in Java


Operators are the symbols which are use to perform operations in Java program like +,-,/,* etc...

Types of Operator:

  1. Arithmetic operator
  2. Relational operator
  3. Logical operator
  4. Bitwise operator
  5. Assignment operator
  6. Shift operator
  7. Ternary operator
  8. Unary operator

Here we have the symbol orientation of Operators:



Operator NameSymbol
Unaryx++(post Increment), ++x(Pre Increment)
x--(Post decrement), --x(Pre decrement)
Arithmetic(+, -, *, /, %)
Shift<<, >>
Relational<, >, <=, >=, ==, !=
Bitwise&, ^, |
Logical&&, ||
Ternary? :
Assignment=

 

Arithmetic Operator Example:



Unary Operator Example:



Shift Operator Example:



Relational Operator Example:



Bitwise and Logical Operator:

Thursday, 14 December 2017

Data Types

Data Types


Data-types indicates the type of data which helps variable to store the value according to the data-type.

In java there are two types of data types present:

  1. Permitive
  2. Non-Permitive
DataTypes

How to initialize data type with variable:


Variable

Variable

Variable is name of memory, which use to allocate reserve memory location. It is also called as "VARY+ABLE" which means vary can be changed.

Here a is used to allocate memory to variable


Types of Variable:


  1. Local Variable: Which is initialize inside the method is called as local variable.

  2. Instance Variable: Which is initialize inside the class but outside the method is known as Instance variable.

  3. Static Variable: A variable which is declared as Static is known as static variable, A static variable can not be used as local variable.


Example


public class Second
{
static int a = 10;//Global Variable
static int c;// instance Variable
public static void main(String[] args)
{
   int b = 20;// Local Variable
  
   c=a+b;
   System.out.println(c);
    }
}

Thursday, 7 December 2017

How to Create and Run First Java program

First Java Program

How to write a java code. After installation of java it will be more easy to write code in java. Let's start with the programming:

  • First open your notepad and write the code in it :



  • After writing the code save the file in your system like I saved my file in E:\ drive :
  • Now after saving open your command prompt window and type javac with class name i.e Hello tp compile the profram:: type javac Hello.java and hit enter.
  • Then to run the program and see the output on command window type java.Hello

Difference between JDK, JRE and JVM?

Difference between JDK, JRE and JVM?


JDK :-   Java Development Kit(JDK) provides an environment to develop and executes the Java Program. If you(as as Developer or Learner) want to make an program on Java, first you need JDK installed in your machine which is easily available on Oracle website. JDK includes two things, first is development tool(Which provides environment to develop the program or application) and second is JRE(which provides environment to executes the program on your machine).

JRE :- Java run-time environment is a installation package which only provide environment to execute the program not to develop on your machine.

JVM :- JVM is the most important part for both JDK and JRE. JVM is pre-installed in both, whatever java code you wants to execute or to develop goes into JVM and JVM is only responsible to code line by line. In other words you can say JVM works as a interpreter.

Installation of Java

Installation of Java

Installation of Java software is very easy. Here are the steps that how to install java and how to set path in your PC-

  1. First you need to download the software. you can directly download the software from this link http://www.oracle.com/technetwork/java/javase/downloads/index.html.
  2. After finish downloading make right click on software setup and run it as administrator.
  3. Accept all the terms and condition and let the software install.
After Installing the Java JDK(Java Development kit), set the path for compiling and executing the java program. let's follow the steps and set the path in your machine :

->First you need to Go to MyComputer properties 


-> click on Advance system settings


-> advanced tab and then environment variables 


-> new tab of user variable 


-> Copy java installed path from c drive location


-> write path of bin folder in variable value like below 


and then hit OK to set path. Now you are ready to develop your first program.

How to Check Java is installed in your machine or not?

Just open command prompt in you machine and type java -version and click enter

Difference between C++ and Java

Difference between C++ and Java


C++ supports both procedural and object oriented programming

C++ and Java originate from the same point, i.e. the C language and Both Java and C++ support object oriented programming, yet there are differences between them-
  • C++ is platform-dependent.
  • C++ generates object code and the same code may not run on different platforms.
  • C++ support destructors, which is automatically invoked when the object is destroyed.
  • C++ is mainly used for system programming.
  • C++ uses compiler only.
  • C++ supports structures and unions.
  • C++ supports both method and operator overloading.
  • C++, you may not include the try/catch even if the function throws an exception.
  • C++ has no built in support for threads.

Java is object oriented programming language

  • Java is platform-independent.
  • Java is interpreted for the most part and hence platform independent.
  • Java support automatic garbage collection. It does not support destructors as C++ does.
  • Java is mainly used for application programming. It is widely used in window, web-based, enterprise and mobile applications.
  • Java uses compiler and interpreter both.
  • Java doesn't support structures and unions.
  • Java has method overloading, but no operator overloading.
  • Exception handling in Java is different because there are no destructors. Also, in Java, try/catch must be defined if the function declares that it may throw an exception.
  • Java has built in support for threads.
  • Unlike C++, Java does not support pointers, multiple inheritance, global variables, templates or classes.

Wednesday, 6 December 2017

Java Reserved Keywords

Java Reserved Keywords


In java programming some identifier names can't be used as variable, class or object is known as Reserved keywords.

Here are the keywords according to their categories.

Reserved keywords for Data-types:

  1. byte
  2. short
  3. int
  4. long
  5. float
  6. double
  7. char
  8. Boolean

Reserved keywords for flow control:

  1. if
  2. else
  3. switch
  4. case
  5. break
  6. continue
  7. default
  8. return
  9. for
  10. while
  11. do

Keywords for Modifiers:

  1. public
  2. protected
  3. private
  4. static
  5. final
  6. native
  7. transient
  8. abstract
  9. native
  10. volatile
  11. synchronized

Keywords for Exception Handling:

  1. try
  2. catch
  3. finally
  4. throw
  5. throws
  6. assert

Keywords for class related:

  1. class
  2. package
  3. import
  4. extends
  5. implements
  6. interface

Object related Keywords:

  1. new
  2. this
  3. super
  4. instanceof

Other keywords:

  1. void
  2. goto
  3. null
  4. strictfp**
  5. enum

Monday, 4 December 2017

What is Java?

Introduction of Java


Java is a High-Level programming language and is Platform independent. Java is Robust, Secured and Object-Oriented programming language.

Java is platform independent which means any hardware and software environment in which a Java program run. Java is also known as platform, since java has its own run time environment(JRE) and API's.

Java was officially released in 1995 by Sun Microsystems and currently owned by Oracle.

    Features of Java

    The main objective of Java programming language creation was to make it portable, simple and secure programming language. Apart from this, there are also some awesome features which play important role in the polularity of this language. The features of Java are also known as java buzzwords. Following is a list of most important features of Java language. The Java Features given below are simple and easy to understand.

    Image result for features of java'
    1. Simple
    2. Object-Oriented
    3. Portable
    4. Platform independent
    5. Secured
    6. Robust
    7. Architecture neutral
    8. Dynamic
    9. Interpreted
    10. High Performance
    11. Multithreaded
    12. Distributed

      Applications of Java:

      1. Standalone Applications
      2. Web Applications
      3. Enterprise banking applications
      4. Robotics and Gaming
      5. Mobile and Tablet Applications
      6. Embedded Systems and Smart Card

      Different Editions of Java:

      1. Java Standard Edition(J2SE):- This is used for making standalone applications and applets.
      2. Java Enterprise Edition(J2EE):- This is used to make complex applications according to small industry to large industry requirements.
      3. Java Micro Edition(J2ME):- This is to make application on Mobile, Tablets and on Embedded Systems.

      History about Java


      James Gosling

      History of Java is very Interesting. Java was originally developed by James Gosling in 1995 at Sun Microsystems. Firstly this was known as "GreenTalk" because this was initiated in June 1991 by James Gosling, Mike Sheridan and Patrick Naughton. This team was known as green team of Sun Microsystems.

      Then after, it is known as OAK(Tree). Because OAK is a symbol of strength. And in 1995 the official name released by James Gosling was "Java".

      And official JDK 1.0 version was released in January 23rd, 1996.

      Java is a Object Oriented programming (OOPS) and High Level Language.

      What is Java

      1. Java is a programming language and a platform.
      2. Java is a high level, robust, secured and object-oriented programming language.

      Platform: Any hardware or software environment in which a program runs, is known as a platform. Since Java has its own runtime environment (JRE) and API, it is called platform.

      Java Example 

      class Simple{
         public static void main(String args[]){ 
           System.out.println("Hello Java");   
          }
        }