Find Second Largest Number in Array – Infosys -CTS -TCS JAVA Interview Question
public class SecondLargestInArrayExample{  
	
	
	
public static int getSecondLargest(int[] a, int total,int k){  
int temp;  
for (int i = 0; i < total; i++)   
        {  
            for (int j = i + 1; j < total; j++)   
            {  
                if (a[i] > a[j])   
                {  
                    temp = a[i];  
                    a[i] = a[j];  
                    a[j] = temp;  
                }  
            }  
        }  
       return a[total-k];  
}  
public static void main(String args[]){  
int a[]={1,2,5,6,3,2,7};  /// 1,2,2,3,5,6,7   7-2 =5    0,1,2,3,4,
//int b[]={44,66,99,77,33,22,55};  

int n=a.length;
int k=3;
System.out.println("Second Largest: "+getSecondLargest(a,n,k));  
//System.out.println("Second Largest: "+getSecondLargest(b,7));  
}

}  
Generate Thumbnail from Video Using Java
public String generateThumnail(String videoUrl) {

		logger.info("************************************");

		FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(videoUrl);
		logger.info(" generateThumnail videoUrl---" + videoUrl);
		String fileName = videoUrl.substring(videoUrl.lastIndexOf('/') + 1);
		logger.info("generateThumnail fileName---" + fileName);
		fileName = fileName.substring(0, fileName.lastIndexOf("."));
		logger.info("generateThumnail fileName---1" + fileName);
		String path = thumbUrl + fileName + ".png";
		String filenameS3 = fileName + ".png";
		logger.info("generateThumnail filenameS3---1" + filenameS3);
		try {
			frameGrabber.start();
			Java2DFrameConverter aa = new Java2DFrameConverter();

			BufferedImage bi;
			Frame f = frameGrabber.grabKeyFrame();
			bi = aa.convert(f);
			while (bi != null) {
				ImageIO.write(bi, "png", new File(serverPath + fileName + ".png"));
				f = frameGrabber.grabKeyFrame();
				bi = aa.convert(f);
				File myFile = new File(serverPath + fileName + ".png");
				InputStream is = new FileInputStream(myFile);
				ObjectMetadata meta = new ObjectMetadata();
				meta.setContentType("image/png");
				meta.setContentLength(myFile.length());
				s3client.putObject(new PutObjectRequest(bucketNameThumb, filenameS3, is, meta)
						.withCannedAcl(CannedAccessControlList.PublicRead));

			}
			frameGrabber.stop();
		} catch (Exception e) {

			logger.info("Error Message: " + e.getMessage());
		}

		return path;

	}
Upload Video File in Amazon S3 Storage Using Java
package com.aws.momo.project.util;

import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Date;

import javax.annotation.PostConstruct;
import javax.imageio.ImageIO;
import javax.security.auth.message.callback.PrivateKeyCallback.Request;

import org.apache.http.HttpRequest;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.Java2DFrameConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.web.multipart.MultipartFile;

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.DeleteObjectRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.util.Base64;
import com.aws.momo.project.controller.MomoUsersController;

@Service
public class AmazonClient {
	private static Logger logger = LoggerFactory.getLogger(AmazonClient.class);

	private AmazonS3 s3client;

	@Value("${amazonProperties.videoUrl}")
	private String videoUrl;
	@Value("${amazonProperties.audioUrl}")
	private String audioUrl;
	@Value("${amazonProperties.thumbUrl}")
	private String thumbUrl;
	@Value("${amazonProperties.localPath}")
	private String localPath;
	@Value("${amazonProperties.serverPath}")
	private String serverPath;
	@Value("${amazonProperties.secretKey}")
	private String secretKey;
	@Value("${amazonProperties.accessKey}")
	private String accessKey;
	@Value("${amazonProperties.bucketNameVideo}")
	private String bucketNameVideo;
	@Value("${amazonProperties.bucketNameSound}")
	private String bucketNameSound;
	@Value("${amazonProperties.bucketNameThumb}")
	private String bucketNameThumb;
	@Value("${amazonProperties.bucketName}")
	private String bucketName;

