Monday, May 24, 2021
Thursday, May 13, 2021
Tuesday, May 11, 2021
Monday, May 10, 2021
Wednesday, May 5, 2021
Sunday, May 2, 2021
Saturday, April 24, 2021
Interview Questions - Java
-
-
What is OOP?
Object Oriented Programming is programming paradigm, that works on the following principals:- Abstraction
- Inheritance
- Polymorphism
- Encapsulation
-
What is Abstraction?
Abstraction is the process of hiding certain details and showing only essential information to the user. -
What is Polymorphism?
Polymorphism is a concept by which we can perform a single action in different ways. ... So polymorphism means many forms. -
What is Inheritance?
Inheritance is a mechanism in which one object acquires all the properties and behaviors of a parent object. -
What is immutable Object and how to create a immutable class?
-
-
-
What is JDK,JRE JVM?
-
Difference between prasing and type casting?
-
What is constructor? difference between constructor and method?
-
What are access specifiers in java ?
-
Write a program to check given string is Anagram or not?
-
-
-
What is Functional interface?
-
Abstract class Vs Interface
-
Overloading Vs Overriding
-
What is marker interface?
-
Write a program to delete duplicate elements from the array and display then ascending order
-
-
-
ArrayList Vs LinkedList
-
HashMap Vs HashTable
-
HashMap vs ConcurrentHashMap
-
How HashMap works internally?
-
Write a program to implement custom hashmap
-
-
-
Callable Vs Runnable
-
Synchronized block vs method
-
What are the different ways to create thered in java?
-
How to run multiple threads simltaniously
-
Write a program to create singleton class
-
-
-
What is design patterns?
-
finally Vs finalize
-
What are the SOLID principals?
-
What is the default capacity of LinkedList, HashMap ?
-
Write a program for builder and factory patterns
-
-
-
What is Streams?
-
Inner classes Vs Lambdas
-
What is difference between stream vs parallel stream?
-
Future vs CompletableFuture
-
Write a program to convert list of string to map
where key is string and length of the string is value using streams
-
-
-
Where do you volatile keyword?
-
volatile vs transient
-
How to store custom object as key in HashMap?
-
What is exception? What are different ways to create custom exception
-
Write a program to create custom exception class?
-
-
-
What is serialaization?
-
What is serial version id?
-
this Vs Super in java?
-
What are different ways to create object?
-
Write a program to create custom annotation?
-
-
-
How garbage collectors work in JVM?
-
What is major GC and minor GC?
-
What is class loader?
-
How to increase memeory size while running java applicaation?
-
Write a program to get max paid employee of the organization using java stream?
-
Friday, January 17, 2020
Bootstrp + jQuery + news REST API example
The directory structure:
Live : https://jsl-news.glitch.me/
newspp
- css
- main.css
- js
- news.js
- index.html
main.css
#subBtn{
margin-top: 13%;
}
index.html
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="css/main.css">
<title>News - Items</title>
</head>
<body>
<div class="py-3 bg-primary text-white text-center">
<h3>Search worldwide news with code</h3>
<p class="lead">Get breaking news headlines, and search for articles from over 30,000 news sources and blogs with our news API</p>
</div>
<div class="container">
<h5 class="text-muted text-center mt-2">Please select the details to get updated news</h5>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3">
<label for="country">Select Country</label>
<select class="form-control" id="country">
<option value="in">India</option>
<option value="us">United State</option>
<option value="sg">Singapore</option>
</select>
</div>
<div class="col-md-3">
<label for="category">Select Category</label>
<select class="form-control" id="category">
<option value="sports">Sports</option>
<option value="health">Health</option>
<option value="business">Business</option>
</select>
</div>
<div class="col-md-3">
<button id="subBtn" class="btn btn-primary">Submit</button>
</div>
</div>
<!--New items-->
<div class="row mt-5">
<div class="col-md-6 offset-md-3" id="showResult">
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="js/news.js"></script>
</body>
</html>
JavaScript: news.js
const url = "https://newsapi.org/v2/top-headlines?";
const apikey = "5c636a468a90465aa7cab199265d7299"; // Change the key by registering with news api
class News{
constructor(title,author,description,urlToImage){
this.title = title;
this.author = author;
this.description = description;
this.urlToImage = urlToImage;
}
}
subBtn = document.querySelector("#subBtn");
function showNews(news){
str ="";
count = 1;
for(let item of news){
str += `<b>#${count++}<br>
<div class="card mt-2 mb-2">
<img src="${item.urlToImage}" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">${item.title}</h5>
<p class="card-text">
<b>${item.author}</b>
<br>
${item.description}
</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
`
}
document.querySelector("#showResult").innerHTML = str;
}
subBtn.addEventListener('click',(e)=>{
let countryName = document.querySelector("#country").value;
let categoryValue = document.querySelector("#category").value;
let reqURL = `${url}country=${countryName}&apiKey=${apikey}&category=${categoryValue}`;
fetch(reqURL).then(rawData=>{
return rawData.json();
}).then(data=>{
news = [];
articles = data["articles"];
for(let article of articles){
newsItem = new News(article.title,article.author,article.description,article.urlToImage);
news.push(newsItem);
}
showNews(news);
}).catch(error=>{
alert("While getting news we got ",error);
})
})
Sample output:
Sunday, January 12, 2020
Monday, August 27, 2018
Python Programming Questions
name = "ThulasiDhasan" map = {} for ch in name: map[ch] = map.get(ch, 0) + 1 print(map)
2. Flatten list of the list in Python
lst = [[2, 3, 5], [6, 7, 8], [9, 0, 1]] t_lst = [ele for sublist in lst for ele in sublist] print(t_lst)
Thursday, March 15, 2018
Python project - Contactbook
MySQL
Python 3.x
Libraries used :
pymsql , beatutifultable
Installation of Libraries using pip
pip install pymsql
pip install beautifultable
This application performs basic CRUD orations to demonstrate Python end-to-end application.
Note: Update and delete methods were not called from main, you can give a try...
contact.py
from collections import namedtuple Contact = namedtuple("Contact", ["cid","name", "email", "mobile"])
config.py
mysql = { 'host': 'localhost', 'user': 'root', 'passwd': 'password', 'db': 'counselor_db'}
util.py
import pymysql import config class DbUtil: @staticmethod def get_connection(): try: con = pymysql.connect(config.mysql['host'], config.mysql['user'],config.mysql['passwd'],config.mysql['db']) except pymysql.MySQLError as error: print('Exception number: {}, value {s}'.format(error.args[0], error)) raise else: return con @staticmethod def close_connection(conn): try: conn.close() except pymysql.MySQLError as error: print("While closing connection ...") print('Exception number: {}, value {!r}'.format(error.args[0], error)) raise @staticmethod def close_cursor(cursor): try: cursor.close() except pymysql.MySQLError as error: print("While closing the cursor ...") print('Exception number: {}, value {!r}'.format(error.args[0], error)) raise
dboperations.py
import config from util import DbUtil import pymysql from contact import Contact class ContactDbOperations: def add_contact(self, new_contact): try: connection = DbUtil.get_connection() with connection.cursor() as cursor: cursor.execute("insert into contact(name,email,mobile) values(%s,%s,%s)", (new_contact.name , new_contact.email , new_contact.mobile)) connection.commit() except pymysql.MySQLError as error: print("While inserting Data ...") print('Exception number: {}, value {!r}'.format(error.args[0], error)) finally: DbUtil.close_connection(connection) DbUtil.close_cursor(cursor) def get_contact(self, cid): try: conn = DbUtil.get_connection() cursor = conn.cursor() cursor.execute("select cid, name, email, mobile from contact where cid = %s", cid) contact = Contact(*cursor.fetchone()) return contact except pymysql.DatabaseError as error: print("While getting data from DB using id... ") print('Exception number: {}, value {!r}'.format(error.args[0], error)) finally: DbUtil.close_connection(conn) DbUtil.close_cursor(cursor) def update_contact(self, contact): try: conn = DbUtil.get_connection() cursor = conn.cursor() cursor.execute("update contact set name = %s ,email = %s, mobile = %s where cid = %s", contact) conn.commit() except pymysql.DatabaseError as error: print("While updating ... ") print('Exception number: {}, value {!r}'.format(error.args[0], error)) finally: DbUtil.close_connection(conn) DbUtil.close_cursor(cursor) def get_all_contacts(self): try: connection = DbUtil.get_connection() with connection.cursor() as cursor: cursor.execute("select cid, name, email, mobile from contact") rows = cursor.fetchall() contacts = self.get_list_data(rows) return contacts except Exception as error: print("While retrieving data ... ") print('Exception number: {}, value {!r}'.format(error.args[0], error)) finally: if connection: DbUtil.close_connection(connection) DbUtil.close_cursor(cursor) def search_contact(self, search_str): try: connection = DbUtil.get_connection() with connection.cursor() as cursor: cursor.execute("select cid, name, email, mobile from contact where name like %s ", ('%' + search_str + '%')) rows = cursor.fetchall() contacts = self.get_list_data(rows) return contacts except Exception as error: print("While searching Data ...") print('Exception number: {}, value {!r}'.format(error.args[0], error)) finally: DbUtil.close_connection(connection) DbUtil.close_cursor(cursor) @staticmethod def delete_contact(cid): try: connection = DbUtil.get_connection() cursor = connection.cursor() cursor.execute("delete from contact where cid = %s ", cid) connection.commit() except pymysql.DatabaseError as error: print("While deleting data ...") print('Exception number: {}, value {!r}'.format(error.args[0], error)) finally: DbUtil.close_connection(connection) DbUtil.close_cursor(cursor) @staticmethod def get_list_data(rows): return [Contact(*row) for row in rows]
contactservice.py
from dboperations import ContactDbOperations from contact import Contact from beautifultable import BeautifulTable class ContactService: def __init__(self): self.cs = ContactDbOperations() def add_contact(self): name = input("Name : ") email = input("Email : ") mobile = input("Mobile : ") contact = Contact(0, name, email, mobile) self.cs.add_contact(contact) self.show_all_contacts() def show_all_contacts(self): contacts = self.cs.get_all_contacts() ContactService.paint_data_list(contacts) def search_contact(self): name = input("Enter search name :") contacts = self.cs.search_contact(name) if contacts: ContactService.paint_data_list(contacts) else: print("No data found with search name :{}".format(name)) @staticmethod def paint_data(data): table = BeautifulTable() table.column_headers = ["CID", "NAME", "EMAIL", "MOBILE"] table.append_row([data.cid, data.name, data.email, data.mobile]) print(table) @staticmethod def paint_data_list(data): table = BeautifulTable() table.column_headers = ["CID", "NAME", "EMAIL", "MOBILE"] for li in data: table.append_row([li.cid, li.name, li.email, li.mobile]) print(table)
main.py
if __name__ == '__main__': cs = ContactService() while True: print("*"*40) print("1. Add Contact 2. View All 3.Search 4. Exit") print("*"*40) choice = int(input("Enter your choice :")) if choice == 1: cs.add_contact() elif choice == 2: cs.show_all_contacts() elif choice == 3: cs.search_contact() elif choice == 4: exit() else: print("Enter only 1 to 4 ......")
Spring Boot 3 : JWT with SecurityFilterChain, AuthorizeHttpRequests, RequestMatchers
pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0...
-
Expression Language A primary feature of JSP technology version 2.0 is its support for an expression language (EL). An expres...
-
import java.util.List ; import java.util.Stack ; public class EvaluatingExpression { public static void main ( String [] arg...