Question

In: Computer Science

Define and give examples for better understanding 1. What are all the data types of java...

Define and give examples for better understanding

1. What are all the data types of java script?

2. What are all the SQL joins?

3. What is polymorphism in your own words?

4. What is a constructor?

Solutions

Expert Solution

Here is the solution if you have any doubt then please write in the comment section.

Please give feedback.

Solution:

(1) What are all the data types of java script?

Solution:

Basically, There are two types of data types in JavaScript
first is Primitive and second is Non-primitive

Primitive Data types are:

String: It represents the string i mean a sequence of characters.
The string data type in JavaScript can be any group of characters enclosed by a single or double-quotes or by backticks.
Example: 
var str1 = “Ram”;  // This is a string primitive type or string literal
var str2= ‘Ram’;
var str3 = `ram`;
var str4 = String(‘ram’); //create string using String() function

Number: A number data type can be an integer, a floating point value, an exponential value, a ‘NaN’ or a ‘Infinity’.
example: 
var a=10;  // integer value
var b=22.6;  // a number containing a decimal 
var c = 5e2 //  an exponential value which evaluates to 5*100;

Boolean: It represents two values true or false
It is mostly used to check a logical condition. Thus Booleans are logical data types that can be used for comparison of two variables or to check a condition. The true and false implies a ‘yes’ for ‘true’ and a ‘no’ for ‘false in some places when we check a condition or the existence of a variable or a value.

Example:
If(a<b)
{//statement 1
}
if a is less than b then it will a<b will give true and statement1 will execute otherwise it will be false and the statement will not execute

Undefined: It represents undefined value, it means the value is not defined yet but declared.

Example:
var result;
console.log(result); // This will return undefined.


Null: It represents null, it means no value at all. The null in JavaScript is a data type that is represented by only one value, the ‘null’ itself. A null value means no value.

Example:
var result=null;
console.log(result); // This will return null.

Symbol: The symbol data type defines a property of an object which is private to the object. It refers to the ‘key’ of the key-value pair of an object.

Example:

var objectA = {
   name: ‘RPM’;
}
var occupation=Symbol(‘Tutor’);

The function Symbol() is used to create a new symbol. Here we have created a symbol ‘occupation’ with the value ‘Tutor’ for the above object ‘objects’.


Non Primitive Data types are:
Object: It represents an instance through which we can access members of a class

Example:
var obj1 = { a: 5, b: 6 };
here a and b are data member of object

Array: It represents a group of similar values [of one data type]. An array contains more than one value with a numerical index, where the index starts from 0. Thus it holds its value in a key-value pair. An array is immutable in javascript. It means if we will try to change any value of the array then a new object will be created.

Example:
var arr= [1, 2, 3,4,5,6];

we can get value by using an index like arr[0] will give 1, arr[1] will give 2

RegExp : It represents regular expression and used for pattern matching.Regular expressions are often used with the two string methods: search() and replace().
The search() method uses an expression to search for a match, and returns the position of the match.
The replace() method returns a modified string where the pattern is replaced.

Example:
var patt = /rpm/i;

/rpm/i  is a regular expression.
rpm  is a pattern (to be used in a search).
i  is a modifier (modifies the search to be case-insensitive).

(2) What are all the SQL joins?

Solution:

A SQL Join statement is used to combine data or rows from two or more tables based on a common field between them. Different types of Joins are:

(1)INNER JOIN: The INNER JOIN keyword selects all rows from both the tables as long as the condition satisfies. This keyword will give the result by combining all rows from both the tables where the condition satisfies i.e value of the common field will be the same.

(2)LEFT JOIN: This join returns all the rows of the table on the left side of the join and matching rows for the table on the right side of the join. For the rows for which there is no matching row on the right side, the result will contain null.

(3) RIGHT JOIN: RIGHT JOIN is similar to LEFT JOIN. This join returns all the rows of the table on the right side of the join and matching rows for the table on the left side of the join. For the rows for which there is no matching row on the left side, the result will contain null.

(4) FULL JOIN: FULL JOIN creates the result-set by combining the result of both LEFT JOIN and RIGHT JOIN. The result will contain all the rows from both the tables. For the rows for which there is no matching, the result will contain NULL values.

Basic Query:

SELECT table1.column1,table1.column2,table2.column1,........
FROM table1 
[INNER JOIN / LEFT JOIN / RIGHT JOIN / FULL JOIN] table2
ON table1.matching_column = table2.matching_column;

