Here is a nice playlist for Spring Boot beginners videos from Java Brains – https://www.youtube.com/playlist?list=PLqq-6Pq4lTTbx8p2oCgcAQGQyqN8XeA1x
Basic Java knowledge refreshed using Sololearn
Find the first and second largest number in a series – without using arrays or functions
This is just a revision of my school memories. Language used is Java.
import java.util.Scanner;
public class testmain {
public static void main(String[] args) {
int large = 0; // there is a possible logic error, ignore
int slarge = 0; // there is a possible logic error, ignore
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of elements");
int N = scanner.nextInt();
for (int c = 0;c<N;c++) {
int num = scanner.nextInt();
if (num > large) {
large = num;
}
if (num != large && num > slarge) {
slarge = num;
}
}
System.out.println(
"Largest = " + large +
"\nSecond Largest = " + slarge
);
}
}
Upload/Download file to/fro MongoDB in Java
// This code is just for my reference
public static void main(String[] args) {
Logger mongoLogger = Logger.getLogger( "org.mongodb.driver" );
mongoLogger.setLevel(Level.SEVERE);
MongoClient mongoClient = MongoClients.create();
MongoDatabase database = mongoClient.getDatabase("testdb");
GridFSBucket gridFSFilesBucket = GridFSBuckets.create(database);
ObjectId fileId = new ObjectId();
try {
InputStream streamToUploadFrom = new FileInputStream(new File("d:\\200mb.mkv"));
// GridFSUploadOptions options = new GridFSUploadOptions()
// .chunkSizeBytes(1000)
// .metadata(new Document("type", "presentation"));
fileId = gridFSFilesBucket.uploadFromStream("myfile", streamToUploadFrom);
System.out.println("ObjectID" + fileId);
} catch(FileNotFoundException ex) {
System.out.println("Error" + ex.getMessage());
}
try {
FileOutputStream streamToDownloadTo = new FileOutputStream("d:/out.mkv");
gridFSFilesBucket.downloadToStream(fileId , streamToDownloadTo);
streamToDownloadTo.close();
System.out.println("Finished!");
} catch (IOException e) {
// handle exception
}
}