Soft Suave Java Fresher Interview Questions with Answers

Hi, in this post we are going to discuss Soft suave Java fresher interview questions with answers. In the first round, they gave technical programs and the candidates were asked to write the output. Let us discuss the secound round questions briefly;

Soft Suave Java Fresher Interview Questions with Answers

1. What is the difference between collection and map in Java?

                   COLLECTION                               MAP
 A collection represents a group of objects, known as its elements. Map stores group of objects in the form of key and value pair.
In collection, we retrive element by their index. In map, we retrive element by key.
Collection is used to store objects. Map is used to store the objects for (key,value) based manner.
Collection classes are used to store object in array format. Map classes are used to store in (KEY,VALUE) pair format.

 

2. Write programs on inheritance.

SAMPLE CODE 1: Single Inheritance
class Animal{
void eat(){System.out.println(“eating…”);}
}
class Dog extends Animal{
void bark(){System.out.println(“barking…”);}
}
class TestInheritance{
public static void main(String args[]){
Dog d=new Dog();
d.bark();
d.eat();
}}
OUTPUT 1:
barking…
eating…

SAMPLE CODE 2:Multilevel Inheritance
class Animal{
void eat(){System.out.println(“eating…”);}
}
class Dog extends Animal{
void bark(){System.out.println(“barking…”);}
}
class BabyDog extends Dog{
void weep(){System.out.println(“weeping…”);}
}
class TestInheritance2{
public static void main(String args[]){
BabyDog d=new BabyDog();
d.weep();
d.bark();
d.eat();
}}
OUTPUT 2:
weeping…
barking…
eating…

SAMPLE CODE 3:Hierarchical Inheritance
class Animal{
void eat(){System.out.println(“eating…”);}
}
class Dog extends Animal{
void bark(){System.out.println(“barking…”);}
}
class Cat extends Animal{
void meow(){System.out.println(“meowing…”);}
}
class TestInheritance3{
public static void main(String args[]){
Cat c=new Cat();
c.meow();
c.eat();
//c.bark();//C.T.Error
}}
OUTPUT 3:
meowing…
eating…

3. Write programs for overriding.

SAMPLE CODE 1: Method overriding
class Animal {
public void move() {
System.out.println(“Animals can move”);
}
}

class Dog extends Animal {
public void move() {
System.out.println(“Dogs can walk and run”);
}
}

public class TestDog {

public static void main(String args[]) {
Animal a = new Animal(); // Animal reference and object
Animal b = new Dog(); // Animal reference but Dog object

a.move(); // runs the method in Animal class
b.move(); // runs the method in Dog class
}
}
OUTPUT 1:
Animals can move
Dogs can walk and run

SAMPLE CODE 2: Using the super Keyword
class Animal {
public void move() {
System.out.println(“Animals can move”);
}
}

class Dog extends Animal {
public void move() {
super.move(); // invokes the super class method
System.out.println(“Dogs can walk and run”);
}
}

public class TestDog {

public static void main(String args[]) {
Animal b = new Dog(); // Animal reference but Dog object
b.move(); // runs the method in Dog class
}
}
OUTPUT 2:
Animals can move
Dogs can walk and run

4. Basic SQL queries.

Storage of your data:
=>CREATE DATABASE is used to create a new, empty database.
=>DROP DATABASE is used to completely destroy an existing database.
=>USE is used to select a default database.
=>CREATE TABLE is used to create a new table, which is where your data is actually stored.
=>ALTER TABLE is used to modify an existing table’s definition.
=>DROP TABLE is used to completely destroy an existing table.
=>DESCRIBE shows the structure of a table.
Manipulating your Data:
=>SELECT is used when you want to read (or select) your data.
=>INSERT is used when you want to add (or insert) new data.
=>UPDATE is used when you want to change (or update) existing data.
=>DELETE is used when you want to remove (or delete) existing data.
=>REPLACE is used when you want to add or change (or replace) new or existing data.
=>TRUNCATE is used when you want to empty (or delete) all data from the template.
Transactions:
=>START TRANSACTION is used to begin a transaction.
=>COMMIT is used to apply changes and end transaction.
=>ROLLBACK is used to discard changes and end transaction.

5. Write a program on exception.

SAMPLE CODE:
public class JavaExceptionExample{
public static void main(String args[]){
try{
//code that may raise exception
int data=100/0;
}catch(ArithmeticException e){System.out.println(e);}
//rest code of the program
System.out.println(“rest of the code…”);
}
}
OUTPUT:
Exception in thread main java.lang.ArithmeticException:/ by zero
rest of the code…

References:
https://www.youth4work.com/Talent/Core-Java/Forum/112685-what-is-the-difference-between-collection-and-map-
https://www.javatpoint.com/inheritance-in-java
https://www.tutorialspoint.com/java/java_overriding.htm
https://mariadb.com/kb/en/library/basic-sql-statements/
https://www.geeksforgeeks.org/output-of-python-programs-set-10-exception-handling/