How to set look and feel on Java Swing applications


Use the method setLookAndFeel like the following to change Java Swing applications’ appearance

try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
} catch (Exception ex) {
//Just print stacktrace here since it's an example.
ex.printStackTrace();
}

And if you get an exception like the following one while trying to integrate SyntheticaStandardLookAndFeel for your application;

java.text.ParseException: Error parsing: org.xml.sax.SAXException: bind: unknown type REGİON null
    at javax.swing.plaf.synth.SynthParser.parse(SynthParser.java:230)
    at javax.swing.plaf.synth.SynthLookAndFeel.load(SynthLookAndFeel.java:589)
    at de.javasoft.plaf.synthetica.SyntheticaLookAndFeel.loadXMLConfig(SyntheticaLookAndFeel.java:401)
    at de.javasoft.plaf.synthetica.SyntheticaLookAndFeel.<init>(SyntheticaLookAndFeel.java:339)
    at de.javasoft.plaf.synthetica.SyntheticaStandardLookAndFeel.<init>(SyntheticaStandardLookAndFeel.java:30)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at javax.swing.UIManager.setLookAndFeel(UIManager.java:558)
    at examples.WelcomeForm.main(WelcomeForm.java:246)

You should change your current locale to English before setting Look and Feel like the code below;

Locale.setDefault(Locale.ENGLISH);
try {
UIManager.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaStandardLookAndFeel");
} catch (Exception ex) {
//Just print stacktrace here since it's an example.
ex.printStackTrace();
}

example Look and Feel class names;

javax.swing.plaf.metal.MetalLookAndFeel
com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
com.sun.java.swing.plaf.motif.MotifLookAndFeel
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel

How to use EXTRACT(XML) function in ORACLE DB


Friends the following udemy course created by me;

      Click here to attend Spring Framework 4.x and certification course with a discount

Spring Framework and Core Spring Certification Udemy course with discount
Spring Framework and Core Spring Certification Udemy course with a discount coupon

Extract(XML) function is used to get a node or nodes inside a XML document stored in Oracle DB. The syntax for EXTRACT function is;

EXTRACT(XML-Document-Column, ‘XPath expression‘)

EXTRACT(XML-Document-Column, ‘XPath expression’, ‘namespace’)

Example usages;

CREATE TABLE LIBRARY
(
ID_COLUMN NUMBER PRIMARY KEY,
XML_DATA_COLUMN XMLType
);

INSERT INTO LIBRARY(ID_COLUMN ,XML_DATA_COLUMN) VALUES
( 1
, XMLType(‘<?xml version=”1.0″ encoding=”UTF-8″?>
<LIBRARY>
    <BOOKS>
        <BOOK isbn=”ABCD7327923″>
            <NAME>Java Programing</NAME>
            <SUBJECT>Java J2EE</SUBJECT>
            <AUTHORS>
                <AUTHOR>Tuna TORE</AUTHOR>
                <AUTHOR>Linus Torvalds</AUTHOR>
                <AUTHOR>James Gosling</AUTHOR>
            </AUTHORS>
        </BOOK>
        <BOOK isbn=”DFGH09093232″>
            <NAME>XPATH for Dummies</NAME>
            <SUBJECT>XPATH development</SUBJECT>
            <AUTHORS>
                <AUTHOR>Linus Torvalds</AUTHOR>
                <AUTHOR>John Hawking</AUTHOR>
            </AUTHORS>
        </BOOK>
        <BOOK isbn=”DSKL2393A”>
            <NAME>J2EE Patterns</NAME>
            <SUBJECT>Design Patterns</SUBJECT>
            <AUTHORS>
                <AUTHOR>Aka Tuna</AUTHOR>
            </AUTHORS>
        </BOOK>
    </BOOKS>
    <DVDS>
        <DVD id=”123456″>
            <NAME>Music DVD</NAME>
            <CONTENT>Music</CONTENT>
            <AUTHORS>
                <AUTHOR>James Gosling</AUTHOR>
                <AUTHOR>Bill Gates</AUTHOR>
            </AUTHORS>
        </DVD>
        <DVD id=”3213324″>
            <NAME>Natural Science</NAME>
            <CONTENT>Science</CONTENT>
            <AUTHORS>
                <AUTHOR>John Green</AUTHOR>
                <AUTHOR>Bill Gates</AUTHOR>
            </AUTHORS>
        </DVD>
        <DVD id=”4353534″>
            <NAME>Rally</NAME>
            <CONTENT>Race</CONTENT>
            <AUTHORS>
                <AUTHOR>Tuna</AUTHOR>
            </AUTHORS>
        </DVD>
    </DVDS>
</LIBRARY>
‘));

