Wednesday, August 21, 2019

Microsoft Office Word 2016: Remove frame from a paragraph

You have a document looks like the one below, and you want to remove the frame from the paragraph,


1. Click anywhere in the frame, then click at the Design in the top menu.



2. select Page Borders from the toolbar.



3. Select the Borders tab in the popped-up Borders and Shading window. Then click on the None icon to select it and choose Paragraph in the Appy to drop-down list. finally, click the OK button.


-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Thursday, August 15, 2019

Java 8: default methods, static methods, and their differences

Before Java 8, an interface can only have abstract methods. Starting Java 8, you can add default and static methods with executable method bodies. This change allows you to add new methods to an interface without affecting any of the many classes that have already implemented the interface.

Default Method

For example, you have a TestFace interface that are implemented by SportCenter1 and SportCenter2.

public interface TestFace {
      public boolean ableToRun(Person p);
}


public class SportCenter1 implement TestFace {
      private List<Person> memberList = <your member list>;

      public boolean ableToRun(Person p) {
            if (p.getForwardMoveSpeed() > 10) {
                  return true;
            }
            return false;
      }

      public List<Person> getRunnableMembers() {
            public List<Person> runnableMembers = memberList.stream()
                          .filter(p -> ableToRun(p))
                          .sort(Comparator.comparing(Person::getName))
                          .collect(Collectors.toList());

            return runnableMembers;
      }
}


public class SportCenter2 implement TestFace {
      private List<Member> memberList = <your member list>;

      public boolean ableToRun(Member p) {
            if (p.getMaxMoveDistance() > 5) {
                  return true;
            }
            return false;
      }

      public List<Member> getRunnableMembers() {
            public List<Member> runnableMembers = memberList.stream()
                          .filter(p -> ableToRun(p))
                          .sort(Comparator.comparingInt(Person::getAge))
                          .collect(Collectors.toList());

             return runnableMembers;
      }
}

Now, you have a new customer, SportCenter3, who wants to know if their members are able to swim. If you add an abstract method, ableToSwim, to the TestFace interface, you have to modify the code of SportCenter1 and SportCenter2 to make them compatible to the changed interface. Here, the default method came in handy. It provides you the backward compatibility to old code. Your modified interface can look like below, and it will not affect the SportCenter1 and SportCenter2 at all. It is especially convenient if there are a large number of classes using the interface.


public interface TestFace {
      public boolean ableToRun(Person p);

      public default boolean ableToSwim(Person p) {
            return true;
      }
}


public class SportCenter3 implement TestFace {
      private List<Person> memberList = <your member list>;

      public boolean ableToRun(Person p) {
            if (p.ableToRun() && p.ableToClimeMountain()) {
                  return true;
            }
            return false;
      }

     //optional to override the default method in the interface
      public boolean ableToSwim(Person p) {
            if (p.passedSwimmingTest()) {
                  retrun true;
            }
            return false;
      }
}

If your class implementing multiple interfaces and more than one interface have the same default method signature, your implementing class should explicitly specify which default method it is using or override this default method.

Static Method

A static method is another way to add a method to an interface without affecting its implementing children.

public interface TestFace {
      public boolean ableToRun(Person p);

      public default boolean ableToSwim(Person p) {
            return true;
      }

      public static void incrementAge(Person p) {
            p.setAge(p.getAge() + 1);
      }
}

Difference between Default Method and Static Method

1. While a default method can be override by implementing classes, static method cannot be overridden.

2. Static methods belong only to the interface and can only be called from the interface class, while default methods can be invoked from instances of both the interface and implementing classes.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

References:
1. Difference Between static and default methods in interface
2. Default Methods In Java 8
3. Java 8 Interface Changes – default method and static method

Wednesday, August 14, 2019

Java 8: Method Reference

Method Reference is a shorthand notation of Lambda Expression.

For example, you want to add an ActionListener to a JButton actButton.

Before Java 8:

actButton.addActionListener(new ActionListener () {
      public void actionPerformed(ActionEvent e) {
            searchButton.requestFocusInWindow();
      }
});


Use Lambda Expression:

actButton.addActionListener((ActionEvent e) -> {
      searchButton.requestFocusInWindow();
});


Use Method Reference:

actButton.addActionListener(searchButton::requestFocusInWindow());

If the method you are referencing is a member of the current class, it is also known as Memeber Reference.

For example, you are working in a class that is a subclass of the JFrame. After you have done some modification of the GUI, you want to call the pack() method.

javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
            this.pack();
      }
}


Use Memeber Reference:

javax.swing.SwingUtilities.invokeLater(this::pack());

The method called in Method Reference can be ordinary instance member of a class as shown in our above examples, a static method of a class, or even a constructor of a class, as long as the signature of the method exactly matches the method in the functional interface.

To reference a static method:

javax.swing.SwingUtilities.invokeLater(ResultCalss::print());

It requires the signature of the method print() matches the signature of the run() method in the Runnable interface.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Reference:
Method References in Java 8


Friday, August 9, 2019

NetBeans: Migrate from an early JDK to Java 8 or a later version

After you have updated the Java platform from an earlier version to Java 8 or a later version, you want to convert the old java code to one with the new features of the newly added Java version.

Of course, you can check your code line by line to convert it manually. However, you can use the NetBeans built-in feature to perform this, which will save you a lot of time and effort.

1. Click the Refactor in the top menu of the NetBeans IDE, and choose Inspect and Transform/



2. In the Inspect and Transform window, select a project you want to refactor from the drop-down list next to the Inspect label.



3. While the Configuration is checked, select the target JDK you will convert to from the drop-down list next to the Configuration label. Then, click the Inspect button.



4. If the below window pops up, click the Inspect button again to continue.



5. In the Refactoring window, click the upward arrow with the notation "Previous Occurrence" on the left column of the window to view the suggestions of code changes.



6. Use the upward and downward arrows on the left column to view all the changes. If all look OK, click the Do Refactoring button.


-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.