	@SuppressWarnings("deprecation")
	@PostConstruct
	private void initializeAmazon() {
		AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
		this.s3client = new AmazonS3Client(credentials);
	}

	private File convertMultiPartToFile(MultipartFile file) throws IOException {

		File convFile = new File(file.getOriginalFilename());
		FileOutputStream fos = new FileOutputStream(serverPath + convFile);
		fos.write(file.getBytes());
		fos.close();
		return convFile;
	}

	private String generateFileName(MultipartFile multiPart) throws IOException {
		return new Date().getTime() + "-" + multiPart.getOriginalFilename().replace(" ", "_");
	}

	public String uploadVideoTos3bucket(MultipartFile file) {

		logger.info("uploadVideoTos3bucket");
		String fileUrl = "";
		try {

			logger.info("file.getOriginalFilename() " + file.getOriginalFilename());
			logger.info("file.getContentType()" + file.getContentType());
			logger.info("file.getInputStream() " + file.getInputStream());
			logger.info("file.toString() " + file.toString());
			logger.info("file.getSize() " + file.getSize());
			logger.info("file.getBytes() " + file.getBytes());
			logger.info("file.hashCode() " + file.hashCode());
			logger.info("file.getClass() " + file.getClass());
			logger.info("file.isEmpty() " + file.isEmpty());

			InputStream is = file.getInputStream();
			String keyName = generateFileName(file);

			logger.info("keyName" + keyName);

			logger.info("Uploading a new object to S3 from a uploadVideoTos3bucket\n");
			ObjectMetadata meta = new ObjectMetadata();
			meta.setContentType("video/mp4");
			meta.setContentLength(file.getSize());
			s3client.putObject(new PutObjectRequest(bucketNameVideo, keyName, is, meta)
					.withCannedAcl(CannedAccessControlList.PublicRead));

			logger.info("************************************");

			fileUrl = videoUrl + keyName;

		} catch (AmazonServiceException ase) {
			logger.info("Caught an AmazonServiceException, which " + "means your request made it "
					+ "to Amazon S3, but was rejected with an error response" + " for some reason.");
			logger.info("Error Message:    " + ase.getMessage());
			logger.info("HTTP Status Code: " + ase.getStatusCode());
			logger.info("AWS Error Code:   " + ase.getErrorCode());
			logger.info("Error Type:       " + ase.getErrorType());
			logger.info("Request ID:       " + ase.getRequestId());

		} catch (AmazonClientException ace) {

			logger.info("Caught an AmazonClientException, which " + "means the client encountered "
					+ "an internal error while trying to " + "communicate with S3, "
					+ "such as not being able to access the network.");
			logger.info("Error Message: " + ace.getMessage());
		} catch (IOException e) {
			logger.info("Error Message: " + e.getMessage());
		}

		return fileUrl;
	}

	


}
Application.yml
amazonProperties:
  videoUrl: 
  audioUrl: 
  thumbUrl: 
  localPath: 
  serverPath: 
   accessKey: 
  secretKey: 
  bucketNameVideo: 
  bucketNameSound:  
  bucketNameThumb:
  bucketName: 
Upload Video File in Amazon S3 Storage Using Spring Boot

Upload Video File in Amazon S3 Storage Using Spring Boot

package com.aws.momo.project.util;

import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Date;

import javax.annotation.PostConstruct;
import javax.imageio.ImageIO;
import javax.security.auth.message.callback.PrivateKeyCallback.Request;

import org.apache.http.HttpRequest;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.Java2DFrameConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.web.multipart.MultipartFile;

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.DeleteObjectRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.util.Base64;
import com.aws.momo.project.controller.MomoUsersController;

@Service
public class AmazonClient {
	private static Logger logger = LoggerFactory.getLogger(AmazonClient.class);

	private AmazonS3 s3client;

