A method to mock a new instance in the class is using the powermockito. Powermockito has a function whenNew. This one can be used to solve this kind of problem.

Following are the characters of the OOP:
1. Encapsulation: capturing and keeping data safely and securely from outside interfaces.
2. Inheritance: class can be derived from a base class, and contains all the feature of the base class but it still has some of its own features.
3. Polymorphism: The ability of objects of different types to respond to functions of the same name.
4. Abstraction: representing the data at a very conceptual level without any details.

Make use of a time-based scheduler Cron, which is available on Debian (as well as on other Unix-like operating systems). Quartz offers a seamless integration with Java applications. Scheduling a particular script (e.g. restarting server) can be easily done using Cron expressions in form of a string consisting of five or six fields (separated by white space), which are respectively responsible for: minutes, hours, day of month, month, day of week, year.

1) Implement a procedure to restart server (e.g. integrated in Java application or through system script).
2) Make use of Quartz to provide Cron functionality to Java application, in particular to make use of Cron expressions.
3) Provide an option for (privileged/administrator) users to manage Cron expression string for restarting server in web interface.
4) Explain in a short summary the principle of functioning of Cron expressions, providing examples of the most common usages.

Update environment variable

Indeed the environment variable on windows does not get updated automatically. So you have to adjust the variable, for a windows computer with german language settings, in: System -> Erweiterte Systemeinstellungen -> Umgebungsvariablen...
Now you only have to update the "JAVA_HOME" variable with the concrete path and/or version number.


Adding components to the Apache Camel main class

The main issue is that Camels main class does not handle its context appropriately. Although its method .getOrCreateCamelContext() returns a context and allows you to add the desired component, the context may not be as unique as one thinks when reading the corresponding description. Furthermore, when it comes to the execution of the code (, a post-processing method tends to override the created context with an empty one. To still be able to work with Camel and pure Java DSL, you can create a new main class as an extension of Camels main. Within this new class you start introducing your own instance of CamelContext and handle it in an uniquely manner. To do so the methods .getOrCreateCamelContext() and .postProcessContext() have to be overridden as shown within the provided code snippet.

Add Hystrix

Hystrix ( is a fault tolerance library developed by Netflix, which uses the circuit breaker pattern to increase the fault tolerance of your Java code. It works by wrapping your code in so called Commands and providing Fallback Methods.

It is integrated in spring cloud, with the spring-cloud-starter-hystrix maven artifact.

The spring integration allows you to declare your service methods as Hystrix commands with annotations, for example:

@HystrixCommand(fallbackMethod = "fallback", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = TIMEOUT)
public Object callService() {
//insert code to send a request to one of your microservices, which could fail, here

private Object fallback(){
//insert code to execute if service fails or takes too long to answer here

With above code snippet you can declare a time out for your method, after which the fallback method will be executed. Furthermore the fallback method is executed should an exception occur or if the method failed too often consecutively (circuit breaker pattern). This allows for fail fast semantics and the failing/overwhelmed microservice you are trying to call is given time to recover.

Using RunOnUiThread to see user interface changes in Xamarin

If you are in your own thread and the code looks similar to this:

//1. Code before your UI action

//2. Code that changes UI

//3. Code after your UI action

Than you need to do the following.

First you need to get the current instance of you main activity that you are in, this can be achieved like this:
In your MainActivity.cs you need to change the App loading to
// LoadApplication(new App(this));

In your "App" class you than write:
// public App(Object o)
// currentMainActivity = (Android.App.Activity)o;

After that you have everywhere in your code access to the current java main activity.
To do some UI actions in your threads, just use the following code:

//1. Code before your UI action

App.currentMainActivity.RunOnUiThread(() =>
// 2. Code that changes UI

//3. Code after your UI action


Preventing multiply output lines in Xamarin for Visual Studio on Android developement

I have used an very easy solution for this problem.
Whenever I need to do some output to the console (hint: you should only do this for you own purpose, later on you should Logging with respective logging levels in you app!) I do it the following way:

In the "App" class i have created a new method called "WriteLine" and there I use a dependency service call to execute some native java code on the android device:

public static void WriteLine(String line)

If you need help for using the DependencyService please look into further tutorials on that!
In the Implementation of the interface IOutput you just need the following code:

public void WriteLine(string line)

Like this you use the java "Console" class and you get the output at least one time less.


Use Locale in Android Application

I assume that your images are stored in the folder res-drawable. In Android Studio, location-specific behavior can be achieved by right-clicking on res and creating a new Android resource directory. In the following pop-up window, different qualifiers can be set, e.g. the Locale that allows will read out the language that is set on the mobile phone of the user and automatically uses the image from the corresponding directory (see the attached picture for details). You will notice that Android Studio creates the new directory with a specific suffix, e.g. "drawable-de" for german images. The general "drawable" folder will be used in case that the Locale of the user does not match any of your specified qualifiers and can therefore be seen as a default case.


Correctly change version code and name of Android Application

When you create your project with Android Studio, most of the files and settings are automatically created for you. You may therefore have missed that there is another file containing a versionCode and versionName, additional to the Manifest file. In your project directory, you will find a gradle file "app.gradle" that contains all the dependencies of your application. Further, in the defaultConfig section, you will see that there is a versionCode and a versionName that is probably identical to the code and name of your previous uploaded .apk file. Change these parameters and you are good to go for rolling out your file! The Play Store automatically notifies all the users of the old version about the changes and updates your product.



Subscribe to java