Tuesday, March 21, 2017

java: hide password input from command line and GUI component



A. If you are running the java program from a command line

java.io.Console console = System.console();

if (console != null) {
      char[] passwordChars = console.readPassword("Password: ");
      String password = new String(passwordChars);

}


B. Use JPasswordField if you are not running the program from a command line

String password = "";

final JPasswordField jpf = new JPasswordField(); 
int opt = JOptionPane.showConfirmDialog(null, jpf, "Password",                                                     JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); 
if (opt == JOptionPane.OK_OPTION) {
      password = new String( jpf.getPassword() );
}

---------------------------------------------------------------------------------------------------

                        


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 free here.

ORA-01733: virtual column not allowed here

This error often occurs when you are trying to update a view that holds values from underlying base tables.

For example, you have a table STUDENT

STUDENT
firstName      lastName      streetAddress       city              state        zip
------------      ------------     -----------------      -----------      ------       ----------
John              Smith            1 main st.             Ocean          FL           33271
Mary             Shaw             2 pine st.              York            MD         07681


For convenience, you created a view STUDENT_VIEW

STUENDT_VIEW
name                                         address
-----------------------                   ----------------------------------------------
John Smith                               1 main st., Ocean, FL 33271
Mary Shaw                               2 pine st., York, MD 07681

The SQL below will cause the virtual column not allowed here error.

SQL> update STUENDT_VIEW set address = '3 main st., Ocean, FL 33271' where name = 'John Smith';

ORA-01733: virtual column not allowed here

To update John Smith's address, you need to update the STUDENT table instead of the STUDENT_VIEW.

-----------------------------------------------------------------------------------------------------------------
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.

Friday, March 17, 2017

[Solved] java: How to insert a character into a String at a certain position?

Lets say you want to insert "." into "B500ST90"  to make it look like "B50.0ST.90".

You can achieve this in the following ways.

      String str = "B500ST90";

1. Substring concatenation
       
      String result = str.substring(0,3) + "." + str.substring(4,7) + "." + str.substring(8);

2. StringBuilder insert

       String result = new StringBuilder("B500ST90").insert(3, ".").insert(7. ".").toString();

---------------------------------------------------------------------------------------------------

                        


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 free here.

Wednesday, March 15, 2017

Split String to tokens: StringTokenizer, String split, and Scanner

The sample code below compares the output and time used for StringTokenizer, String split, and Scanner to break the same string to string segments using the same delimiter. The StringTokenizer is the fastest and does not generate empty tokens. Both String split and Scanner produce empty tokens. Among these two, the String split is faster. However, StringTokenizer can only use a String as the delimiter, String split and Scanner can take a regular expression pattern as the delimiter.

The String.split("<delimiter>") method ignores empty ending token. If you want the empty token to be included in the result, use String.split("<delimiter>", -1)

import java.util.Scanner;
import java.util.StringTokenizer;

public class StringToken {
    public static void main(String[] args) {
        String str = "00002 A000    1 Cholera due to Vibrio cholerae 01, biovar cholerae           Cholera due to Vibrio cholerae 01, biovar cholerae";
        System.out.println("----Tokenizer----");
        long time = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            System.out.println();
            StringTokenizer st = new StringTokenizer(str, " ");
            while(st.hasMoreTokens()){
                System.out.print(st.nextToken()+",");
            }
        }
        long tokenTime = System.currentTimeMillis()-time;
        System.out.println();
        System.out.println("----split----");
        time = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            System.out.println();
            String[] st = str.split(" ");
            for (String s : st) {
                System.out.print(s + ",");
            }
        }
        long splitTime = System.currentTimeMillis() - time;
        System.out.println();
        System.out.println("----Scanner----");
        time = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            System.out.println();
            Scanner sc = new Scanner(str).useDelimiter(" ");
            while (sc.hasNext()) {
                System.out.print(sc.next() + ",");
            }
        }
        long scanTime = System.currentTimeMillis() - time;
        System.out.println();
        System.out.println("StringTokenizer: "+tokenTime);
        System.out.println("Split: "+splitTime);
        System.out.println("Scanner: " + scanTime);
    }
}

Output:
----Tokenizer----
00002,A000,1,Cholera,due,to,Vibrio,cholerae,01,,biovar,cholerae,Cholera,due,to,Vibrio,cholerae,01,,biovar,cholerae,
. . . . . .

----split----
00002,A000,,,,1,Cholera,due,to,Vibrio,cholerae,01,,biovar,cholerae,,,,,,,,,,,Cholera,due,to,Vibrio,cholerae,01,,biovar,cholerae,
. . . . . .

----Scanner----
00002,A000,,,,1,Cholera,due,to,Vibrio,cholerae,01,,biovar,cholerae,,,,,,,,,,,Cholera,due,to,Vibrio,cholerae,01,,biovar,cholerae,
. . . . . .

StringTokenizer: 27
Split: 38
Scanner: 84

---------------------------------------------------------------------------------------------------

                        


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 free here.

Thursday, March 9, 2017

[Solved] NetBeans: How to view all the running processes?

There are at least two ways to see which processes are currently running in your NetBeans.

A. Through the menu

  1. Click the Window in the top menu
  2. Selelct IDE Tools
  3. Select Processes


B. Through the Task Running bar

Click the bar with the word "running" on it at the bottom right of the NetBean screen and all the processes currently running will be displayed.

---------------------------------------------------------------------------------------------------

                        


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 free here.


[Solved] NetBeans: How to get back / recover / restore the Output window, Editor window, Projects window, or the Navigator window?

A. Window closed by accident

If you closed any of the NetBean windows by accident, you can always click on the Window menu in the top menu, and select the window you want to recover or display. If you don't see the window you want to display, check the submenus under the Window menu.


B. Window minimized by clicking the minimize button of the window

Look at the side and bottom edge of the NetBean screen to locate the minimized window, click on it to restore it.

If you feel the windows are really messed up, you can click on the word Window in the top menu and select Reset Windows before you perform the A or B listed above. This will reset the windows to their default layout.

---------------------------------------------------------------------------------------------------

                        


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 free here.