	@Value("${amazonProperties.videoUrl}")
	private String videoUrl;
	@Value("${amazonProperties.audioUrl}")
	private String audioUrl;
	@Value("${amazonProperties.thumbUrl}")
	private String thumbUrl;
	@Value("${amazonProperties.localPath}")
	private String localPath;
	@Value("${amazonProperties.serverPath}")
	private String serverPath;
	@Value("${amazonProperties.secretKey}")
	private String secretKey;
	@Value("${amazonProperties.accessKey}")
	private String accessKey;
	@Value("${amazonProperties.bucketNameVideo}")
	private String bucketNameVideo;
	@Value("${amazonProperties.bucketNameSound}")
	private String bucketNameSound;
	@Value("${amazonProperties.bucketNameThumb}")
	private String bucketNameThumb;
	@Value("${amazonProperties.bucketName}")
	private String bucketName;

	@SuppressWarnings("deprecation")
	@PostConstruct
	private void initializeAmazon() {
		AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
		this.s3client = new AmazonS3Client(credentials);
	}

	private File convertMultiPartToFile(MultipartFile file) throws IOException {

		File convFile = new File(file.getOriginalFilename());
		FileOutputStream fos = new FileOutputStream(serverPath + convFile);
		fos.write(file.getBytes());
		fos.close();
		return convFile;
	}

	private String generateFileName(MultipartFile multiPart) throws IOException {
		return new Date().getTime() + "-" + multiPart.getOriginalFilename().replace(" ", "_");
	}

	public String uploadVideoTos3bucket(MultipartFile file) {

		logger.info("uploadVideoTos3bucket");
		String fileUrl = "";
		try {

			logger.info("file.getOriginalFilename() " + file.getOriginalFilename());
			logger.info("file.getContentType()" + file.getContentType());
			logger.info("file.getInputStream() " + file.getInputStream());
			logger.info("file.toString() " + file.toString());
			logger.info("file.getSize() " + file.getSize());
			logger.info("file.getBytes() " + file.getBytes());
			logger.info("file.hashCode() " + file.hashCode());
			logger.info("file.getClass() " + file.getClass());
			logger.info("file.isEmpty() " + file.isEmpty());

			InputStream is = file.getInputStream();
			String keyName = generateFileName(file);

			logger.info("keyName" + keyName);

			logger.info("Uploading a new object to S3 from a uploadVideoTos3bucket\n");
			ObjectMetadata meta = new ObjectMetadata();
			meta.setContentType("video/mp4");
			meta.setContentLength(file.getSize());
			s3client.putObject(new PutObjectRequest(bucketNameVideo, keyName, is, meta)
					.withCannedAcl(CannedAccessControlList.PublicRead));

			logger.info("************************************");

			fileUrl = videoUrl + keyName;

		} catch (AmazonServiceException ase) {
			logger.info("Caught an AmazonServiceException, which " + "means your request made it "
					+ "to Amazon S3, but was rejected with an error response" + " for some reason.");
			logger.info("Error Message:    " + ase.getMessage());
			logger.info("HTTP Status Code: " + ase.getStatusCode());
			logger.info("AWS Error Code:   " + ase.getErrorCode());
			logger.info("Error Type:       " + ase.getErrorType());
			logger.info("Request ID:       " + ase.getRequestId());

		} catch (AmazonClientException ace) {

			logger.info("Caught an AmazonClientException, which " + "means the client encountered "
					+ "an internal error while trying to " + "communicate with S3, "
					+ "such as not being able to access the network.");
			logger.info("Error Message: " + ace.getMessage());
		} catch (IOException e) {
			logger.info("Error Message: " + e.getMessage());
		}

		return fileUrl;
	}

	


}
Application.yml
amazonProperties:
  videoUrl: 
  audioUrl: 
  thumbUrl: 
  localPath: 
  serverPath: 
   accessKey: 
  secretKey: 
  bucketNameVideo: 
  bucketNameSound:  
  bucketNameThumb:
  bucketName: 


List of the Best Advertising Agencies in India

  • DDB Mudra Communications
  • Grey India
  • Rediffusion (Y&R)
  • McCann-Erickson India Ltd
  • Ogilvy & Mather

1. DDB Mudra Communications