–you can get all DVDs in the library with the following query
SELECT ID_COLUMN, EXTRACT(XML_DATA_COLUMN, ‘/LIBRARY/DVDS/DVD‘)
FROM LIBRARY

–result will be

<DVD id=”123456″>
    <NAME>Music DVD</NAME>
    <CONTENT>Music</CONTENT>
    <AUTHORS>
        <AUTHOR>James Gosling</AUTHOR>
        <AUTHOR>Bill Gates</AUTHOR>
    </AUTHORS>
</DVD>
<DVD id=”3213324″>
    <NAME>Natural Science</NAME>
    <CONTENT>Science</CONTENT>
    <AUTHORS>
        <AUTHOR>John Green</AUTHOR>
        <AUTHOR>Bill Gates</AUTHOR>
    </AUTHORS>
</DVD>
<DVD id=”4353534″>
    <NAME>Rally</NAME>
    <CONTENT>Race</CONTENT>
    <AUTHORS>
        <AUTHOR>Tuna</AUTHOR>
    </AUTHORS>
</DVD>

–or you can get a specific DVD with the following query DVD having id –> 4353534
SELECT ID_COLUMN, EXTRACT(XML_DATA_COLUMN, ‘/LIBRARY/DVDS/DVD[@id=4353534]‘)
FROM LIBRARY

— the result is
<DVD id=”4353534″>
    <NAME>Rally</NAME>
    <CONTENT>Race</CONTENT>
    <AUTHORS>
        <AUTHOR>Tuna</AUTHOR>
    </AUTHORS>
</DVD>

You can also use the EXTRACTVALUE function for getting only the value inside XML tags
If you want to get value (name) for the DVD having id number –> 3213324

SELECT ID_COLUMN, EXTRACTVALUE(XML_DATA_COLUMN, ‘/LIBRARY/DVDS/DVD[@id=3213324]/NAME‘)
FROM LIBRARY

— the result is
Natural Science

And if you want to get XML tags for the above operation use EXTRACT instead of using EXTRACTVALUE

SELECT ID_COLUMN, EXTRACT(XML_DATA_COLUMN, ‘/LIBRARY/DVDS/DVD[@id=3213324]/NAME‘)
FROM LIBRARY

— the result is
<NAME>Natural Science</NAME>

You can also use EXTRACTVALUE in the WHERE clause of a SQL
like the following query

SELECT EXTRACT(XML_DATA_COLUMN, ‘/LIBRARY/DVDS/DVD[@id=3213324]‘) FROM LIBRARY
WHERE EXTRACTVALUE(XML_DATA_COLUMN, ‘/LIBRARY/DVDS/DVD[@id=3213324]/NAME‘) = ‘Natural Science’;

— the result is
<DVD id=”3213324″>
    <NAME>Natural Science</NAME>
    <CONTENT>Science</CONTENT>
    <AUTHORS>
        <AUTHOR>John Green</AUTHOR>
        <AUTHOR>Bill Gates</AUTHOR>
    </AUTHORS>
</DVD>


How to configure Oracle Express Edition 10g’s port number, password and start options during boot on Linux OS


If you want to change the port number for Oracle Express Edition DB on Linux OS apply
the following command

[root@localhost ~]# sudo /etc/init.d/oracle-xe configure

Oracle Database 10g Express Edition Configuration
————————————————-
This will configure on-boot properties of Oracle Database 10g Express
Edition. The following questions will determine whether the database should
be starting upon system boot, the ports it will use, and the passwords that
will be used for database accounts. Press <Enter> to accept the defaults.
Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]:8080

Specify a port that will be used for the database listener [1521]:1521

Specify a password to be used for database accounts. Note that the same
password will be used for SYS and SYSTEM. Oracle recommends the use of
different passwords for each database account. This can be done after
initial configuration:
Confirm the password:

Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]:N

Starting Oracle Net Listener…Done
Configuring Database…Done
Starting Oracle Database 10g Express Edition Instance…Done
Installation Completed Successfully.
To access the Database Home Page go to “http://127.0.0.1:8080/apex&#8221;

How to edit grub.conf file using vi editor on Linux


Sometimes you need to edit grub.conf file for changing the behaviour of Linux systems start up

To change that file, you should apply the following commands for editing grup.conf file

1. Open a terminal

2. apply the following commands

[tuna@localhost ~]$ su –

Password: type password

[root@localhost ~]# vi /boot/grub/grub.conf

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE: You have a /boot partition. This means that

# all kernel and initrd paths are relative to /boot/, eg.

# root (hd0,1)

# kernel /vmlinuz-version ro root=/dev/sda5

# initrd /initrd-version.img

#boot=/dev/sda

default=1

timeout=5

splashimage=(hd0,1)/grub/splash.xpm.gz

hiddenmenu

title Fedora (2.6.27.5-117.fc10.i686)

root (hd0,1)

kernel /vmlinuz-2.6.27.5-117.fc10.i686 ro root=UUID=4e7e082f-78cf-42e2-8842-3dbb4146245d rhgb quiet

initrd /initrd-2.6.27.5-117.fc10.i686.img

title Other

rootnoverify (hd0,0)

chainloader +1

~

~

~

~

~

~

~

~

~

~

“/boot/grub/grub.conf” 20L, 684C

press i here for inserting (INSERT Mode) (changing the grub.conf file)

default attribute of this file should be modified for selecting the default Operating System. In this situation default:1 will start Vista OS first and if I change it to default=0 then Linux(Fedora) operating system will be started first. I can also change the timeout attribute and this will change waiting period in seconds for the boot menu when the computer starts.

After changing grub.conf you should press ESC (Command Mode) first and press : (colon) after

and w(rite) and q(uit) if you need modification

like :wq or just :q if you need no modification on the file

How to remove Ubuntu MBR entry on Vista OS


Click on Start

Click Run> write cmd

Write BCDEDIT on console

And use the following command for removing Ubuntu MBR Entry

BCDEDIT /DELETE identifier /F

after doing that you will see operation is successful on console.

identifier:           {09b0078a-93b2-11e0-8500-0021866bc194}
device                  unknown
path                    \ubuntu\winboot\wubildr.mbr
description             Ubuntu

C:\Users\Hp>BCDEDIT /DELETE {09b0078a-93b2-11e0-8500-0021866bc194} /F

And restart your system

 

How to display content of a file using head and tail commands Linux


Here is the solution if you want to display the first 20 lines of a file inside a Linux OS. use the following command

syntax –> head-linestobeshowed filename

linuxserver:/servers/apache-tomcat-6.0.18/conf # head -20 web.xml
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<!–
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the “License”); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
–>
<web-app xmlns=”http://java.sun.com/xml/ns/javaee&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#8221;

And, if you want to display the last 20 lines of a file inside a Linux OS.

syntax –> tail -linestobeshowed filename

linuxserver:/servers/apache-tomcat-6.0.18/conf # tail -20 web.xml

<!– ==================== Default Welcome File List ===================== –>
<!– When a request URI refers to a directory, the default servlet looks  –>
<!– for a “welcome file” within that directory and, if present,          –>
<!– to the corresponding resource URI for display.  If no welcome file   –>
<!– is present, the default servlet either serves a directory listing,   –>
<!– or returns a 404 status, depending on how it is configured.          –>
<!–                                                                      –>
<!– If you define welcome files in your own application’s web.xml        –>
<!– deployment descriptor, that list *replaces* the list configured      –>
<!– here, so be sure that you include any of the default values that     –>
<!– you wish to include.                                                 –>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>