(3) What is polymorphism in your own words?

Solution:

Polymorphism means having many forms. Simply we can define polymorphism as the ability of a message to be displayed in more than one form. A real-life example of polymorphism is like A person at the same time can have different characteristics. Like a man at the same time is a father, a husband, an employee. So here the person is one but this person has many characteristics. i.e many forms
Polymorphism is of two types of static polymorphism or dynamic polymorphism.

Method overloading is a type of Static polymorphism.

Example: Like we want to find some the integers, the sum of floats then we can have a function/method with the same name and both methods will return sum but they have different arguments.

int sum(int a,int b)
{
return a+b;
}

float sum(float a,float b)
{
return a+b;
}

Here no need for inheritance and this polymorphism will take place at compile time.

Method overriding is a type of Dynamic polymorphism. For dynamic polymorphism, inheritance is required. If we have any one method in the base class and we want another implementation of that method in over base class then we can override that method and give a different implementation, this is called dynamic polymorphism.

In dynamic polymorphism, both names of the method and argument must be the same.

Example:
class Base
{
int value(int x)
{
return 5*x;
}
}
class Derived extends Base
{
int value(int x)
{
return 8*x;
}
}

we can easily see that both method name and argument are same but implementation is different , this is called dynamic polymorphism, and it takes place based on runtime object.

(4) What is a constructor?

Solution:

The main purpose of the constructor is not to create an object.
the new operator is used to creating an object in java,c++, python, etc.
Whenever we are creating an object then some piece of code always executing to provide initialization of the object that piece of code is known as a constructor.

Hence the main purpose of the constructor is to provide initialization of objects. It means to provide value for instance variables of the object.

The name of the constructor should be the same as the class name.
If we don't provide any constructor then automatically a default constructor with no argument is created, and it will only be created if we have not defined any constructor to the class.

Example:

class Person
{
        int id;
        //constructor with no argument
        Person()
        {}

        //constructor with argument
        Person(int ids)
        {
                id=ids;
        }

        //copy constructor
        Person(Person p)
        {
                id=p.id;
        }
}

If you have any type of doubts then please write in the comment section, I will feel happy to help you.

Please give feedback.

Thank You!


Related Solutions

Define for better understanding & give example. do not copy paste google answers of definitions. 1....
Define for better understanding & give example. do not copy paste google answers of definitions. 1. What is the difference between a set and a list? 2. What is inheritance ? 3. Difference between a class and an object? How do classes relate to objecst? 4. How would you create an SQL table which makes use of customers information table and vehicle ownership over time? 5. How would you create a function that checks if a string is a palindrome?
Explain different types of data used in C#.•Illustrate and give examples of all predefined data types...
Explain different types of data used in C#.•Illustrate and give examples of all predefined data types in C#. C sharp
Define Fraud and give specific examples of three types
Define Fraud and give specific examples of three types
1. Give examples of the types of risks companies face. Give examples.
1. Give examples of the types of risks companies face. Give examples.
Define microbial nutritional types with respect to carbon and energy sources. Define and give examples of...
Define microbial nutritional types with respect to carbon and energy sources. Define and give examples of the following: photoautotroph, chemoautotroph, photoheterotroph, chemoheterotroph, saprobe, parasite.
: Define and give examples of three types of corporate mergers, and explain the role of...
: Define and give examples of three types of corporate mergers, and explain the role of leveraged buyouts and taking a firm private.
Question 1: In order to get a better understanding of which types of people buy their...
Question 1: In order to get a better understanding of which types of people buy their product, a large company wanted to estimate the proportion of customers who are considered low income. They took a random sample (a very small subset) of 500 customers and found that 210 were low income. a) Check to see if conditions (there are 4) are met to have a valid confidence interval. b) What would happen to the distribution of sample proportions if one...
1- Define and give examples of compensating wage differentials. 2- What is the impact of a...
1- Define and give examples of compensating wage differentials. 2- What is the impact of a minimum wage law on unskilled labor? Give examples
Define, give examples, and discuss the role of several instances in supporting arguments. Define, give examples,...
Define, give examples, and discuss the role of several instances in supporting arguments. Define, give examples, and discuss the role of statistics in supporting arguments.
Define and give 2 examples each for strategic, operational, and administrative types of decisions. Definition &...
Define and give 2 examples each for strategic, operational, and administrative types of decisions. Definition & Examples Strategic Decisions Operational Decisions Administrative Decisions
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT