Category: Java Tutorial

  • Static block in Java

    A static block in a program is a block which is associated with a static keyword. The static block executes when the classloader loads the class. A static block is invoked before the main() method in java.

    Syntax:

    .........
    static {
    .......statements
    }
    .......

    Let us go through a static block example.

    Static block in Java with Example

    class StaticTest
    {
    	//static integer is declared
    	static int num;
    
            //static block
    	static
       
    	{
    		num = 100;	//assigned the value
    		System.out.println("This is Static block!");
    	}
    }
    
    //Main driver
    public class Main
    {
    	public static void main(String args[])
    	{
    		//printing the num value, but will be printed atlast
    		System.out.println(StaticTest.num);
    	}
    }

    Output:

    This is Static block!
    100

    As you can see, the static block is executed first, and then the Main function in the above program.


  • Java – Increment and Decrement Operator

    The ++ and the – – are Java’s increment and decrement operators. ++ is used to increase the value by 1 and – – is used to decrease the value by 1. There are two kinds of Increment and Decrement Operators.

    They are:

    • Post-Increment or Post-Decrement:
      First, the value is used for operation and then incremented or decremented. Represented like a++ or a–.
    • Pre-Increment Pre-Decrement:
      Here First the value is incremented or decremented then used for the operation. Represented like ++a or – –a.

    Example on Increment and Decrement Operator in java

    //This program demonstrates the ++ and -- operators.
    
    public class IncrementDecrement
    {
       public static void main(String[] args)
       {
          int number = 10;
    
          //Original Value
          System.out.println("Original value: " + number);
    
          //Incrementing the number.
          number++;
    
          //Value after incrementing
          System.out.println("After Incrementing: " + number);
    
          // Decrement number.
          number--;
    
          // Display the value in number.
          System.out.println("Again, after decrementing " + number);
       }
    }

    Output: After execution following result will be displayed.

    Original value: 10
    After Incrementing: 11
    Again, after decrementing 10

    Limitations of Increment and Decrement Operators:

    Increment and decrement operators can only be applied to variables but not on constant values. If we apply on canstants then we will get a compile-time error.

    int x = 10;       
    int y = ++10; // this will through compile-time error.

    Example of Pre increment and Post increment in java:

    a = 4;
    i = ++a + ++a + a++;
    i = 5 + 6 + 6;
    (a = 7)

    The above shows the use of a++ and ++a and at the end, if you print the value of a, you will get 7 as the value of a.

    Pre-increment: (++a)

    The major point to remember is that ++a increments the value and immediately returns it.

    Post-increment: (a++)

    a++ also increments the value but returns an unchanged value of the variable. It does not return the value immediately but if it is executed on the next statement then a new value is used.

    Example of Pre decrement and Post decrement in java:

    a = 4;
    i = --a + --a + a--;
    i = 3 + 2 + 2;
    (a = 1)

    Pre-decrement: (a)

    The major point to remember is that ––a decrements the value and immediately returns it.

    Post-decrement: (a)

    a–– also decrements the value but returns an unchanged value of the variable. It does not return the value immediately but if it is executed on the next statement then a new value is used.


  • Java – Relational Operator

    Comparison operators are used to comparing two values and return boolean results. These operators are used to check for relations like equality, greater than, less than between two values.

    They are used with a loop statement and also with if-else statements.

    Following are the Relational operators in Java:

    OperatorNameExample
    ==Equal to.A == B
    !=Not equal.A != B
    >Greater than.A > B
    <Less than.A < B
    >=Greater than or equal to.A >= B
    <=Less than or equal to.A <= B

    Java Program for Relational Operator

      public class Relational 
      {
    
        public static void main(String args[]) 
        {
        int x = 10;
        int y = 20;
    
        System.out.println("Is x == y = " + (x == y) );
        System.out.println("Is x != y = " + (x != y) );
        System.out.println("Is x > y = " + (x > y) );
        System.out.println("Is x < y = " + (x < y) );
        System.out.println("Is y >= a = " + (y >= x) );
        System.out.println("Is y <= a = " + (y <= x) );
        
        //Demonstration to use it with if-else 
        if(x==y){
            System.out.println("X is equal to y"); 
        }
        else{
            System.out.println("X is not equal to y" );
        }
        
       }
      }

    Output:

      Is x == y = false
      Is x != y = true
      Is x > y = false
      Is x < y = true
      Is y >= a = true
      Is y <= a = false
      X is not equal to y

  • Java – Logical Operator

    Logical Operators are used in conditional statements and loops for evaluating a condition with binary values.

    All of the binary logical operators combine two boolean values that are true and false to form a result value.

    Logical Operators with their description:

    OperatorDescriptionExample
    && (logical and)If both the operands are non-zero, then the condition becomes true.(X && Y) is false
    || (logical or)If any of the two operands are non-zero, then the condition becomes true.(X || Y) is true
    ! (logical not)Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.!(X && Y) is true

    Java Program for Logical Operator

      public class Logical 
      {
        public static void main(String args[]) 
        {
        boolean x = true;
        boolean y = false;
    
        System.out.println("&& (logical and) = " + (x&&y));
        System.out.println("|| (logical or) = " + (x||y) );
        System.out.println("! (logical not) = " + !(x&&y));
        }
      }  

    Output:

     && (logical and) = false
     || (logical or) = true
     ! (logical not) = true

  • Ternary Operator in Java

    Ternary Operator is also known as the Conditional operator. It is used to evaluate Boolean expressions. We can say that it is a short version of the if-else statement. But here instead of operating on two operands, it operates on three operands, and therefore the name ternary.

    Syntax: of Ternary Operator:

    variable num1 = (expression) ? value if true : value if false


    Java Program for Ternary Operator :

      public class Ternary 
      {
        public static void main(String args[]) 
        {
        int number1, number2;
        number1 = 30;
            
        number2 = (number1 == 15) ? 200: 400;
        System.out.println( "For false, value of number2 is: "+number2);
        
        /* number1 is not equal to 15 the second value after colon that is false value is assigned to the variable number2 */
    
        number2 = (number1 == 30) ? 200: 400;
        System.out.println( "For true, value of number2 is: "+number2);
        
        /* number1 is equal to 30 so the first value that is the true value is assigned to the variable number2 */
        }
      }  

    Output:

    For false, value of number2 is: 400
    For true, value of number2 is: 200


  • Java – Assignment Operator

    Assignment operator is used to assigning a value to any variable. This operator assigns the value of the righthand side of an operator to the lefthand side. Various assignment operator in Java:
    These are the short version formed by combining the two operators.

    For example Instead of writing, we can write a+= 5.

    • Assignment operator: ‘=’ This operator assigns the value on the right to the variable on the left.
      a = 20; B = 30; Ch = 'cha';
    • Add AND assignment operator: ‘+=’ This operator first adds the current value of the variable on the left to the value on the right and then assigns the result to the variable on the left.
      c+=7; a+=b;
    • Subtract AND assignment operator: ‘-=’ This operator first subtracts the current value of the variable on the left from the value on the right and then assigns the result to the variable on the left.
      c-=7; a-=b;
    • Multiply AND assignment operator: ‘*=’ This operator first multiplies the current value of the variable on the left to the value on the right and then assigns the result to the variable on the left.
      c*=7; a*=b;
    • Divide AND assignment operator: ‘/=’ This operator first divides the current value of the variable on the left by the value on the right and then assigns the result to the variable on the left.
      c/=7; a/=b;
    • Modulus AND assignment operator: ‘%=’ It takes modulus using two operands and assigns the result to the left operand.
      C %= A is equivalent to C = C % A ;
    • Right shift AND assignment operator: ‘>>=’ This operator is used for Right shift Operation.
      C >>= 2 ;
    • Left shift AND assignment operator: ‘<<=’ This operator is used for Left shift Operation.
      C <<= 2 ;
    • Bitwise AND assignment operator: ‘&=’ This operator is used for Bitwise AND Operations.
      C &= 2;
    • Bitwise exclusive OR and assignment operator: ‘^= This operator is used for Bitwise exclusive OR Operations.
      C ^= 2;
    • Bitwise inclusive OR and assignment operator: ‘|= This operator is used for Bitwise inclusive OR.
      C |= 2;

    Example of Assignment Operator:

      public class AssignmentOperator 
      {
        public static void main(String args[]) 
        {
        int number1 = 100;
        int number2 = 10;
    
        number2 += number1;
        number2 -= number1;
        number2 *= number1;
        number2 /= number1;
        number2 %= number1;
    
    
        System.out.println(" Result of +=: "+number2);
        System.out.println(" Result of -=: "+number2);
        System.out.println(" Result of *=: "+number2);
        System.out.println(" Result of /=: "+number2);
        System.out.println(" Result of %=: "+number2);
        }
      }  

    Output:

     Result of +=: 110
     Result of -=: 90
     Result of *=: 1000
     Result of /=: 10
     Result of %=: 0

  • Java – Arithmetic Operators

    1. Arithmetic Operators: 

    They are used to perform basic arithmetic operations. They perform on primitive data types.
    They are:

    • * : Multiplication
      Multiplies two values
      Example: x * y;
    • / : Division
      Divides one value from another
      Example: x / y;
    • % : Modulo
      Returns the division remainder
      Example: x % y;
    • + : Addition
      Adds together two values
      Example: x + y;
    • – : Subtraction
      Subtracts one value from another
      Example: x - y;

    Example of Arithmetic Operator

    public class ArithmeticOperator 
    {
     public static void main(String args[]) 
     {
        int number1 = 100;
        int number2 = 10;
        
        System.out.println("Addition: " + (number1 + number2) );
        System.out.println("Subtraction: " + (number1 - number2) );
        System.out.println("Multiplication: " + (number1 * number2) ); 
        System.out.println("Division: " + (number1 / number2) );
        System.out.println("Modulo: " + (number1 % number2) );
     }
    }  

    Output:

    Addition: 110
    Subtraction: 90
    Multiplication: 1000
    Division: 10
    Modulo: 0

  • Java – Bitwise Operator

    Bitwise operator works on bits and performs a bit-by-bit operation. There are six Bitwise Operators and can be applied to the integer types, long, int, short, char, and byte.

    List of Bitwise Operator in Java:

    • Bitwise AND: ‘&’
      Binary AND Operator copies a bit to the result if it exists in both operands.
    • Bitwise OR: ‘|’
      Binary OR Operator copies a bit if it exists in either operand.
    • Bitwise XOR: ‘^’
      Binary XOR Operator copies the bit if it is set in one operand but not both.
    • Binary Left Shift: ‘<<’
      TThe left operands value is moved left by the number of bits specified by the right operand.
    • Binary Right Shift: ‘>>’
      The left operand’s value is moved right by the number of bits specified by the right operand.
    • Bitwise complement: ‘~’
      Binary Ones Complement Operator is unary and has the effect of ‘flipping’ bits.
    • zero-fill right shift: ‘>>>’
      The left operands value is moved right by the number of bits specified by the right operand and shifted values are filled up with zeros.

    Java Program for Bitwise Operator :

    public class Bitwise 
      {
        public static void main(String args[]) {
    
        int number1 = 11;  /* 15 = 00001011 */
        int number2 = 22;  /* 10 = 00010110 */
        int output = 0;
    
        output = number1 & number2;   
        System.out.println("Result for number1 & number2: "+output);
    
        output = number1 | number2;   
        System.out.println("Result for number1 | number2: "+output);
        
        output = number1 ^ number2;   
        System.out.println("Result for number1 ^ number2: "+output);
        
        output = ~number1;   
        System.out.println("Result for ~number1: "+output);
        
        output = number1 << 2;   
        System.out.println("Result for number1 << 2: "+output); 
        output = number1 >> 2;   
        System.out.println("Result for number1 >> 2: "+output);
       }
      } 

    Output:

     Result for number1 & number2: 2
     Result for number1 | number2: 31
     Result for number1 ^ number2: 29
     Result for ~number1: -12
     Result for number1 << 2: 44
     Result for number1 >> 2: 2

  • Top Interview Question of Java

    This article contains 50+ top java interview questions and answers that help you prepare for your interview. These are frequently asked java questions in an interview from basic to intermediate.

    This article will help to understand the OOP concept, basic overview, exceptions, threads, modifiers, collections, Bytecode, various differences, etc. and help to get ready for any java related interview.


    1. What is Java?

    Java is a popular general-purpose, high-level, modern programming language, and computing platform. It is fast, reliable, secure and dynamic, with the ability to fit the needs of virtually any type of application. It was created by James Gosling from Sun Microsystems (Sun) in 1991. It is Platform Independent, which means the user only needs to write a program once and it can be run on a number of different platforms such as Windows, Mac OS, and the various versions of UNIX.


    2. What are the features of JAVA?

      Object-Oriented
      Platform Independent
      Simple and secure
      Portable
      Robust
      Dynamic
      Multi-threaded
      High Performance
      Compiled and Interpreted
      Distributed.
    Click Here to learn in detail.


    3. What do you understand by JVM?

    JVM stands for Java Virtual Machine, which is an abstract machine that provides a runtime environment to run Java programs. JVM is the specification that must be implemented in the computer system. It converts Java bytecode into machine language, so not only Java but it also enables the computer to run other programs that are compiled to bytecode. There are three notations in JVM:
    Specification, Implementation, and Runtime Instance.


    4. Name the types of memory allocated by JVM?

    Types of memory allocated by JVM are:

    • Method Area:
      In method area, structures like the run-time constant pool, field and method data, variables information, static variables, etc. are stored.
    • Heap:
      It is a shared resource among all the threads and created during run-time. All the Objects, metadata, and arrays are stored in the heap.
    • JVM language Stacks:
      Java language Stacks stores parameters, local variables and return addresses during method calls. It is not a shared resource. One JVM stack is created simultaneously for each thread that is each thread contains its own JVM stack.
    • PC Registers:
      PC(Program Counter) Register contains/stores the address of JVM(Java Virtual Machine) instruction that is being currently executed. Each thread in Java has its own PC register.
    • Native Method Stacks:
      Every thread has its own separate native stack hold the native method information.

    Click here for more detail


    5. What is the Java IDE’s?

    Eclipse and NetBeans are the IDE’s of JAVA.


    6. JDK vs JRE vs JVM.

    JDK

    It stands for Java Development Kit. It is the tool necessary to compile, document, and package Java programs. It contains JRE + development tools and is an implementation of any one of the following Java Platforms released by Oracle:
    1. Standard Edition Java Platform
    2. Enterprise Edition Java Platform
    3. Micro Edition Java Platform

    JRE

    It stands for Java Runtime Environment. JRE refers to a runtime environment in which Java bytecode can be executed and used for developing java applications with a set of libraries. It’s an implementation of the JVM and is physically exists.

    JVM

    JVM stands for Java Virtual Machine, which is an abstract machine that provides a runtime environment to run Java programs. JVM is the specification that must be implemented in the computer system. There are three notations in JVM:
    Specification, Implementation, and Runtime Instance.


    7. What is the JIT compiler?

    Just-In-Time(JIT) compiler: It is used to increase the performance of the compiler by taking the block of similar bytecode that is the repeated method calls. Hence reducing the compilation time and making it more efficient.


    8. What is meant by the Local variable and the Instance variable?

    Local variable: A variable that is declared within the body of the method or constructor is called a local variable. And is destroyed after exiting the method or block.
    Instance variable: These are the non-static variable that is declared within the class but outside the method or constructor. And can be accessed only by creating objects.


    9. What gives Java its ‘write once and run anywhere’ nature?

    The bytecode. Java compiler converts the Java programs into the class file (Byte Code) which is the intermediate language between source code and machine code. This bytecode is not platform-specific and can be executed on any computer.


    10. What are Class and Objects?

    Class: A class is a user-defined blueprint or prototype for creating Objects. It is a logical entity.
    A class in Java contain:
    Methods
    Fields
    Constructors
    Blocks
    Interfaces

    Objects: It can be defined as a real-world entity that has state and behavior. An object is a runtime entity. Eg. bike, Lamp, pen, table, etc.
    An Object is an instance of a class. It is a physical as well as a logical entity.


    11. What are the Oops concepts?


    12. What is the classloader subsystem?

    This subsystem is used for loading class files. It performs three major functions :
    Loading, Linking, and Initialization.
    There are three built-in classloaders in Java:

    • Bootstrap ClassLoader: It loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package classes, java.net package classes, java.util package classes.
    • Extension ClassLoader: It loads the jar files located inside $JAVA_HOME/jre/lib/ext directory.
    • System ClassLoader: It loads the class files from the classpath. Also known as Application classloader.

    13. Does Java Use Pointers?

    No, Java doesn’t use pointers. It has tough security and is not safe. Instead of pointers, java uses reference types as they are safer and more secure. Memory allocation is done automatically so to avoid direct access to memory by the user java doesn’t allow pointers.


    14. What are the various access modifiers for Java classes?

    The access modifiers in Java specify the accessibility or visibility or scope of a field, method, constructor, or class. Following are Java’s four access modifiers with their accessibility:

    • default (Same class, Same package)
    • private (Same class)
    • protected ( Same class, Same package, Subclasses)
    • public ( Same class, Same package, Subclasses, Everyone)

    15. What are the Functions of JVM and JRE?

    JVM (Java Virtual Machine) provides a runtime environment for Java Byte Codes to be executed.
    JRE (Java Runtime Environment) includes sets of files required by JVM during runtime.


    16. How can we restrict inheritance for a class?

    We can restrict inheritance for a class by the following steps:

    1. By using the final keyword.
    2. If we make all methods final, then we cannot override that.
    3. By using private constructors.
    4. By using the Javadoc comment (//)

    17. What Is the Difference Between Overloading and Overriding?

    Method Overloading is one of the features in a class having more than one method with the same name. Method Overriding is a feature that allows the user to declare a method with the same name in a sub-class that is already present in a parent class.


    18. What is the super keyword in java?

    The super keyword in Java is used in the sub-class for calling the inherited parent class method/constructor. Super is used to access superclass variables, methods, constructors.
    Super can be used in two forms :

    1. The first form is for calling a superclass constructor.
    2. The second one is to call superclass variables, methods.

    19. Why java is platform-independent?

    Unlike other programming languages such as C, C++, etc, which require a specific platform to be compiled whereas Java is compiled into byte-code and this byte-code is Platform Independent. This means Java is only required to write-once and can be run on any platform such as Windows, Linux, Mac OS, etc. This byte-code is interpreted by the Java Virtual Machine (JVM).


    20. What is bytecode in java?

    When a javac compiler compiles a class it generates a .class file. This .class file contains a set of instructions called byte code. Byte code is a machine-independent language and contains a set of instructions that are to be executed only by JVM. JVM can understand these byte codes.


    21. Explain the main() method in java?

    The main () method is the starting point of execution for all java applications.

    public static void main(String[] args) {}

    String args[] are an array of string objects we need to pass from command line arguments. Every Java application must have at least one main method.


    22. Difference between ‘>>’ and ‘>>>’ operators in java?

    >> is a right shift operator that shifts all of the bits in value to the right to a specified number of times.
    int a = 12;
    a = a >> 3;

    The above line of code moves 12 three characters right.
    >>> is an unsigned shift operator used to shift right. The places which were vacated by shift are filled with zeroes.


    23. What Is a Package?

    Packages in Java are a way to pack(group) a number of related types such as classes, interfaces, enumerations, and annotations together into a single unit. Packages are used to avoid name conflicts, provide a good structure to the projects with maintainable code that consists of many classes.


    24. What is a singleton class?

    A singleton class in java can have only one instance and hence all its methods and variables belong to just one instance. Singleton class concept is useful for situations when there is a need to limit the number of objects for a class.


    25. What are Loops in Java?

    loop statement allows us to execute a block of code or statement or group of statements as many times according to the user’s need. It is done by evaluating a given condition for true and false. The statement stops looping when the condition is false.


    26. What is an infinite Loop and how it is declared?

    An infinite loop runs without any condition and runs infinitely. An infinite loop (sometimes called an endless loop).
    An infinite loop is declared as follows:

     or (;;)
     {
        // Statements to execute
    
        // Add any loop breaking logic
     }

    27. Java doesn’t support Multiple Inheritance. Why?

    In this type of inheritance, one class(derived class) can inherit from more than one superclass. Java doesn’t support multiple inheritances because the derived class will have to manage the dependency on two base classes. It creates ambiguity.


    28. Define an abstract class.

    An abstract class is a class that is declared with an abstract keyword. An abstract class may or may not have abstract methods. This class cannot create objects, to access this class, it must be inherited. This class can have public, private, protected, or constants and default variables.
    Example:

    abstract class ClassName{ }


    29. What is the finalize method?

    Before destroying an object, the finalize() method is called by Garbage Collector for performing the cleanup process. And once it’s done, Garbage Collector destroys that object. The finalize() method is present in an Object Class as:

    protected void finalize(){}


    30. What is Runtime Exceptions?

    Unchecked Exceptions are also known as run-time exceptions. These exceptions occur during the time of execution of a program that is at run-time. Some of the Unchecked Exceptions occur are ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException, etc.


    31. What is an Interface?

    An Interface in Java is the same as a class, like any other class, an interface can have methods and variables. But unlike a class, the method in it is an abstract method (only method signature, contain no-body), and also by default, the declared variables in an interface are public, static & final. It is used to achieve abstraction and loose coupling.


    32. What is an applet?

    The Applet in Java is a special type of internet-based program, that runs on the web browser and works at the client side. It is used to make the webpage more dynamic and provide interactive features that cannot be applied by HTML alone. Any applet in Java is a class that extends the java.applet.Applet class. An Applet class does not contain the main() method.


    33. Why Multiple Inheritance is not supported in java?

    In this type of inheritance, one class(derived class) can inherit from more than one superclass. Java doesn’t support multiple inheritances because the derived class will have to manage the dependency on two base classes. In java, we can achieve multiple inheritances only through Interfaces. It is rarely used because it creates an unwanted problem in the hierarchy.


    34. What is the difference between StringBuffer and String?

    A string is an Immutable class that is their values are unchangeable once it is created. Whereas StringBuffer is a mutable class that is their values or content can be changed later. Every time we alter the value or content the String objects create a new string rather than changing the existing one. Due to this, the StringBuffer is preferred rather than String.


    35. Distinguish between StringBuffer and StringBuilder in Java programming.

    StringBuffer

    • StringBuffer is a thread-safe.
    • These methods are synchronized.
    • The performance is very slow.

    StringBuilder

    • StringBuilder is fast as it is not thread-safe.
    • These methods are non-synchronized.
    • The performance is very fast.

    36. What are the default value of float and double data-type in Java?

    For float its 0.0f and for double it’s 0.0d


    37. What is an Exception?

    An exception in Java is an event that arises during the execution of a program i.e. during run-time. The occurrence of an exception in a program disrupts the normal flow of instructions. This causes the termination of the program or application and therefore needs to be handled by calling an exception handler, which deals with the exception.


    38. When a super keyword is used?

    The super keyword in Java is used in the sub-class for calling the inherited parent class method/constructor. It can be also used to refer to a hidden field.


    39. What is the benefit of using Encapsulation?

    Benefits of Encapsulation:

    • Data- hiding in Java.
    • The class field can be made read-only or write-only.
    • It provides the class the total control over the data.

    40. Why Packages are used?

    Packages are used to avoid name conflicts, provide a good structure to the projects with maintainable code that consists of many classes.


    41. State the main purpose of using MultiThreading.

    The main purpose of MultiThreading is to achieve the simultaneous execution of more than two tasks so to maximize the use of CPU time.


    42. What are the ways in which Thread can be created?

    There are two ways to create a thread:
      By extending Thread class.
      By implementing the Runnable interface.


    43. name a class extended by applet?

    An applet extends java.applet.Applet class.


    44. What is Garbage collection in Java?

    Garbage collection in java is a way in which the unreachable objects are destroyed to free up space in memory. JVM creates a heap area which is called runtime data area, where all the objects are stored. And the space in that area is limited so it is needed to manage this area efficiently by removing the objects that are no longer required or are unused. And therefore, this process of removing the unused objects present in the heap area is known as Garbage collection.


    45. Define final keyword in java.

    In java, the final keyword is used in many contexts to identify the entity that can only be assigned once and is used as a non-access modifier. These can be:

    final variable:
    The variable declared as final cannot have its value changed once it is assigned. It remains the same that is constant.
    final int maxSpeed = 90; //final variable  

    final method:
    The declared final method cannot be overridden by the inheriting class.
    final void speed() { block of code }

    final class:
    If a class is declared as final, it cannot be extended by other subclasses. Although, it can extend to other classes.
    final class Speed { code }


    More will be added soon. it will be updated from time to time, so stay connected to simple2code.


  • Main Features of Java

    The following are the features of Java:

    • Object-Oriented
    • Platform Independent
    • Simple and secure
    • Portable
    • Robust
    • Dynamic
    • Multi-threaded
    • High Performance
    • Compiled and Interpreted
    • Distributed.

    1. Object-Oriented:

    Java is an object-oriented programming language. OOP divides the program into a number of objects and makes it simpler. This Object has some data and behavior which is used inflow of data from one function to another. Users can easily extend java as it is based on Object Model. Therefore understanding OOP is an important step to learn Java Programming. Basic concepts of OOPs are:

    • Object
    • Class
    • Inheritance
    • Polymorphism
    • Abstraction
    • Encapsulation

    2. Platform Independent:

    Unlike other programming languages such as C, C++, etc, which require a specific platform to be compiled whereas Java is compiled into byte-code and this byte-code is Platform Independent. This means Java is only required to write-once and can be run on any platform such as Windows, Linux, Mac OS, etc. This byte-code is interpreted by the Java Virtual Machine (JVM).

    3. Simple and secure:

    Java is very easy to learn, clean, and easy to understand. Java language is a simple programming language because of its C++ syntax. Java is also best known for the security that it provides and enables us to develop virus-free systems. it is secured because java programs run inside the virtual machine sandbox.

    4. Portable:

    As mentioned above, the byte-code is Platform Independent and can be carried to any other platform for execution of Java program that makes Java code portable.

    5. Robust:

    Robust means strong. Java is strong and reliable because of its ability for early checking for errors, mainly on compilation error and run-time checking.

    6. Dynamic:

    Since Java is designed to adapt to a transformed environment, it makes java dynamic. it is considered to be more dynamic than C or C++. Java supports the dynamic loading of classes and compilation and garbage collection.

    7. Multi-threaded:

    This feature in Java allows Java to perform more than one task at once by defining multiple threads for maximum utilization of CPU. The advantage of the use of Multi-threaded is that it does not require to occupy space in memory for each thread instead it shares the common memory space.

    8. High Performance:

    Java-enabled High performance by introducing JIT- Just In Time compiler, that is the compiler only compiles the code or method that is called, making compilation process faster and consume less-time.

    9. Compiled and Interpreted:

    Java has both Compiled and Interpreted feature where the compilation feature allows to create byte code after compilation. And after, the byte codes are converted into Machine Language with the help of an Interpreter. Hence both features are required for the execution of Java Code.

    10. Distributed: 

    Java is distributed because it allows users/developers to create distributed applications that are designed to run on computer networks. RMI(Remote Method Invocation) and EJB (Enterprise Java Beans) are used for creating distributed applications. In other words, this feature allows the user to access the files from any machine that is connected to each other on the internet.