How JVM Works – JVM Architecture?
variables scope
- In general, a set of curly brackets { } defines a scope.
- In Java we can usually access a variable as long as it was defined within the same set of brackets as the code we are writing or within any curly brackets inside of the curly brackets where the variable was defined.
- Any variable defined in a class outside of any method can be used by all member methods.
- When a method has the same local variable as a member, this keyword can be used to reference the current class variable.
- For a variable to be read after the termination of a loop, It must be declared before the body of the loop.
Currying Functions in Java
Binary Search in Java
Different ways to create objects in Java
1) Using new Keyword :
2) Using New Instance :If we know the name of the class & if it has a public default constructor we can create an object –Class.forName. We can use it to create the Object of a Class. Class.forName actually loads the Class in Java but doesn’t create any Object. To Create an Object of the Class you have to use the new Instance Method of the Class.
5)Using newInstance() method of Constructor class :There is one newInstance() method in the java.lang.reflect.Constructor class which we can use to create objects.
// Java program to illustrate creation of Object
// using newInstance() method of Constructor class
import java.lang.reflect.*;
public class ReflectionExample
{
private String name;
ReflectionExample()
{
}
public void setName(String name)
{
this.name = name;
}
public static void main(String[] args)
{
try
{
Constructor<ReflectionExample> constructor
= ReflectionExample.class.getDeclaredConstructor();
ReflectionExample r = constructor.newInstance();
r.setName("Hey");
System.out.println(r.name);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
// Java program to illustrate creation of Object
// using newInstance() method of Constructor class
import java.lang.reflect.*;
public class ReflectionExample
{
private String name;
ReflectionExample()
{
}
public void setName(String name)
{
this.name = name;
}
public static void main(String[] args)
{
try
{
Constructor<ReflectionExample> constructor
= ReflectionExample.class.getDeclaredConstructor();
ReflectionExample r = constructor.newInstance();
r.setName("Hey");
System.out.println(r.name);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Threads:
Java Multi threading interview questions-
https://javacmlearning.blogspot.com/2019/10/java-multi-threading-interview-questions.html
what are distributed transactions in microservices?
suppose one microservice has updated db1 and another microservice has db2 and fail and microservice3 has to use combined results of 1 and 2 . so how you have to maintain ACID property here.
the answer is either avoid distributed transection at all.
or
use
2phase commit protocol
saga pattern
event based transections
suppose we have deployed our service using http protocol just wanted to convert this to https call what changes required in server?
First, make sure that you have configured and enabled both the HTTP and HTTPS
<Connector>
elements in your conf/server.xml
file:
For details on how to prepare your conf/keystore file, see http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html.
Restart Tomcat and test both of these connectors, making sure that you can access your web application via either connector before you proceed. Next, edit your web app's
WEB-INF/web.xml
file and add the following inside of your <web-app>
container element:
No comments:
Post a Comment
Note: only a member of this blog may post a comment.