Google Search
Wednesday, March 23, 2016
Wednesday, March 2, 2016
what is the output?
main()
{
clrscr();
}
clrscr();
{
clrscr();
}
clrscr();
Answer:
No output/error
No output/error
Explanation:
The first clrscr() occurs inside a function. So it becomes a function call. In the second clrscr(); is a function declaration (because it is not inside any function).
The first clrscr() occurs inside a function. So it becomes a function call. In the second clrscr(); is a function declaration (because it is not inside any function).
HADOOP Tutorial 2
Hadoop is an Apache open source framework written in java that allows distributed processing of large datasets across clusters of computers using simple programming models. A Hadoop frame-worked application works in an environment that provides distributed storage and computation across clusters of computers. Hadoop is designed to scale up from single server to thousands of machines, each offering local computation and storage.
Hadoop Architecture
Hadoop framework includes following four modules:
Hadoop framework includes following four modules:
Hadoop Common: These are Java libraries and utilities required by other Hadoop modules. These libraries provides filesystem and OS level abstractions and contains the necessary Java files and scripts required to start Hadoop.
Hadoop YARN: This is a framework for job scheduling and cluster resource management.
Hadoop Distributed File System (HDFS™): A distributed file system that provides high-throughput access to application data.
Hadoop MapReduce: This is YARN-based system for parallel processing of large data sets.
HADOOP Tutorial
MapReduce
Hadoop MapReduce is a software framework for easily writing applications which process big amounts of data in-parallel on large clusters (thousands of nodes) of commodity hardware in a reliable, fault-tolerant manner.
Hadoop MapReduce is a software framework for easily writing applications which process big amounts of data in-parallel on large clusters (thousands of nodes) of commodity hardware in a reliable, fault-tolerant manner.
The term MapReduce actually refers to the following two different tasks that Hadoop programs perform:
The Map Task: This is the first task, which takes input data and converts it into a set of data, where individual elements are broken down into tuples (key/value pairs).
The Reduce Task: This task takes the output from a map task as input and combines those data tuples into a smaller set of tuples. The reduce task is always performed after the map task.
Typically both the input and the output are stored in a file-system. The framework takes care of scheduling tasks, monitoring them and re-executes the failed tasks.
The MapReduce framework consists of a single master JobTracker and one slave TaskTracker per cluster-node. The master is responsible for resource management, tracking resource consumption/availability and scheduling the jobs component tasks on the slaves, monitoring them and re-executing the failed tasks. The slaves TaskTracker execute the tasks as directed by the master and provide task-status information to the master periodically.
The JobTracker is a single point of failure for the Hadoop MapReduce service which means if JobTracker goes down, all running jobs are halted.
Hadoop Distributed File System
Hadoop can work directly with any mountable distributed file system such as Local FS, HFTP FS, S3 FS, and others, but the most common file system used by Hadoop is the Hadoop Distributed File System (HDFS).
Hadoop can work directly with any mountable distributed file system such as Local FS, HFTP FS, S3 FS, and others, but the most common file system used by Hadoop is the Hadoop Distributed File System (HDFS).
The Hadoop Distributed File System (HDFS) is based on the Google File System (GFS) and provides a distributed file system that is designed to run on large clusters (thousands of computers) of small computer machines in a reliable, fault-tolerant manner.
HDFS uses a master/slave architecture where master consists of a single NameNode that manages the file system metadata and one or more slave DataNodes that store the actual data.
A file in an HDFS namespace is split into several blocks and those blocks are stored in a set of DataNodes. The NameNode determines the mapping of blocks to the DataNodes. The DataNodes takes care of read and write operation with the file system. They also take care of block creation, deletion and replication based on instruction given by NameNode.
HDFS provides a shell like any other file system and a list of commands are available to interact with the file system. These shell commands will be covered in a separate chapter along with appropriate examples.
How Does Hadoop Work?
Stage 1
A user/application can submit a job to the Hadoop (a hadoop job client) for required process by specifying the following items:
Stage 1
A user/application can submit a job to the Hadoop (a hadoop job client) for required process by specifying the following items:
The location of the input and output files in the distributed file system.
The java classes in the form of jar file containing the implementation of map and reduce functions.
The job configuration by setting different parameters specific to the job.
Stage 2
The Hadoop job client then submits the job (jar/executable etc) and configuration to the JobTracker which then assumes the responsibility of distributing the software/configuration to the slaves, scheduling tasks and monitoring them, providing status and diagnostic information to the job-client.
The Hadoop job client then submits the job (jar/executable etc) and configuration to the JobTracker which then assumes the responsibility of distributing the software/configuration to the slaves, scheduling tasks and monitoring them, providing status and diagnostic information to the job-client.
Stage 3
The TaskTrackers on different nodes execute the task as per MapReduce implementation and output of the reduce function is stored into the output files on the file system.
The TaskTrackers on different nodes execute the task as per MapReduce implementation and output of the reduce function is stored into the output files on the file system.
Advantages of Hadoop
Hadoop framework allows the user to quickly write and test distributed systems. It is efficient, and it automatic distributes the data and work across the machines and in turn, utilizes the underlying parallelism of the CPU cores.
Hadoop framework allows the user to quickly write and test distributed systems. It is efficient, and it automatic distributes the data and work across the machines and in turn, utilizes the underlying parallelism of the CPU cores.
Hadoop does not rely on hardware to provide fault-tolerance and high availability (FTHA), rather Hadoop library itself has been designed to detect and handle failures at the application layer.
Servers can be added or removed from the cluster dynamically and Hadoop continues to operate without interruption.
Another big advantage of Hadoop is that apart from being open source, it is compatible on all the platforms since it is Java based.
C program to change Background Color
#include<graphics.h>
#include<conio.h>
#include<conio.h>
main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
outtext("Press any key to change the background color to GREEN.");
getch();
getch();
setbkcolor(GREEN);
getch();
closegraph();
return 0;
}
closegraph();
return 0;
}
C program for toggling of Characters of a string, like ComPuter-> output : cOMpUTER
#include<stdoi.h>
int main()
{
char name[100];
int loop;
printf("Enter any Sting: ");
fgets(name,sizeof(name),stdin);
{
char name[100];
int loop;
printf("Enter any Sting: ");
fgets(name,sizeof(name),stdin);
for (loop=0; name[loop] !=0; loop++)
{
if(name[loop]>='A' && name[loop]<='Z')
name[loop]=name[loop]+32;
else if(name[loop]>='a' && name[loop]<='z')
name[loop]=name[loop]-32;
{
if(name[loop]>='A' && name[loop]<='Z')
name[loop]=name[loop]+32;
else if(name[loop]>='a' && name[loop]<='z')
name[loop]=name[loop]-32;
}
printf("\nConvert case of character : %s",name);
return 0;
}
printf("\nConvert case of character : %s",name);
return 0;
}
C program to Convert Binary to Float:
Steps to convert Binary to float:
1.) Separate integral and fractional part from the binary digits.
(Note : While you can separate the integral and fractional part with some algorithm, but the most convenient way to separate is, by storing the binary point number in string format or character array, so that we can compare ‘.'(binary point) easily.)
2.) Integral part can be converted to decimal by, multiplying the binary digits, starting from the LSB(Least significant bit) or from right hand side, with 2 to the power of its position(start from zero) and adding the values.
2.) Integral part can be converted to decimal by, multiplying the binary digits, starting from the LSB(Least significant bit) or from right hand side, with 2 to the power of its position(start from zero) and adding the values.
for eg : 1010 : 1*2^3 + 0*2^2 + 1*2^1 + 0*2^0
=> 1010 : 8 + 0 + 2 + 0
=> 1010 : 10
3.) To convert the fractional part to floating value, multiply the binary digits, starting from MSB(most significant bit) or left hand side of fractional number, with 2 to the power of its negative position(start from one) and adding the values.
for eg : 0.1011 : 1*2^(-1) + 0*2^(-2) + 1*2^(-3) + 1*2^(-4)
=> 0.1011 : 0.5 + 0 + 0.125 + 0.0625
=> 0.1011 : 0.6895 = > ~ 0.7
C program to convert Binary to float
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<string.h>
#include<conio.h>
float pow(int, int);
int main()
{
char digits[50];
int befDec[50], aftDec[50];
int aftDecDigits, befDecDigits, storeIntegral=0, i, j=0, k=0;
float storeFractional=0, floatValue;
char up = 'd';
{
char digits[50];
int befDec[50], aftDec[50];
int aftDecDigits, befDecDigits, storeIntegral=0, i, j=0, k=0;
float storeFractional=0, floatValue;
char up = 'd';
printf("******* Convert binary to float *********\n");
//Taking binary digits in character arrary
printf("Enter binary point number : ");
scanf("%s",&digits);
printf("Enter binary point number : ");
scanf("%s",&digits);
//Separating the integral and fractional part from the floating point value
//strlen() is an inbuilt funtion defined in string.h header file
for(i=0; i<strlen(digits); i++)
{
if(digits[i]=='.')
{
up='u';
}
else if(up=='d')
{
//ASCII value of 0 is 48, so when character is casted to integer, it results to 48, which is to be subtracted
befDec[i] = (int)digits[i]-48;
k++;
}
else
{
aftDec[j] = (int)digits[i]-48;
j++;
}
}
//strlen() is an inbuilt funtion defined in string.h header file
for(i=0; i<strlen(digits); i++)
{
if(digits[i]=='.')
{
up='u';
}
else if(up=='d')
{
//ASCII value of 0 is 48, so when character is casted to integer, it results to 48, which is to be subtracted
befDec[i] = (int)digits[i]-48;
k++;
}
else
{
aftDec[j] = (int)digits[i]-48;
j++;
}
}
// Storing the lenght of Integral and fractional
befDecDigits = k;
aftDecDigits = j;
befDecDigits = k;
aftDecDigits = j;
//Loop to convert the integral binary part to decimal
j=0;
for(i = befDecDigits-1; i>=0; i--)
{
storeIntegral = storeIntegral + (befDec[i] *(int) pow(2,j));
j++;
}
j=0;
for(i = befDecDigits-1; i>=0; i--)
{
storeIntegral = storeIntegral + (befDec[i] *(int) pow(2,j));
j++;
}
//Loop to convert the fractoinal binary part to floating point value
j = -1;
for(i = 0; i<aftDecDigits; i++)
{
storeFractional = storeFractional + (aftDec[i]*pow(2,j));
j--;
}
j = -1;
for(i = 0; i<aftDecDigits; i++)
{
storeFractional = storeFractional + (aftDec[i]*pow(2,j));
j--;
}
//Adding both the integral and fractional part to get the resultant value
floatValue = storeIntegral + storeFractional;
printf("Floating point value = %f\n\n\n\n\n",floatValue);
}
floatValue = storeIntegral + storeFractional;
printf("Floating point value = %f\n\n\n\n\n",floatValue);
}
//Defining power function
float pow(int c, int d)
{
float pow=1;
if (d >= 0)
{
int i = 1;
while (i <= d)
{
pow = pow * c;
i++;
}
}
else
{
int i = 0;
while (i > d)
{
pow = pow/c;
i--;
}
}
return pow;
}
float pow(int c, int d)
{
float pow=1;
if (d >= 0)
{
int i = 1;
while (i <= d)
{
pow = pow * c;
i++;
}
}
else
{
int i = 0;
while (i > d)
{
pow = pow/c;
i--;
}
}
return pow;
}
C Program to mask password text with *:
#include <stdio.h>
#include <conio.h>
#include <conio.h>
void main()
{
char pasword[10],usrname[10], ch;
int i;
{
char pasword[10],usrname[10], ch;
int i;
clrscr();
printf("Enter User name: ");
gets(usrname);
printf("Enter the password <any 8 characters>: ");
gets(usrname);
printf("Enter the password <any 8 characters>: ");
for(i=0;i<8;i++)
{
ch = getch();
pasword[i] = ch;
ch = '*' ;
printf("%c",ch);
}
{
ch = getch();
pasword[i] = ch;
ch = '*' ;
printf("%c",ch);
}
pasword[i] = '\0';
/*If you want to know what you have entered as password, you can print it*/
printf("\nYour password is :");
printf("\nYour password is :");
for(i=0;i<8;i++)
{
printf("%c",pasword[i]);
}
}
{
printf("%c",pasword[i]);
}
}
What do you mean by self complementing code?
A self-complementing code is one in which the 9's complement is formed by taking the 1's complement. For instance, the 9's complement of 6 is 3 and the 9's complement of 1 is 8.
If we consider Excess 3:
0 0011
1 0100
2 0101
3 0110
4 0111
5 1000
6 1001
7 1010
8 1011
9 1100
If we consider Excess 3:
0 0011
1 0100
2 0101
3 0110
4 0111
5 1000
6 1001
7 1010
8 1011
9 1100
Then thinking about 6 and 3 we see the XS3 codes are: 1001 and 0110 which are the 1's complement of each other. Considering 1 and 8, the XS3 codes are 0100 and 1011 - again 1's complements. There are several self-complementing codes. There is one where instead of the usual binary weights of 8, 4, 2 and 1 you can use 2, 4, 2, and 1.
Why DDA algorithm ?
DDA Algorithm is used to plot line between two nodes i.e two end points in computer system.
While our computer understand pixels, if we want to plot a line, we should have maximum intermediate vertices of the line i.e intermediate points, so as to generate a straight line. Here DDA does the same.
While our computer understand pixels, if we want to plot a line, we should have maximum intermediate vertices of the line i.e intermediate points, so as to generate a straight line. Here DDA does the same.
c program for dda algorithm :
#include <graphics.h>
#include <stdio.h>
#include <math.h>
#include <stdio.h>
#include <math.h>
int main( )
{
float x,y,x1,y1,x2,y2,dx,dy,pixel;
int i,gd,gm;
{
float x,y,x1,y1,x2,y2,dx,dy,pixel;
int i,gd,gm;
printf("Enter the value of x1 : ");
scanf("%f",&x1);
printf("Enter the value of y1 : ");
scanf("%f",&y1);
printf("Enter the value of x2 : ");
scanf("%f",&x2);
printf("Enter the value of y1 : ");
scanf("%f",&y2);
scanf("%f",&x1);
printf("Enter the value of y1 : ");
scanf("%f",&y1);
printf("Enter the value of x2 : ");
scanf("%f",&x2);
printf("Enter the value of y1 : ");
scanf("%f",&y2);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"");
initgraph(&gd,&gm,"");
dx=abs(x2-x1);
dy=abs(y2-y1);
dy=abs(y2-y1);
if(dx>=dy)
pixel=dx;
else
pixel=dy;
pixel=dx;
else
pixel=dy;
dx=dx/pixel;
dy=dy/pixel;
dy=dy/pixel;
x=x1;
y=y1;
y=y1;
i=1;
while(i<=pixel)
{
putpixel(x,y,1);
x=x+dx;
y=y+dy;
i=i+1;
delay(100);
}
getch();
closegraph();
}
while(i<=pixel)
{
putpixel(x,y,1);
x=x+dx;
y=y+dy;
i=i+1;
delay(100);
}
getch();
closegraph();
}
RMI in JAVA
The server creates remotes objects and makes references to those objects accessible. Then it waits for clients to invoke methods on the objects. The client gets remote
references to remote objects in the server and invokes methods on those remote objects. Java RMI is a mechanism that allows one to invoke a method on an object that exists in another address space. The other address space could be on the same machine or a different one. Java Remote Method Invocation (Java RMI) enables the programmer to create distributed Java technology-based to Java technology-based
applications in which the methods of remote Java objects can be invoked from other Java virtual machines possibly on different hosts
references to remote objects in the server and invokes methods on those remote objects. Java RMI is a mechanism that allows one to invoke a method on an object that exists in another address space. The other address space could be on the same machine or a different one. Java Remote Method Invocation (Java RMI) enables the programmer to create distributed Java technology-based to Java technology-based
applications in which the methods of remote Java objects can be invoked from other Java virtual machines possibly on different hosts
In mathematics and computer programming, which is the correct order of mathematical operators ?
A. Addition, Subtraction, Multiplication, Division
B. Division, Multiplication, Addition, Subtraction
C. Multiplication, Addition, Division, Subtraction
D. Addition, Division, Modulus, Subtraction
B. Division, Multiplication, Addition, Subtraction
C. Multiplication, Addition, Division, Subtraction
D. Addition, Division, Modulus, Subtraction
Answer: Option B
Explanation:
Simply called as BODMAS (Brackets, Order, Division, Multiplication, Addition and Subtraction).
Simply called as BODMAS (Brackets, Order, Division, Multiplication, Addition and Subtraction).
Mnemonics are often used to help students remember the rules, but the rules taught by the use of acronyms can be misleading. In the United States the acronym PEMDAS is common. It stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. In other English speaking countries, Parentheses may be called Brackets, or symbols of inclusion and Exponentiation may be called either Indices, Powers or Orders, and since multiplication and division are of equal precedence, M and D are often interchanged, leading to such acronyms as BEDMAS, BIDMAS, BODMAS, BERDMAS, PERDMAS, and BPODMAS.
Java program to reverse a string
import java.util.*;
class ReverseString
{
public static void main(String args[])
{
String original, reverse = "";
Scanner in = new Scanner(System.in);
{
public static void main(String args[])
{
String original, reverse = "";
Scanner in = new Scanner(System.in);
System.out.println("Enter a string to reverse");
original = in.nextLine();
original = in.nextLine();
int length = original.length();
for ( int i = length - 1 ; i >= 0 ; i-- )
reverse = reverse + original.charAt(i);
reverse = reverse + original.charAt(i);
System.out.println("Reverse of entered string is: "+reverse);
}
}
}
}
What is a sub query and what are the different types of subqueries?
Sub Query is also called as Nested Query or Inner Query which is used to get data from multiple tables. A sub query is added in the where clause of the main query.
There are two different types of subqueries:
Correlated sub query
A Correlated sub query cannot be as independent query but can reference column in a table listed in the from list of the outer query.
Non-Correlated subquery
This can be evaluated as if it were an independent query. Results of the sub query are submitted to the main query or parent query
What are temporal data types in Oracle?
Oracle provides following temporal data types:
Date Data Type – Different formats of Dates
TimeStamp Data Type – Different formats of Time Stamp Interval Data Type – Interval between dates and time
TimeStamp Data Type – Different formats of Time Stamp Interval Data Type – Interval between dates and time
Subscribe to:
Posts (Atom)