How to make out.println() method working in a simple java file without using System Class reference? - import

public class ABC{ public static void main(String[] args) { out.println("Hello"); } }

This works, though static imports are not generally considered a good thing in java.
import static java.lang.System.out;
public class ABC {
public static void main(String[] args) {
out.println("hello");
}
}

Related

How to add a hook to the Vertx Launcher

I would like to collect metrics with Vert.x Micrometer Metrics, so I need to set proper options to VertxOptions. I run Vertx with Launcher and there is a hook beforeDeployingVerticle but when I override it it's not called.
I overriden Launcher class and beforeDeployingVerticle method but this method is never executed.
public class LauncherTest {
public static class SimpleVerticle extends AbstractVerticle {
#Override
public void start(Future<Void> startFuture) throws Exception {
System.out.println("verticle started");
}
}
public static class LauncherWithHook extends Launcher {
#Override
public void beforeDeployingVerticle(DeploymentOptions deploymentOptions) {
System.out.println("before deploying");
}
}
public static void main(String[] args) {
new LauncherWithHook().execute("run", SimpleVerticle.class.getName());
}
}
In a result I receive just verticle started, but I expect also to have before deploying there. Should I add this hook somehow different?
change your main method like this:
public static void main(String[] args) {
String[] argz = {"run", "your.namepace.LauncherTest$SimpleVerticle"};
LauncherWithHook launcher = new LauncherWithHook();
launcher.dispatch(argz);
}

Interface in java

interface A {
public void eg1();
}
interface B {
public void eg1();
}
public class SomeOtherClassName implements A, B {
#Override
public void eg1() {
System.out.println("test.eg1()");
}
}
What is the output and what occurs if method is overriden in interface?
First of all it's of no use to implement both class A and B as both
of them has same method signature i.e both has same method name and
return type.
Secondly you'll need a main method to run the program.
Also in interface you can only declare the methods, the implementation
has to be done in the class which implements it.
interface A {
public void eg1();
}
interface B {
public void eg1();
}
public class Test implements A{
#Override
public void eg1() {
System.out.println("test.eg1()");
}
public static void main (String args[]) {
A a = new test();
a.eg1();
}
}
Output : test.eg1()

Automaticle replicate microservices with Spring Cloud Netflix

I have multiple Spring Cloud microservices. I want the automatic replication of microservices to be done when microservice cannot manage to do its work.
I tried to find any solutions but I found only this: here. This solution cannot be applied to my problem as it describes only the case when we have a certain number of microservices.
I will be very grateful if you give me some examples to help me with this problem.
UPDATE: I've several microservices
Eureka:
#SpringBootApplication
#EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args){
SpringApplication.run(EurekaApplication.class, args);
}
}
GatewayApplication:
#EnableZuulProxy
#EnableEurekaClient
#SpringBootApplication
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
FirstSybsystemApplication:
#SpringBootApplication
#EnableEurekaClient
#EnableFeignClients
public class FirstSubsystemApplication implements CommandLineRunner{
public static void main(String[] args) {
SpringApplication.run(FirstSubsystemApplication.class);
}
#Override
public void run(String... args) throws Exception {
}
}
I want to make a high load on FirstSubsystemApplication and to launch its copy automatically.

How to create an instance of A class that extends Application

I just designed a simple javaFx app. While running it solo works, but when I try to separated and create an instance of it all I get :
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
my code
import javafx.application.Application;
import javafx.stage.Stage;
public class Demo
{
public static void main(String[] args)
{
Demos dm = new Demos();
}
}
class Demos extends Application {
private String args;
private Stage stage;
public Demos()
{
main(args);
start(stage);
}
public void main(String args)
{
this.args=args;
launch(this.args);
}
#Override
public void start(Stage stage)
{
this.stage=stage;
this.stage.setTitle("Simple JavaFX Application");
this.stage.setResizable(false);
this.stage.show();
}
}
Application.launch requires the Application class to be lauched to be public. This is not the case for your Demos class.
Additional Notes
private String args;
private Stage stage;
public Demos()
{
main(args);
...
}
public void main(String args)
{
this.args=args;
...
}
Just assigns the initial value of args to itself, which will always result in args remaining null.
Application.launch is a static method creating the Application instance itself. Calling this form from a instance makes little sense.
If you want to launch a specific Application, pass the Application class to Application.launch:
public static void main(String[] args) {
Application.launch(Demos.class);
}
public Demos extends Application {
private Stage stage;
public Demos(){
}
#Override
public void start(Stage stage) {
this.stage=stage;
this.stage.setTitle("Simple JavaFX Application");
this.stage.setResizable(false);
this.stage.show();
}
}

Method overloading- cant find symbol

public class Overloading {
static void printing() {
System.out.println("Something being printed here");
}
static void printing(String name) {
System.out.println("hello"+name);
}
public static void main(String[] args) {
printing();
printing(rizwana);
}
}
I am trying something to check method overloading. But here is the error I got.
error: cannot find symbol
printing(rizwana);
symbol: variable rizwana
location: class Overloading
rizwana refers to a variable which you have not made in your code. If you want to pass a string, you should pass it as "rizwana".
Call the method as: printing("rizwana");
printing(String name) method will accept a string argument. So you should use printing("rizwana") instead of printing(rizwana). You could this
class Overloading {
static void printing() {
System.out.println("Something being printed here");
}
static void printing(String name) {
System.out.println("hello "+name);
}
public static void main(String[] args) {
printing();
printing("rizwana");
}
}