Introduction: It is known as India’s no. one and largest marketing communications services enterprise. It has expertisation under four disciplines (Media, Outdoor Advertsing, Retail, and Experiential).

It has bragged most of the awards in national and international film festivals like Cannes, Spikes Asia, Clio, Adfest, ABBYs, OAA etc. 25 March is still celebrated across all Mudra offices as Mudra Day. On When comparing the awards, it has won a Silver at the Olive Crown Awards in the ‘Young Green Art Director of the Year’ category.

History: It was founded on 25 March 1980 by A. G. Krishnamurthi and its headquarter is situated in Mumbai. Initially it started with only 15 employees, 500 sq.ft space and Rs 40,000 as startup capital But in 1990, Mudra signed a collaboration agreement with DDB Needham Worldwide.

In 2011, Mudra group was acquired BY Ominicom Group and named as DDB Mudra group and was merged with DDB worldwide. Currently It has three agency networks and six specialist agencies and eleven SBU.

Sonal Dabral is currently the Chairman and Chief Creative Officer of DDB Mudra Group.

Clients: Linen Club, Aditya Birla Group, Bharat Petroleum, Henkel, ACC Limited, Pepsi, Colgate, USHA, McDonalds, Reebok, Puma, Peter England, among many others.

2. Grey India

Introduction : Grey India is a part of Grey global group and is among the world’s top marketing and advertising agencies. They have shown some famous and effective work for some of the India’s most prestigious clients.

History: It was founded in 1917 by Lawrence Valenstein and has its headquarted in U.S. It has many subsidary branches named as Grey India, G2, GHG, GCI Group, MediaCom Worldwide, Alliance, G WHIZ, WING, Grey EMEA, ArcTouch. In India its office is situated in Mumbai which handle projects in retailing, visualdesign and fixture design.

Clients: Sensodyne, BNatural, Gillette, Dell, Crocin, Indian Air Force, Tic-Tac, Ferrero, Fortis Healthcare, Pantene, Cadbury Silk, Kinder Joy and many more.

3. Rediffusion (Y&R)

Rediffusion is a part of WPP group which is among the top leading advertising agencies in India. The company offers various services which includes advertisement, consultancy, web design, social media, promotion and program setups.

History: Rediffusion was started with a collaborative efforts of The three people, Diwan Arun Nanda, Ajit Balakrishnan, and Mohammed Khan in 1973. It was created for creating fearless, bold and passionate work. Rediffusion-Y&R is part of the Young & Rubicam network having 187 offices and 6,500 employees with offices in Mumbai, Delhi, Kolkata, Bangalore, Chennai, and in Sri Lanka, providing strategic and creative solutions to its clients.

Clients: Tata Motors, ITC Stationery, Eveready, Handard, Ambuja, Emani and many more.

4. McCann-Erickson India Ltd

Introduction: It is one of the highest ranked company of the advertising agencies in India . McCann has been awarded the Global Agency of the Year by Adweek thriceIt was also named as “Global Agency of the Year”.

History: It was founded in the year 1902 and 1912 McCann registered the world’s first advertising trademark ‘Truth Well Told’. McCann has offices in 120 countries spreading a global network in different parts of the country.They work through creative ideas born at the intersection of technology solutions, measurable performance and their unique understanding of people .

Clients

Maybelline, Loris,Spirite, Master card, Cococola, Microsoft and etc

5. Ogilvy & Mather

Introduction: Ogilvy & Mather is a well known and among the top Advertising companies in India who works on the principle of 360 degree branding on both local and global scale and has created a digital dominance for them. This agency works on “We sell or else.” These words sound simple, but are very meaninful to a ad agency. It is the only firm that grabbed network of the year at cannes for 3 consecutives year.

History

It was founded in the year 1948 by David Oligavy and has its offices in more than 150 countries worldwide. It operates in 6 cities throughout India and has become one of the leading advertising agencies in India.

Clients

American Express, IBM, Dove, NASCAR, Philips, Coke Zero, IKEA, UPS, Nationwide and Tiffany & Co.