What is java?

* Java is a programming language.
* It was first developed by James Gosling at Sun Microsystems, which is now a part of Oracle Corporation.
* Java is an object oriented programming language.
* It is easier than C++ and has various advantages over C++. 


java important question find it here.


 

What are the features of JAVA?
(or)
List the BUZZ words?

Simple
Object-Oriented
Platform independent
Secured
Robust
Architecture neutral
Portable
Dynamic
Interpreted
High Performance
Multithreaded
Distributed


java important question


What are the advantages of Java ?

Java is easy to learn. Java was designed to be easy to use and is therefore easy to write, compile, debug, and learn than other programming languages.
Java is object-oriented. This allows you to create modular programs and reusable code.
Java is platform-independent.
Java is secured.


java important question


How Java program runs?

Compilation and execution of a Java program is two step process. During compilation phase Java compiler compiles the source code and generates bytecode. This intermediate bytecode is saved in form of a .class file. In second phase, Java virtual machine (JVM) also called Java interpreter takes the .class as input and generates output by executing the bytecode.



TYPECAST

int i=567;
byte b;
b=(byte) i;

Here in the above code i is initialized as integer and b which is initialized as byte.
The value of i is stored in b by converting i from integer to byte.



OPERATORS

Arithmetic operators
Bitwise operators
Relational operators
Boolean logical operators
Assignment operator
?  operator.



INHERITANCE

  • Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another.
  • A class that is derived from another class is called a subclass (also a derived class, extended class, or child class).
  •  The class from which the subclass is derived is called a superclass (also a base class or a parent class).
  • Extends is the keyword used to inherit the properties of a class.
  • SYNTAX
    class Base{
    .....
    .....
    }
    
    class Subclass extends Base{
    .....
    .....
    
    }
  • EXAMPLE [Single level inheritance]
    class Base
    {
       void fun1()
       {
        System.out.println("BASE CLASS FUNCTION");   
       }
    }
    
    class Sub extends Base
    {
       void fun2()
       {
        System.out.println("DERIVED CLASS FUNCTION");
       }
       public static void main(String args[])
       {
        Sub obj1=new Sub();
        obj1.fun1();
        obj1.fun2();
       }
    }
    
    OUTPUT:
    
    BASE CLASS FUNCTION
    DERIVED CLASS FUNCTION
  • EXAMPLE [Multi level Inheritance]
    Class A{
    void fun1()
    {
    System.out.println(“FUNCTION of A”);
    }
    }

Class B extends Class A{
void fun2()
{
System.out.println(“FUNCTION of B”);
}
}

Class C extends Class B{
public static void main(String args[])
{
C obj1 = new C();
obj1.fun1();
obj1.fun2();
}
}

  • Multiple inheritance is not possible in java. It is done using a technique called Interface.


  • Packages in Java

There are two types of packages in Java as built-in package and user defined package.

You can even create your own package in Java but it will work only on your machine where you implement it.

Java packages can be stored in compressed files called JAR File allowing classes to be downloaded faster as groups rather than individually.

Advantages of Packages:

  • Java package is used to categorize the classes and interfaces so that they can be easily maintained.
  • Java package provides access protection.
  • Java package removes naming collision.


  • ABSTRACT CLASS

Keyword abstract is used.

It can have abstract and non-abstract methods

Abstraction is a process of hiding the implementation details and showing only functionality to the user.

EXAMPLE:

abstract class Bike{

abstract void run();

}

class Honda4 extends Bike{

void run(){System.out.println(“running safely..”);}

public static void main(String args[]){

Bike obj = new Honda4();

obj.run();

}  }



POLYMORPHISM

The word polymorphism means having many forms. Typically,polymorphism occurs when there is a hierarchy of classes and they are related by inheritance.

Types of polymorphism in java- Runtime and Compile time polymorphism

Runtime Polymorphism

Method overriding is a perfect example of  runtime polymorphism.

It is also called as Dynamic Polymorphism.

EXAMPLE:

public class X
{
    public void methodA() //Base class method
    {
        System.out.println ("hello, I'm methodA of class X");
    }
}

public class Y extends X
{
    public void methodA() //Derived Class method
    {
        System.out.println ("hello, I'm methodA of class Y");
    }
}
public class Z
{
   public static void main (String args []) {
       X obj1 = new X(); // Reference and object X
       X obj2 = new Y(); // X reference but Y object
       obj1.methodA();
       obj2.methodA();
   }
}

Output:

hello, I‘m methodA of class X
hello, I’m methodA of class Y

Compile Time polymorphism

Compile time polymorphism is nothing but the method overloading in java.

In simple terms we can say that a class can have more than one methods with same name but with different number of arguments or different types of arguments or both.

It is also called Static polymorphism.

EXAMPLE:

class X
{
   void methodA(int num)
   {
       System.out.println ("methodA:" + num);
   }
   void methodA(int num1, int num2)
   {
       System.out.println ("methodA:" + num1 + "," + num2);
   }
   double methodA(double num) {
       System.out.println("methodA:" + num);
       return num;
   }
}

class Y
{
   public static void main (String args [])
   {
       X Obj = new X();
       double result;
       Obj.methodA(20);
       Obj.methodA(20, 30);
       result = Obj.methodA(5.5);
       System.out.println("Answer is:" + result);
   }
}

Output:

methodA:20
methodA:20,30
methodA:5.5
Answer is:5.5


java important question is available above is only for engineering students of CSE for thier first unit.

Follow me

Gowdham S

Technical Manager at SeekaHost Ltd
Love to learn new things & Love to create new things with Innovative Ideas. Having 5+ years of experience in Digital Marketing Strategies and expertise in Server Handling & Web Hosting Technologies.
Follow me
More in sem5
Discrete Mathematics 2 marks Unit-1 (2m)

Close