Java Hyd Team
745 subscribers
986 photos
39 videos
670 files
690 links
https://teamhydteam.my.canva.site/

Can visit us on our website 😊
Still working on it 😊
Download Telegram
Forwarded from Aman Raj
11. Java - Generic

public class Generic<T> {

private Tt;

public void set(Tt) { this.t=t; }

public T get() {

return t;

public void inspect (U u) (

System.out.println("T: "+t.getClass().getName()); System.out.println("U:"u.getClass().getName());

public static void main(String[] args) {

Generic<Integer> integerBox = new Generic<Integer>();

integerBox.set(10);

integer Box. inspect (2);

Pick ONE option

T: java.lang.Integer U: java.lang.Integer

T: java.lang.Integer U: java.lang.Object

Runtime Exception

Compilation Error

Clear Selection
Forwarded from Aman Raj
12. Java 8

Which of the following are not valid lambda expressions?

Pick ONE option

0->0

() -> "Ram"

() -> {return "Shyam";}

(Integer i) -> return "Alan" + i;

Clear Selection
πŸ‘1
---

## Problem: Compare User Lists

### Background

You are tasked with developing a backend system for a company’s administrative portal. This system manages user information and allows administrators to view, update, and add new users. Your task is to implement a function that compares the current state of user data in the database with a new set of data and determines which records need to be updated and which ones need to be inserted.

### Problem Statement

You are given two lists of users:

1. Current Users List (from Database): This list represents the users currently in the database. Each user is represented by an ID and a set of attributes.
2. New Users List (from UI): This list represents the updated set of user data, including new users and changes to existing ones. Users with an ID of 0 are new users that need to be inserted, while users with a positive ID are existing users that may need to be updated.

You need to implement a function that processes these lists and returns two lists:
Updated Users: A list of users that exist in the database but have different attributes compared to the new list.
Inserted Users: A list of users that are present in the new list with an ID of 0 and do not exist in the database.

### Input

First Line: An integer n, the number of users in the current database.
Next n Lines: Each line contains a comma-separated string representing a user in the current database in the format:
  ID,First Name,Last Name,Age,Email,Gender,Country,City,Address,Zip Code,Phone Number,Department,Role,Date Joined,Salary,Status
Next Line: An integer m, the number of users in the new list.
Next m Lines: Each line contains a comma-separated string representing a user in the new list in the same format as the database list.

### Output

Updated Users: Print the number of users that need to be updated.
Inserted Users: Print the number of users that need to be inserted.

### Constraints

The number of users n and m will be between 1 and 10^4.
All fields are non-empty strings except for ID, Age, Salary which are integers.
User IDs are unique in each list.

### Example

Input:2
1,Firste,Laste,40,ema110@gmail.com,Male,Countrye,City,Address,ZipCodes,Phone Number,Departmente,Role,2016.07.18,656,Active
2,Firstl,Last1,50,email1@gmail.com,Female,Country1,Cityl,Address1,ZipCodel,Phone Number1,Department1,Rolel,2018.10.08,778,Inactive
2
1,First,Laste,40,emaile@gmail.com,Male,Countrye,City@,Address,ZipCode,Phone Number,Departmente,Role6,2017.02.24,176,Active
0,NewFirst,NewLast,30,newemail@gmail.com,Female,NewCountry,NewCity,NewAddress,NewZip,NewPhone,NewDept,NewRole,2021.03.12,600,Active
Output:Updated Users: 1
Inserted Users: 1
### Explanation

1. User with ID 1 in the database has been updated. The attributes have changed in the new list.
2. User with ID 0 is a new user that should be inserted into the database.

### Function Signature
java
public static List<User>[] compareUsers(List<User> usersListInDB, List<User> newUsersList);
---
Question:
Given the following table schemas and requirements, write an SQL query to obtain a combined list of assets (bonds and stocks) with their total cash flows or dividends.
Schemas
Table bonds
id (INT, Primary Key): Unique identifier for each bond.
name (VARCHAR): Name of the bond.
Table bond_payments
id (INT, Primary Key): Unique identifier for each bond payment.
bond_id (INT, Foreign Key): ID of the bond (references bonds.id).
cash_flow (DECIMAL): Amount of cash flow for the bond.
Table stocks
id (INT, Primary Key): Unique identifier for each stock.
name (VARCHAR): Name of the stock.
Table stock_payments
id (INT, Primary Key): Unique identifier for each stock payment.
stock_id (INT, Foreign Key): ID of the stock (references stocks.id).
dividend (DECIMAL): Amount of dividend for the stock.
Requirements
Calculate the total cash flows for each bond and the total dividends for each stock.
Include only those bonds and stocks where the total cash flows or dividends are greater than $2000.00.
Combine the results for both bonds and stocks into a single result set.
Ensure that the results include the name of the asset, the type of asset (either 'Bond' or 'Stock'), and the total cash flows or dividends rounded to two decimal places.
Order the final result set by the name of the asset in ascending order.
SQL Query
Write an SQL query to meet the above requirements.
---

3. REST API: Top Articles

Query a REST API to get a list of articles. Given an integer limit, return the top limit article names ordered by decreasing comment count, and then by decreasing alphabetical order for articles with the same comment count.

To access the collection of articles, make an HTTP GET request to:http://jemack.hascheccnck.com/api/articles?page=<pageNumber>where <pageNumber> is an integer. The total_pages field in the JSON response indicates the total number of pages available.

The response is a JSON object with the following fields:
page: The current page of the results.
per_page: The maximum number of records returned per page.
total: The total number of records on all pages of the result.
total_pages: The total number of pages with results.
data: An array of objects containing the records returned on the requested page.

Each record in data has the following schema:
title: The title of the article, may be null.
url: The URL of the article.
author: The username of the author of the article.
num_comments: The number of comments the article has, may be null.
story_id: An identifier of the story related to the article, may be null.
story_title: The title of the story related to the article, may be null.
story_url: The URL of the story related to the article, may be null.
parent_id: Identifier of the parent of the article, may be null.
created_at: The date and time the record was created.

Requirements:

1. Retrieve the article name.
   - If the title field is not null, use title.
   - Otherwise, if the story_title field is not null, use story_title.
   - If both fields are null, ignore the article.

2. Sort the articles first by num_comments in decreasing order. If there are ties, sort alphabetically in decreasing order by article name.

3. Return a list of the top limit article names.

Function Signature:
java
public static List<String> topArticles(int limit) throws IOException, InterruptedException, ParseException;
Input Format for Custom Testing:

An integer limit on the first line.

Sample Input for Custom Testing:
2
Sample Output:
UK Votes to Leave EU
FCC Repeals Net Neutrality Rules
Explanation:

The limit value is 2, so return the names of the top two articles based on the number of comments. The top articles are:
1. Title: "FCC Repeals Net Neutrality Rules", Comments: 1397
2. Title: "UK Votes to Leave EU", Comments: 2537

Their names are their titles because they are not null. The article with more comments is listed first. In case of ties in comment count, titles are sorted alphabetically in descending order.

---
πŸ‘2
### Question:

You are tasked with querying a REST API to get a list of articles and processing this data to obtain the top article names based on their comment count.

#### API Specification

Base URL: https://jsonmock.hackerrank.com/api/articles
Endpoint Format: https://jsonmock.hackerrank.com/api/articles?page=<pageNumber>
Response Schema:

 json
  {
    "page": <current_page_number>,
    "per_page": <number_of_records_per_page>,
    "total": <total_number_of_records>,
    "total_pages": <total_number_of_pages>,
    "data": [
      {
        "title": <article_title>,  // may be null
        "url": <article_url>,
        "author": <author_username>,
        "num_comments": <number_of_comments>,  // may be null
        "story_id": <story_id>,  // may be null
        "story_title": <story_title>,  // may be null
        "story_url": <story_url>,  // may be null
        "parent_id": <parent_id>,  // may be null
        "created_at": <creation_datetime>
      }
    ]
  }
 
#### Requirements

1. Fetch and process the data from all available pages of the API.
2. For each article:
   - Use the title if it is not null.
   - If the title is null, use the story_title if it is not null.
   - Ignore the article if both title and story_title are null.
3. Sort the articles by the number of comments in descending order.
4. If there is a tie in the number of comments, sort the articles alphabetically by their title in descending order.
5. Return the names of the top limit articles based on the above sorting criteria.

#### Function Signature
java
public static List<String> topArticles(int limit) throws IOException, InterruptedException, ParseException;
#### Input

An integer limit representing the number of top articles to return.

#### Output

A list of strings where each string is the name of an article, sorted according to the criteria specified.

---
DOC-20240829-WA0007.
67.7 KB
Document from πŸ’°
Morgan Stanley virtual interview round question
Hiring for Java 17-21 developer experience 5+ years
Don't Miss out this opportunity
those who filled out form you will get details in next 2-3 days
Those who filled this form let me know if all of you received the referral link
Be prepared guys for the system design also as now every MNC is going to ask
Looking for Angular developer with 2+ year experience in my team expected hike 20-30% hike on CTC