Вы находитесь на странице: 1из 9

JAVA QUESTIONS

1. What are the components of web


service?
The various web services components are as follows:
• SOAP- Simple Object Access Protocol
• UDDI- Universal Description, Discovery, and Integration
• WSDL- Web Service Description language
• RDF- Resource Description Framework
• XML- Extensible Markup Language

2. Explain web service architecture?


The Web Service Framework comprises of three different layers of
architecture. The following are the roles of the layers:
• Service Provider: As the name implies, the function of
the service provider is to develop the internet services and make
it available via the internet to customer software for their use.
• Service Requester: As with the client application, service
requester is essentially a user of web services. User programs
are compiled for all types of functions in any language contact
Web service by transferring XML requires via the internet
connection available.
• Service Registry: Service Registry is the core repository
that supports the location of customer web services. The current
web services can be found here, and also the new programmers
can also build them.
The service provider makes the current web services accessible for
customer applications with the ‘ Publish ‘ interface of the registry
service. The service requester is able to attach or override the
services with all information given by the service register.

3. Define web service protocol stack and its layers?


The protocol stack of Web service comprises of four layers. This is as
follows:
1) Service transport: It is the first layer that enables transport XML
messages between different client programs and uses the protocols
listed below:
• HTTP(Hypertext Transport Protocol)
• SMTP(Simple Mail Transport Protocol)
• FTP(File Transfer Protocol)
• BEEP(Block Extensible Exchange Protocol)
2) XML messaging: This is premised on the XML model, which
encodes messages in prevalent XML format that others can easily
understand. This layer comprises:
• XML-RPC
• SOAP(Simple Object Access Protocol)
3) Service description: The layer involves descriptions of location,
features available and XML messaging data types describing a public
interface to a particular web service. Include this layer:
• WSDL(Web Service Description Language)
4) Service discovery: This layer provides a way of publishing and
finding web services throughout the web. This layer contains:
• UDDI(Universal Description, Discovery, and Integration)

4. SCALA - What is Anonymous (lambda) Function in Scala?


An anonymous function is a function that has no name but works as a
function. It is good to create an anonymous function when you don't
want to reuse it later. You can create anonymous function either by
using ⇒ (rocket) or _ (underscore) wildcard in Scala.

Example

1. object MainObject {  
2.    def main(args: Array[String]) = {  
3.      var result1 = (a:Int, b:Int) => a+b        // Anonymous func
tion by using => (rocket)  
4.      var result2 = (_:Int)+(_:Int)              // Anonymous functio
n by using _ (underscore) wild card  
5.      println(result1(10,10))  
6.      println(result2(10,10))  
7.     }  
8. }  

5.  Why do we use =(equal) operator in Scala function?


You can create a function with or without = (equal) operator. If you
use it, the function will return value. If you don't use it, your function
will not return anything and will work like the subroutine.

Example

1. object MainObject {  
9.    def main(args: Array[String]) {  
10.         var result = functionExample()      // Calling function  
11.         println(result)  
12.     }  
13.     def functionExample() = {           // Defining a function  
14.           var a = 10  
15.           a  
16.     }  
17. }  

6.
How can you avoid importing tables one-by-one
when importing a large number of tables from a
database?

Ans. Using the command


sqoop import-all-tables
–connect
–usrename
–password
–exclude-tables table1,table2 ..
Basically, this will import all the tables except the ones
mentioned in the exclude-tables clause.

7.

 I am getting connection failure exception during connecting


to Mysql through Sqoop, what is the root cause and fix for
this error scenario?
This will happen when there is lack of permissions to access our Mysql
database over the network. We can try the below command to confirm
the connect to Mysql database from aSqoop client machine.
$ mysql –host=MySqlnode> –database=test –user= –password=
We can grant the permissions with below commands.
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘%’@’localhost’;
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘ ’@’localhost’;

8.What is a Sqoop tool ?


Apache Sqoop has 15 distinct functions to import, export, validate, merge, create
jobs, meta-store, merge, evaluate, create tables, codegen, list databases, list
tables, user help and version. Each one of these functions is considered a tool
within Sqoop. 
The table below lists these 15 tools within Apache Sqoop
Tool Name Description
sqoop-import Imports an individual table from an RDBMS to HDFS
sqoop-import-all-
Imports a set of tables from an RDBMS to HDFS
tables
sqoop-import- Imports all sequential datasets in a partitioned
mainframe dataset(PDS) on a mainframe to HDFS
sqoop-export Exports a set of files from HDFS back to an RDBMS
Validate the data copied by comparing the row counts from
validation
the source and target
sqoop-job Used to create and save jobs
Used to configure Sqoop to host a shared metadata
sqoop-metastore
repository
sqoop-merge Used to combine two datasets
Generates Java classes which encapsulate and interpret
sqoop-codegen
imported records
sqoop-create-hive- Populates a Hive metastore with table definitions imported
table to HDFS
Enables users to run SQL queries against a database for
sqoop-eval
evaluation
sqoop-list-
Lists database schemas on a server
databases
sqoop-list-tables Lists tables present in a database
sqoop-help Lists and explains tools available in Apache Sqoop
sqoop-version Displays version information for Apache Sqoop

What are Sqoop Commands ?


Apache Sqoop is a collection of 15 tools to performs various import/export and
related functions. Sqoop Commands are how you invoke the specific Sqoop tool.
Fortunately, the name of the Sqoop tool and Sqoop commands are the same.
Example: To use the Apache Sqoop import tool, at the CLI type " Sqoop import"
Command Description
import Imports an individual table from an RDBMS to HDFS
import-all-
Imports a set of tables from an RDBMS to HDFS
tables
import- Imports all sequential datasets in a partitioned dataset(PDS) on
mainframe a mainframe to HDFS
export Exports a set of files from HDFS back to an RDBMS
Validate the data copied by comparing the row counts from the
validation
source and target
job Used to create and save jobs
metastore Used to configure Sqoop to host a shared metadata repository
merge Used to combine two datasets
Generates Java classes which encapsulate and interpret
codegen
imported records
create-hive- Populates a Hive metastore with table definitions imported to
table HDFS
Enables users to run SQL queries against a database for
eval
evaluation
list-databases Lists database schemas on a server
list-tables Lists tables present in a database
help Lists and explains tools available in Apache Sqoop
version Displays version information for Apache Sqoop

9. Explain parallelism in Apache Sqoop ?


Parallel processing is the simultaneous execution of multiple instances of the
same instructions or tasks.
Apache Sqoop data imports are processed in parallel, with 4 as the default
degree of parallelism. Sqoop uses the Primary Key column in the table as the
splitting column for parallel imports. The degree of parallelism can be controlled
by setting the specific argument  'm' or 'num-mappers' 

10. What is an incremental import in Sqoop ?


Incremental import in Sqoop allows data to be imported in chunks as a
continuation instead of having to import the entire dataset. Apache Sqoop
supports 2 types of incremental imports: append and lastmodified
The append incremental import in sqoop allows data to be imported based on a
row id value, and the lastmodified import allows data to be incrementally
imported based on a timestamp

11. Java doesn't support multiple inheritance. Why?


Java doesn’t support multiple inheritance. Because we cannot use
different methods in one class it creates an ambiguity.
Example:
class Intellipaat1
{
void test()
{
system.out.println("test() method");
}
}class Intellipaat2
{
void test()
{
system.out.println("test() method");
}
}Multiple inheritance
class C extends Intellipaat1, Intellipaat2
{
………………………………………….
…………………………………………..
}
Intellipaat1 and Intellipaat2 test() methods are inheriting to class C
So which test() method C class will take. As Intellipaat1 & Intellipaat2
class test () methods are different, So here we would face ambiguity.
12.
Are constructors inherited? Can a subclass call the parent's
class constructor?
We cannot inherit a constructor. We create an instance of a subclass
using a constructor of one of its superclass. Because override the
superclass constructor is not our wish so that, we override a superclass
constructor, then we destroy the encapsulation abilities of the language.
13.
Difference between the Inner Class and Sub Class.
Inner Class Sub Class

It’s a class which is nested within another class. It’s a class which inherits from
another class called super class.

Inner class provides the access rights for the class Sub-class provides access to all
which is nesting it and that can access all variables and public and protected methods and
methods defined in the outer class. fields of its super class.

14. Can we execute any code, even before the main method?
Explain?
Yes, We can execute any code, even before the main method. We are
using a static block of code in the class when creating the objects at load
time of class. Any statements within this static block of code will get
executed one time while loading the class, even before the creation of
objects in the main method.
15.
 Differentiate between StringBuffer and StringBuilder in
Java programming.
String Buffer String Builder

StringBuffer methods are synchronized StringBuilder is non synchronized

Storage area is Heap and modified easily. Storage is Heap and can be modified.

StringBuffer is thread safe. StringBuilder is fast as it is not thread safe

Performance is very slow Performance is very fast.

Вам также может понравиться