-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnowing
More file actions
668 lines (453 loc) · 24 KB
/
Knowing
File metadata and controls
668 lines (453 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
Late night women security:
Stichting all cc cameras data to get grey area in the city i.e, area which is not covered under cctv footage.. so whenever a device enters to the grey area, mobile has to share the live location and update the emergency contacts by sharing location and vehicle details automatically. This helps in the location of the women to secure and updating the current situation to the emergency contacts.
Initially, this has to start from the available CC tv footage units and pin to the map and get the area wise specifications.
Process:
Divide the city into grids that covers some specific area.
List of the CC tvs in that grid.
Estimate how much area covered from each CC tv unit.
Differentiate area in each grid how much it is covered and how much is left out.
Repeat for each grid.
By doing this we will get the grey areas. This is exactly similar to the how Uber/Ola ride sharing apps do for their drivers to find the riders.
Usecase:
1.A person is leaving from one place to another. She might travel through number of grids that we differentiated. So if she enters grey area., app automatically alerts and do required events that we configured(sharing location/informing emergency contacts..).
Here we can configure the different conditions like.,
event if the person is in grey area for more than given time
event if the person is exiting the limited grids.
2. Recommendations to the person who lost in grey area.
If a person A is lost in grey area., she can find the other persons who are travelling in same area via suggestions. These recommended persons can be another person who is using same app or volunteers or police persons.
Technical steps:
It has to run entirely on Google Map APIs.
Hibernate cache mechanisms:
Transaction Scope Hibernate Level 1 Cache
Hibernate Level 1 Cache, also known as Session Cache, is built-in, meaning that session caches must be used whenever you use hibernate.Since the life cycle of a Session object usually corresponds to a database transaction or an application transaction, its cache is transaction-wide.In the first level cache, each instance of a persisted class has a unique primary key.
Scope Hibernate Level 2 Cache
Hibernate secondary cache is also known as the "SessionFactory Cache". Because the life cycle of the SessionFactory object corresponds to the entire process of the application, Hibernate secondary cache is a process-wide or cluster-wide cache, which can cause concurrency problems. Therefore, an appropriate concurrent access policy is required, which provides transaction isolation level for cached data..The second level cache is optional and a configurable plug-in that SessionFactory does not enable by default
N+1 problem
How spring annotations work internally
Aspect oriented program
Hibernate fetch types:
FetchType.LAZY = Doesn’t load the relationships unless explicitly “asked for” via getter
FetchType.EAGER = Loads ALL relationships
@Component
This is a generic annotation and can be applied to any class of the application to make it a spring managed component(simply, generic stereotype for any spring managed component). when the classpath is scanned by the spring’s component-scan (@ComponentScan) feature, it will identify the classes annotated with @Component annotation (within the given package) and create the beans of such classes and register them in the ApplicationContext. @Component is a class level annotation and its purpose it to make the class as spring managed component and auto detectable bean for classpath scanning feature.
if you want to know more about @Component and other stereo type annotations, it is recommended to look at this article.
@Bean
@Bean is used to explicitly declare and register a bean (as a configuration bean) in Spring IOC container that is returned from a method. @Bean is a method level annotation and it is used within a class that is annotated with @Configuration. Simply, @Bean annotation is used to register the bean returned by a method as a spring configuration bean in IOC Container. @Bean is only a method level annotation and it cannot be used with classes and object declaration.
@Bean annotation indicates that a method produces a bean that should be managed by the Spring container.
To declare a bean, simply annotate a method with the @Bean annotation. When JavaConfig encounters such a method, it will execute that method and register the return value as a bean within a ApplicationContext. By default, the bean name will be the same as the method name.The following is a simple example of a @Bean method declaration.
http://www.cleantutorials.com/jconsole
Multi threading:
https://hellokoding.com/java-completablefuture-runasync-vs-supplyasync/
public static void main(String argss[]) throws InterruptedException {
List<CompletableFuture<Integer>> futuresList = new ArrayList<CompletableFuture<Integer>>();
CompletableFuture<Integer> addAsy = CompletableFuture.supplyAsync(()->(addFun1(10,5)));
CompletableFuture<Integer> subAsy = CompletableFuture.supplyAsync(()->(subFun1(10,5)));
CompletableFuture<Integer> mulAsy = CompletableFuture.supplyAsync(()->(mulFun1(10,5)));
futuresList.add(addAsy);
futuresList.add(subAsy);
futuresList.add(mulAsy);
/*
* allOf --- waits till all the threads in the arguments get completed
* join --- collects all the return values from all the threads
* */
CompletableFuture<Void> allFutures = CompletableFuture
.allOf(futuresList.toArray(new CompletableFuture[futuresList.size()]));
CompletableFuture<List<Integer>> allCompletableFuture = allFutures.thenApply(future -> {
return futuresList.stream().map(completableFuture -> completableFuture.join())
.collect(Collectors.toList());
});
CompletableFuture<List<Integer>> completableFuture = allCompletableFuture.toCompletableFuture();
try {
List<Integer> finalList = (List<Integer>) completableFuture.get();
System.out.print(finalList);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
https://www.cubrid.org/blog/understanding-jdbc-internals-and-timeout-configuration
A CountDownLatch is useful when we need a mechanism to notify one or more threads that a set of operations performed by other threads has finished.
ExecutorCompletionService is useful when we need to access the task result as soon as possible and other approaches when we want to wait for all of the running tasks to finish.
http://eherrera.net/ocpj8-notes/09-java-file-io-(NIO.2)
https://www.baeldung.com/java-nio2-watchservice
https://www.geeksforgeeks.org/classloader-in-java/
https://medium.com/karuna-sehgal/a-simplified-explanation-of-the-big-o-notation-82523585e835
https://youtu.be/T3PsRW6wZSY
http://houseofbots.com/news-detail/3623-4-50-data-structure-algorithms-and-programming-languages-interview-questions-for-programmers
// file name: Main.java
class A {
static void fun() {
System.out.println("A.fun()");
}
}
class B extends A {
static void fun() {
System.out.println("B.fun()");
}
}
public class Main {
public static void main(String args[]) {
A a = new B();
a.fun(); // prints A.fun()
}
}
If we make both A.fun() and B.fun() as non-static then the above program would print “B.fun()”.
Even though both are part of JVM and both consumers memory allocated to the Java process, there are many differences between them e.g. Heap memory is shared by all threads of Java application but Stack memory is local to each thread. Objects are created in heap memory but method frames are stored in Stack memory, and size of heap space is much bigger than the small size of Stack in Java.
Association
Association refers to the relationship between multiple objects. It refers to how objects are related to each other and how they are using each other's functionality. Composition and aggregation are two types of association.
Composition
The composition is the strong type of association. An association is said to composition if an Object owns another object and another object cannot exist without the owner object. Consider the case of Human having a heart. Here Human object contains the heart and heart cannot exist without Human.
Aggregation
Aggregation is a weak association. An association is said to be aggregation if both Objects can exist independently. For example, a Team object and a Player object. The team contains multiple players but a player can exist without a team.
Example of Composition
//Car must have Engine
public class Car {
//engine is a mandatory part of the car
private final Engine engine;
public Car () {
engine = new Engine();
}
}
//Engine Object
class Engine {}
Example of Aggregation
//Team
public class Team {
//players can be 0 or more
private List players;
public Car () {
players = new ArrayList();
}
}
//Player Object
class Player {}
Collections:
headMap - Excludes the key passed
tailMap - Includes the key passed
Towers of Hanoi problem with recursion
Jquery callback function
Instantiate an array
STATIC KEYWORD:
No object needs to be created to use static variable or call static methods, just put the class name before the static variable or method to use them. Static method can not call non-static method.
static keyword always fixed the memory that means that will be located only once in the program where as final keyword always fixed the value that means it makes variable values constant.
Can we have static methods in abstract class?
Yes
Interfaces vs abstract class
Consider using abstract classes if any of these statements apply to your situation:
In java application, there are some related classes that need to share some lines of code then you can put these lines of code within abstract class and this abstract class should be extended by all these related classes.
You can define non-static or non-final field(s) in abstract class, so that via a method you can access and modify the state of Object to which they belong.
You can expect that the classes that extend an abstract class have many common methods or fields, or require access modifiers other than public (such as protected and private).
Consider using interfaces if any of these statements apply to your situation:
It is total abstraction, All methods declared within an interface must be implemented by the class(es) that implements this interface.
A class can implement more than one interface. It is called multiple inheritance.
You want to specify the behavior of a particular data type, but not concerned about who implements its behavior.
Indexes
Can we have constructor in interface - Yes
How to determine the type of a class - instanceof operator: The java instanceof operator is used to test whether the object is an instance of the specified type (class or subclass or interface). At run time, the result of the instanceof operator is true if the value of the Expression is not null.
class Parent{}
class Child1 extends Parent{}
class Child2 extends Parent{}
class Test
{
public static void main(String[] args)
{
Parent p =new Parent();
Child1 c1 = new Child1();
Child2 c2 = new Child2();
System.out.println(c1 instanceof Parent); //true
System.out.println(c2 instanceof Parent); //true
System.out.println(p instanceof Child1); //false
System.out.println(p instanceof Child2); //false
p = c1;
System.out.println(p instanceof Child1); //true
System.out.println(p instanceof Child2); //false
p = c2;
System.out.println(p instanceof Child1); //false
System.out.println(p instanceof Child2); //true
}
}
Choosing Between Primitives and Wrapper Classes : Primitives(int, boolean,etc) cannot have methods called on them, because they are not objects. Whereas wrapper classes(Integer, Boolean) turn these primitives into objects. Therefore, instances of wrapper classes can have methods called upon them.
(https://www.learnhowtoprogram.com/java/java-basics-44521e57-d3ce-4b3e-a597-61222d841568/primitives-and-wrapper-classes-261b7135-a428-4beb-8323-bb14a3f41be0)
Autoboxing : Converting a primitive value into corresponding wrapper class object( int to Integer)
Unboxing : Converting a wrapper class object into corresponding primitive value (Integer to int)
Generic classes
Integer i = new Integer(10);
// unboxing the Object
int i1 = i;
String vs string buffer
public class StringExample{
public static void main(String args[]){
String s1="java";
String s = s1;
System.out.println(s == s1);
}}
Output: true
In String class,
The Java Generics programming is introduced in J2SE 5 to deal with type-safe objects.
Before generics, we can store any type of objects in collection i.e. non-generic. Now generics, forces the java programmer to store specific type of objects.
Advantage of Java Generics
There are mainly 3 advantages of generics. They are as follows:
1) Type-safety : We can hold only a single type of objects in generics. It doesn’t allow to store other objects.
2) Type casting is not required: There is no need to typecast the object.
Before Generics, we need to type cast.
List list = new ArrayList();
list.add("hello");
String s = (String) list.get(0);//typecasting
After Generics, we don't need to typecast the object.
List<String> list = new ArrayList<String>();
list.add("hello");
String s = list.get(0);
3) Compile-Time Checking: It is checked at compile time so problem will not occur at runtime. The good programming strategy says it is far better to handle the problem at compile time than runtime.
List<String> list = new ArrayList<String>();
list.add("hello");
list.add(32);//Compile Time Error
Syntax to use generic collection
ClassOrInterface<Type>
Example to use Generics in java
ArrayList<String>
JAVA Programming :
static - we can use statis fields without invoking object
servlet lifecycle - init,service , destroy
jsp lifecycle
hibernate mappings one to many .. join tables
class A{
static int i;
A(){
i++;
}
public static void main(String args[]){
A a =new A();
A b =new A();
A c =new A();
System.out.println(i);
}
}
o/p:3
If static not used “i”, A.java:10: error: non-static variable i cannot be referenced from a static context
~~~~~~~~~~~~~~~~~~~~~~
Runtime Polymorphism or Dynamic method dispatch
Dynamic method dispatch is a mechanism by which a call to an overridden method is resolved at runtime. This is how java implements runtime polymorphism. When an overridden method is called by a reference, java determines which version of that method to execute based on the type of object it refer to. In simple words the type of object which it referred determines which version of overridden method will be called.
When Parent class reference variable refers to Child class object, it is known as Upcasting
class Game
{
public void type()
{
System.out.println("Indoor & outdoor"); }
}
Class Cricket extends Game
{
public void type()
{ System.out.println("outdoor game");
}
public static void main(String[] args)
{
Game gm = new Game();
Cricket ck = new Cricket();
gm.type();
ck.type();
gm=ck; //gm refers to Cricket object
gm.type(); //calls Cricket's version of type
}
}
Indoor & outdoor
Outdoor game
Outdoor game
Notice the last output. This is because of gm = ck; Now gm.type() will call Cricket version of type method. Because here gm refers to cricket object
~~~~~~~~~~~~
Q. Difference between Static binding and Dynamic binding in java ?
Static binding in Java occurs during compile time while dynamic binding occurs during runtime. Static binding uses type(Class) information for binding while dynamic binding uses instance of class(Object) to resolve calling of method at run-time. Overloaded methods are bonded using static binding while overridden methods are bonded using dynamic binding at runtime.
In simpler terms, Static binding means when the type of object which is invoking the method is determined at compile time by the compiler. While Dynamic binding means when the type of object which is invoking the method is determined at run time by the compiler.
~~~~~~~~~~~~~
if(null){
System.out.println("aaaaaa");
}else{
System.out.println("bbbbb");
}
//throws error
Cricket.java:28: error: incompatible types
if(null){
^
required: boolean
found: <null>
1 error
Keywords are words that are used as part of code structure, like for or while. They change the way a compiler handles a block of code, e.g. a for tells the compiler to execute the code within the specified scope repeatedly, until the given exit condition is reached. The class keyword tells the compiler to treat everything within the specified scope to be part of a particular class. Keyword names are restricted, so you can't use them as variable names.
Literals like true, false and null are values that can be assigned, but their names are restricted in the same way that keywords are, i.e. you can't have a variable called true or for. They form parts of expressions, but don't change the way a compiler handles code.
~~~~~~~~~~~
serialization and Externalization
Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object.
transient - used to exclude from serialization
Spring Architecture:
MVC JEE https://www.tuturself.com/posts/view?menuId=90&postId=481
JMS Spring configuration :
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms-3.0.xsd">
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
p:brokerURL="tcp://localhost:61616" />
<bean id="listener" class="com.javatpoint.MyMessageListener"></bean>
<jms:listener-container container-type="default" connection-factory="connectionFactory"
acknowledge="auto">
<jms:listener destination="myqueue" ref="listener" method="onMessage"></jms:listener>
</jms:listener-container>
DATABASE :
remove duplidate records - ccreate a temp table and insert all distinct records , then truncate old table, then add these temp table results to old table and drop temp table
~~~~~~~~~~~~~~~~~~~~~~
Self join and left outer join
~~~~~~~~~~~~~~~~~~~
UNION and UNION ALL
UNION - remove the duplicates
UNION ALL - Remains the duplicates
COALESCE() Function :
Return the first non-null expression in a list:
SELECT COALESCE(NULL, NULL, NULL, 'W3Schools.com', NULL, 'Example.com');
AWS:
EC2 : Elastic Cloud Computing : create amazon machine image , instances
Elastic Block Storage EBS : to store
SSS : Simple Storage Service : stores files,
Buckets
Triggers events when change in objects
Preserves older versions
Replicates across regions
HADOOP:https://parthgoelblog.wordpress.com/2016/12/31/how-to-install-hadoop-2-7-3-single-node-cluster-on-ubuntu-16-04/
Springs Slides:
DEPENDENCY INJECTION:
Types of Injection:
Construction Injection
Setter or Property Injection
Getter/Setter:
myCard bean name should be matched with the Property name , object for class in main class
1. Remove Duplicates Using Row_Number.
WITH CTE (Col1, Col2, Col3, DuplicateCount)
AS
(
SELECT Col1, Col2, Col3,
ROW_NUMBER() OVER(PARTITION BY Col1, Col2,
Col3 ORDER BY Col1) AS DuplicateCount
FROM MyTable
) SELECT * from CTE Where DuplicateCount = 1
2.Remove Duplicates using self Join
YourTable
emp_name emp_address sex matial_status
uuuu eee m s
iiii iii f s
uuuu eee m s
SELECT emp_name, emp_address, sex, marital_status
from YourTable a
WHERE NOT EXISTS (select 1
from YourTable b
where b.emp_name = a.emp_name and
b.emp_address = a.emp_address and
b.sex = a.sex and
b.create_date >= a.create_date)
3. Remove Duplicates using group By
SELECT FirstName, LastName, MobileNo, COUNT(*) as CNT
FROM CUSTOMER
GROUP BY FirstName, LastName, MobileNo;
HAVING COUNT(*) = 1
Virtusa:
Hashmap vs hashtable
Struts interceptor
Request dispatcher vs redirection
Concurrent hash table
Servlet inter communication
Post vs put
Hibernate mappings
How springs and Hibernate integrated
What is the default scope of a bean in springs
How to make an object immutable
String vs string buffer
Delete vs truncate in SQL
difference in SendRedirect() and RequestDispatcher() in Servlet
SendRedirect
This is the method of object HttpServlerResponse.
Request is redirected to client (Browser), and it will process the new URL.
End User can see on which page, url is redirected.
In Nutshell, Processing done at client side.
RequestDispatcher
This object can be accessed from HttpServletRequest.
Servlet will internally forward the request to another servlet or jsp page.
End user don’t know that which page is processed internally.
In Nutshell, Processing done at server side.
http://www.javasafari.com/servlet/inter-servlet-communication.php
RequestDispatcher interface provides two methods:
public void forward(ServletRequest req,ServletResponse res)throws ServletException,java.io.IOException:
Forwards a request from a servlet to another resource on the server.
public void include(ServletRequest req,ServletResponse res)throws ServletException,java.io.IOException:
Includes the content of a resource in the response.
N-gram generation:
public static List<String> ngrams(int n, String str) {
List<String> ngrams = new ArrayList<String>();
for (int i = 0; i < str.length() - n + 1; i++)
ngrams.add(str.substring(i, i + n));
return ngrams;
}
oauth2
spring mvc
spring data
spring transaction
config file
java (1.8)
spring ioc
spring rest
microservice
springboot cli
reactive pattern
microservice fundamentals
spring config
springboot s
circuit breaker
service discovery
health check
asynchronous
distributed tracing
api gateway
event driven
tls
Mphasis:
Internal data structure of hashmap
Hashmap vs linkedhashmap
Hashmap order
Visibility of spring bean Scopes
@component vs @bean
Comparator
Singleton design pattern
Coupling and cohesion : https://www.decodejava.com/coupling-cohesion-java.htm
Same method signatures with default methods in interface A and B .. can a class implemented both.. no.. if not default, yes.
Externalization in Java
Node JS:
promise-based programming and package q
package async-q
JSON file reading and parsing - look at package fs for file operations
request package for making http requests
regular expression handling in nodejs
package lodash for utility functions
finally, restify package for creating microservices
Lodash makes JavaScript easier by taking the hassle out of working with arrays,
numbers, objects, strings, etc. Lodash’s modular methods are great for:
Iterating arrays, objects, & strings
Manipulating & testing values
Creating composite functions
https://www.sitepoint.com/lodash-features-replace-es6/
== (Double equals operator): Known as the equality or abstract comparison operator
=== (Triple equals operator): Known as the identity or strict comparison operator
const re1 = new RegExp('password') ⇒ re1.test('password')
var server = restify.createServer();
// request('http://www.google.com', function (error, response, body) {
// if (!error && response.statusCode == 200) {
// console.log(body) // Print the google web page.
// }
// })
server.get('/hello/:name', respond);
//server.head('/hello/:name', respond);
server.listen(8080, function () {
console.log('%s listening at %s', server.name, server.url);
});
JSON.stringify() function converts an object to a JSON string.
JSON.parse() is a secure function to parse JSON strings and convert them to objects.