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: