Thursday, January 31, 2013

SOSS

http://sossprojects.herokuapp.com/


https://github.com/soss

Config Log

INSTALL XQuery Develop Tool
http://stackoverflow.com/questions/7117603/can-not-install-xqdt-in-eclipse
The latest version of XQDT requires the dynamic languages toolkit [3.0.0, 4.0.0). In other words, the DLTK version must be >= 3.0.0 and < 4.0.0. If you're using Eclipse Juno, you'll need to download the DLTK from the Indigo update site (http://download.eclipse.org/releases/indigo), not the Juno update site. The XQDT plug-in doesn't like the fact that the version number of the DLTK from the Juno update site is > 4.0.0.

note

1. He wasn't the man he said he was.
2. He admitted to me that ...
3. He wish he had more time to right his wrong.

Wednesday, January 30, 2013

2012

HOWTO: Setup the Java JDK, Eclipse, Android SDK and Android ADT for Android Development (Windows 7)


HOWTO: Setup the Java JDK, Eclipse, Android SDK and Android ADT for Android Development (Windows 7)

http://www.youtube.com/watch?v=buGXaLNE4vw

JDK & JRE


The "JDK" is the Java Development Kit. I.e., the JDK is bundle of software that you can use to develop Java based software. The "JRE" is the Java Runtime Environment. I.e., the JRE is an implementation of the Java Virtual Machine which actually executes Java programs.
Typically, each JDK contains one (or more) JRE's along with the various development tools like the Java source compilers, bundling and deployment tools, debuggers, development libraries, etc.

Marshalling & Serialization

Marshalling : The process of gathering data and transforming it into a standard format before it is transmitted over a network so that the data can transcend network boundaries. In order for an object to be moved around a network, it must be converted into a data stream that corresponds with the packet structure of the network transfer protocol. This conversion is known as data marshalling. Data pieces are collected in a message buffer before they are marshaled. When the data is transmitted, the receiving computer converts the marshaled data back into an object.

In particular, marshaling is about getting parameters from here to there, while serialization is about copying structured data to or from a primitive form such as a byte stream. In this sense, serialization is one means to perform marshaling, usually implementing pass-by-value semantics.

JAXB

No extra jaxb libraries are required if you are using JDK1.6 or above, because JAXB is bundled in JDK 1.6
http://www.mkyong.com/java/jaxb-hello-world-example/

JAXB tutorial part 2: generating classes from XML schema

http://www.youtube.com/watch?v=kOLziP28598
When creating JAXB Project, make sure your eclipse are using JDK 1.6 above to run JAXB. 

Thursday, January 24, 2013

1/24/2013



1. Primitives and collections

Why Java Collections can not directly store Primitives types?

It was a Java design decision (mistake). Containers want Objects and primitives don't derive from Object.
Generics allow you to pretend there is no wrapper, but you still pay the performance price of boxing. This is IMPORTANT to many programmers.

what is so hard technically to include primitive types when talking about Generics ?
In Java's case, it's because of the way generics work. In Java, generics are a compile-time trick, that prevents you from putting an Image object into an ArrayList<String>. However, Java's generics are implemented with type erasure: the generic type information is lost during run-time. This was for compatibility reasons, because generics were added fairly late in Java's life. This means that, run-time, an ArrayList<String> is effectively an ArrayList<Object> (or better: just ArrayList that expects and returns Object in all of its methods) that automatically casts to String when you retrieve a value.

But since int doesn't derive from Object, you can't put it in an ArrayList that expects (at runtime) Object and you can't cast an Object to int either. This means that the primitive int must be wrapped into a type that does inherit from Object, like Integer.


2. A constructor cannot be abstract, static, final, native, or synchronized
It can be public, protected, default, and private.

But, what’s the point of having a private constructor?



2.1 The first that you only want objects to be created internally – as in only created in your class.

Private constructors can be used in the singleton design pattern

2.2 The second is that you don’t want any objects of your class to be created at all.
when creating an object doesn’t make sense – and this occurs when the class only contains static members.


3. Static method can only use static variables.


4. The concept is : || and && are short circuiting operation i.e. if the value of the expression can be known by just seeing the first part then the remaining part is not evaluated while | and & will always let all the parts evaluates.

robust design
if ( (str == null) || (i == str.length() )
(i == str.length()) will only be evaluated if (str == null) is false, and (str == null) will be false if 'str' is NOT null. So it will NEVER throw a NullPointerException.


5. Unlike a class, an interface can extend from multiple interfaces.

6. invalid Identifier

My Variable // Contains a space
9pins // Begins with a digit
a+c // The plus sign is not an alphanumeric character
testing1-2-3 // The hyphen is not an alphanumeric character
O'Reilly // Apostrophe is not an alphanumeric character
OReilly_&_Associates // ampersand is not an alphanumeric characterIdentifiers must comply with these rules:

7. key word:  native?  friendly?

Tuesday, January 22, 2013

Register


Register
A, special, high-speed storage area within the CPU. All data must be represented in a register before it can be processed. For example, if two numbers are to be multiplied, both numbers must be in registers, and the result is also placed in a register. (The register can contain the address of a memory location where data is stored rather than the actual data itself.)
The number of registers that a CPU has and the size of each (number of bits) help determine the power and speed of a CPU. For example a 32-bit CPU is one in which each register is 32 bits wide. Therefore, each CPU instruction can manipulate 32 bits of data.
Usually, the movement of data in and out of registers is completely transparent to users, and even to programmers
Only assembly language programs can manipulate registers. 
In high-level languages, the compiler is responsible for translating high-level operations into low-level operations that access registers.
  • Primary Storage is the top level and is made up of CPU registers, CPU cache and memory which are the only components that are directly accessible to the systems CPU. The CPU can continuously read data stored in these areas and execute all instructions as required quickly in a uniform manner. Secondary Storage differs from primary storage in that it is not directly accessible by the CPU. A system uses input/output (I/O) channels to connect to the secondary storage which control the data flow through a system when required and on request
  • Secondary storage is non-volatile so does not lose data when it is powered down so consequently modern computer systems tend to have a more secondary storage than primary storage. All secondary storage today consist of hard disk drives (HDD), usually set up in a RAID configuration, however older installations also included removable media such us magneto optical or MO
  • Tertiary Storage is mainly used as backup and archival of data and although based on the slowest devices can be classed as the most important in terms of data protection against a variety of disasters that can affect an IT infrastructure. Most devices in this segment are automated via robotics and software to reduce management costs and risk of human error and consist primarily of disk & tape based back up devices
  • Offline Storage is the final category and is where removable types of storage media sit such as tape cartridges and optical disc such as CD and DVD. Offline storage is can be used to transfer data between systems but also allow for data to be secured offsite to ensure companies always have a copy of valuable data in the event of a disaster.

Monday, January 21, 2013

Glassfish - Application Server


What is JNDI?
The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java software clients to discover and look up data and objects via a name. 

File Structure:
/
 - /root
 - /home/glassfish

Commands:
cd ~ -> /root
cd ~glassfish -> /home/glassfish
cd home (and then) cd glassfish -> /home/glassfish


Start/restart/stop-server
[ec2-user@ip-10-195-17-79 ~]$ sudo su -
[root@ip-10-195-17-79 ~]# cd ~glassfish
[root@ip-10-195-17-79 glassfish]# su glassfish
[glassfish@ip-10-195-17-79 ~]$ cd /usr/share/glassfish3/bin
[glassfish@ip-10-195-17-79 bin]$ ls
asadmin  asadmin.bat  pkg  pkg.bat  updatetool  updatetool.bat
[glassfish@ip-10-195-17-79 bin]$ ./asadmin
Use "exit" to exit and "help" for online help.
asadmin> start-domain
Waiting for domain1 to start .....

Or

[ec2-user@ip-10-195-17-79 ~]$ sudo su -
[root@ip-10-195-17-79 ~]#service glassfish start

shut down
[ec2-user@ip-10-195-17-79 ~]$ sudo service glassfish stop  //have to add glassfish as a service first. POdcast 12.


Got a problem that I cannot ping the Postgres DB from Glassfish.
Solution: restart glassfish to load the new-downloaded JDBC.

Creating a Connection Pool to PostgreSQL on Glassfish V3

http://www.hildeberto.com/2010/02/creating-connection-pool-to-postgresql.html


The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java software clients to discover and look up data and objects via a name.
Application in glassfish can use this Name to access to Database.

ALTER ROLE in Postgres


[ec2-user@ip-10-195-17-79 ~]$ sudo su -  // become superuser
[root@ip-10-195-17-79 ~]# su postgres -   // become user:postgres
bash-4.1$ psql -U postgres -c '\du'  //UNIX bash shell - check the role
// 'psql -U postgres' means type in command as user postgres
could not change directory to "/root"

                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 charlie   | Superuser                                      | {}
 load      |                                                | {}
 lord      |                                                | {}
 postgres  | Superuser, Create role, Create DB, Replication | {}
 serf      |                                                | {}

Problem 1---------------could not change directory to "/root" 

viju <ace_of_blackstar(at)yahoo(dot)com> writes:
> I am new to postgresql. I am having some weird problems.
> Output
>  attached below. Please any help would be appreciated.

> bash-3.2$
>  createdb test1
> could not change directory to "/root"
> bash-3.2$ 
> dropdb test
> could not change directory to "/root"
> bash-3.2$ 

Apparently you did "su postgres" from the root account, so you're
still in root's home directory.  It'd be better to do "su - postgres"
to ensure you've acquired all of the postgres account's environment.
Reading "man su" might help you out here.

   regards, tom lane

-----------------------------
Solution: exit and do it again using su - postgres


[root@ip-10-195-17-79 ~]# su - postgres
-bash-4.1$ psql -U postgres
psql (9.2.2)
Type "help" for help.

postgres=#

//now, I can run sql query on the db: postgres
//now, I am gonna add role attributes to lord and serf
//remember to use semicolon because this is the sql clause.
postgres=# DROP ROLE load;
DROP ROLE
postgres=# DROP ROLE lord;
DROP ROLE
postgres=# drop role serf;
ERROR:  role "serf" cannot be dropped because some objects depend on it
DETAIL:  owner of database serfdb
//role attributes
SUPERUSER
NOSUPERUSER
CREATEDB
NOCREATEDB
CREATEROLE
NOCREATEROLE
CREATEUSER
NOCREATEUSER
INHERIT
NOINHERIT
LOGIN
NOLOGIN
CONNECTION LIMIT connlimit
PASSWORD password
ENCRYPTED
UNENCRYPTED
VALID UNTIL 'timestamp'


postgres=# create role lord with superuser encrypted password 'xxxxxxx';
CREATE ROLE
postgres=# alter role serf with encrypted password 'xxxxxx';
ALTER ROLE



Sunday, January 20, 2013

Linux FILE SYSTEM Structure


More file system layout

3.1.3.1. Visual

For convenience, the Linux file system is usually thought of in a tree structure. On a standard Linux system you will find the layout generally follows the scheme presented below.
Figure 3-1. Linux file system layout
This is a layout from a RedHat system. Depending on the system admin, the operating system and the mission of the UNIX machine, the structure may vary, and directories may be left out or added at will. The names are not even required; they are only a convention.
The tree of the file system starts at the trunk or slash, indicated by a forward slash (/). This directory, containing all underlying directories and files, is also called the root directory or "the root" of the file system.
Directories that are only one level below the root directory are often preceded by a slash, to indicate their position and prevent confusion with other directories that could have the same name. When starting with a new system, it is always a good idea to take a look in the root directory. Let's see what you could run into:

emmy:~> cd /
emmy:/> ls
bin/   dev/  home/    lib/         misc/  opt/     root/  tmp/  var/
boot/  etc/  initrd/  lost+found/  mnt/   proc/    sbin/  usr/
Table 3-2. Subdirectories of the root directory
DirectoryContent
/binCommon programs, shared by the system, the system administrator and the users.
/bootThe startup files and the kernel, vmlinuz. In some recent distributions also grub data. Grub is the GRand Unified Boot loader and is an attempt to get rid of the many different boot-loaders we know today.
/devContains references to all the CPU peripheral hardware, which are represented as files with special properties.
/etcMost important system configuration files are in /etc, this directory contains data similar to those in the Control Panel in Windows
/homeHome directories of the common users.
/initrd(on some distributions) Information for booting. Do not remove!
/libLibrary files, includes files for all kinds of programs needed by the system and the users.
/lost+foundEvery partition has a lost+found in its upper directory. Files that were saved during failures are here.
/miscFor miscellaneous purposes.
/mntStandard mount point for external file systems, e.g. a CD-ROM or a digital camera.
/netStandard mount point for entire remote file systems
/optTypically contains extra and third party software.
/procA virtual file system containing information about system resources. More information about the meaning of the files in proc is obtained by entering the command man proc in a terminal window. The file proc.txt discusses the virtual file system in detail.
/rootThe administrative user's home directory. Mind the difference between /, the root directory and /root, the home directory of the root user.
/sbinPrograms for use by the system and the system administrator.
/tmpTemporary space for use by the system, cleaned upon reboot, so don't use this for saving any work!
/usrPrograms, libraries, documentation etc. for all user-related programs.
/varStorage for all variable files and temporary files created by users, such as log files, the mail queue, the print spooler area, space for temporary storage of files downloaded from the Internet, or to keep an image of a CD before burning it.
How can you find out which partition a directory is on? Using the df command with a dot (.) as an option shows the partition the current directory belongs to, and informs about the amount of space used on this partition:

sandra:/lib> df -h .
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda7             980M  163M  767M  18% /
As a general rule, every directory under the root directory is on the root partition, unless it has a separate entry in the full listing from df (or df -h with no other options).
Read more in man hier.

KPM

http://www.matrix67.com/blog/archives/115/

Saturday, January 19, 2013

SSH/EC2 && sudo/su


charlie@ubuntu:~/CS548$ ssh -i ~/CS548/XXXX.pem ec2-user@eXXXXXX.amazonaws.com


I got this error at the beginning.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0664 for 'CS548/ec2-glassfish-keypair.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: CS548/ec2-glassfish-keypair.pem
Permission denied (publickey).

Solution:
change the permission to access private key :
Only owner can read and write the private key:
chmod 600 /home/me/.ssh/id_rsa_targethost
chomod 600 ~/CS548/XXXX.pem
http://www.thinkplexx.com/learn/howto/security/ssh/fix-permissions-are-too-open-private-key-will-be-ignored

SSH - "provide secure remote login"
SSH(SecureShell)是目前比较可靠的为远程登录会话和其他网络服务提供安全性的协议。利用SSH协议可以有效防止远程管理过程中的信息泄露问题。通过SSH,可以把所有传输的数据进行加密,也能够防止DNS欺骗和IP欺骗。


后面会提示你私钥的文件名,放在哪,这些问题,选择默认就行了,中途会让你输入密码,这个你可得记住。这样你的用户目录下会多出一个隐藏的.ssh文件夹。可以使用ls-A来查看。里面还有两文件,一个是id_rsa(私钥),还有一个是id_rsa.pub(公钥)
这个私钥和公钥到底是什么概念?
简单说,公钥就是你的银行帐户,这个可能别人也知道,但只有手上有信用卡或是存折才能有资格去试帐户密码。所以这个信用卡和存折就是你的私钥。所以这个私钥得保存好。
也就是说,那个id_rsa文件你得保存好,可以弄到U盘上,随身带着。而id_rsa.pub得改成系统默认识别的authorized_keys并保存在.ssh文件夹下



15 Linux Yum Command Examples – Install, Uninstall, Update Packages

http://www.thegeekstuff.com/2011/08/yum-command-examples/

Installing, removing, and updating packages is a typical activity on Linux. Most of the Linux distributions provides some kind of package manager utility. For example, 
apt-get, dpkg, rpm, yum, etc.
On some Linux distributions, yum is the default package manager.
yum-security  http://linux.die.net/man/8/yum-security

Description

This plugin extends yum to allow lists and updates to be limited using security relevant criteria


sudo意思就是super-user do,让当前用户暂时以管理员的身份root来执行这条命令。
su是用来改变当前用户的,su root,就是将当前用户切换为root,用了su root之后,下面所有的命令就可以不用打sudo了,因为当前用户已经是管理员root了。
root 用户为根用户,也就是 系统管理员 拥有全部权限
一个用户只能拥有一个 GID ,但是还可以归属于其它附加群组

Those commands I used to initialize my instance in EC2:

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2012.09-release-notes/
[ec2-user@ip-10-195-17-79 ~]$ ls
[ec2-user@ip-10-195-17-79 ~]$ su root
Password: 
su: incorrect password
[ec2-user@ip-10-195-17-79 ~]$ sudo su -
[root@ip-10-195-17-79 ~]# ^C
[root@ip-10-195-17-79 ~]# 

[root@ip-10-195-17-79 ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/xvda1             8256952    966160   7206936  12% /
tmpfs                   304364         0    304364   0% /dev/shm

[root@ip-10-195-17-79 ~]# fdisk -l                             ----查看硬盘分区

Disk /dev/xvda1: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/xvdf: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@ip-10-195-17-79 ~]# mkfs -t ext3 /dev/xvdf         
/*mkfs - build a Linux file system








-t fstype
Specifies the type of file system to be built. If not specified, the default file system type (currently ext2) is used.*/

mke2fs 1.42.3 (14-May-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done


/*
Cat 有三大功能
1. 一次显示整个文件
$cat filename
2. 从键盘输入内容创建一个文件,该命令不能用来修改已经存在的文件
$cat >filename2
3. 把多个文件合并成一个文件
$cat filename1 filename2 > filename3
*/


/*
The fstab ( /etc/fstab ) (or file systems table) file is a system configuration file commonly found on Unix systems.

*/

[root@ip-10-195-17-79 ~]# cat /etc/fstab
#
LABEL=/     /           ext4    defaults,noatime  1   1
tmpfs       /dev/shm    tmpfs   defaults        0   0
devpts      /dev/pts    devpts  gid=5,mode=620  0   0
sysfs       /sys        sysfs   defaults        0   0
proc        /proc       proc    defaults        0   0
[root@ip-10-195-17-79 ~]# echo "/dev/xvdf /data ext3 noatime 0 0">>/etc/fstab
[root@ip-10-195-17-79 ~]# cat /etc/fstab  

 /* 

What is fstab and why it's useful >

http://www.tuxfiles.org/linuxhelp/fstab.html
*/
#
LABEL=/     /           ext4    defaults,noatime  1   1
tmpfs       /dev/shm    tmpfs   defaults        0   0
devpts      /dev/pts    devpts  gid=5,mode=620  0   0
sysfs       /sys        sysfs   defaults        0   0
proc        /proc       proc    defaults        0   0
/dev/xvdf /data ext3 noatime 0 0


/*mount command: 挂载文件系统*/

[root@ip-10-195-17-79 ~]# mount /data
[root@ip-10-195-17-79 ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/xvda1             8256952    966168   7206928  12% /
tmpfs                   304364         0    304364   0% /dev/shm
/dev/xvdf              1032088     34088    945572   4% /data

// Install postgresql:


[root@ip-10-195-17-79 ~]# sudo yum install postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs

//initialize the software



[ec2-user@ip-10-195-17-79 ~]$ sudo rm -rf /data/lost+found
[ec2-user@ip-10-195-17-79 ~]$ chown -R postgres:postgres /data
chown: changing ownership of `/data': Operation not permitted
[ec2-user@ip-10-195-17-79 ~]$ sudo chown -R postgres:postgres /data
[ec2-user@ip-10-195-17-79 ~]$ sudo su -
[root@ip-10-195-17-79 ~]# su postgres -
bash-4.1$  /usr/bin/initdb -D /data
could not change directory to "/root"
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

fixing permissions on existing directory /data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/bin/postgres -D /data
or
    /usr/bin/pg_ctl -D /data -l logfile start

bash-4.1$ 


bash-4.1$  wget -O postgresql.conf.1 http://www.cs.stevens.edu/~dduggan/Teaching/Scripts/ec2/postgresql.conf
--2013-01-20 20:03:00--  http://www.cs.stevens.edu/~dduggan/Teaching/Scripts/ec2/postgresql.conf
Resolving www.cs.stevens.edu... 155.246.89.84
Connecting to www.cs.stevens.edu|155.246.89.84|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16947 (17K) [text/plain]
Saving to: “postgresql.conf.1”

100%[===============================>] 16,947      --.-K/s   in 0.02s   

2013-01-20 20:03:01 (784 KB/s) - “postgresql.conf.1” saved [16947/16947]


Control the server


bash-4.1$ /usr/bin/pg_ctl start -D /data
server starting
bash-4.1$ /usr/bin/pg_ctl status -D /data
pg_ctl: server is running (PID: 2502)
/usr/bin/postgres "-D" "/data"

PostgreSQL - creating and dropping roles


http://articles.slicehost.com/2009/5/7/postgresql-creating-and-deleting-roles


----------------------------------------------------------------set up jdk--------------------------------------


/* solution for install java using wget
wget in linux
http://blog.kdecherf.com/2012/04/12/oracle-i-download-your-jdk-by-eating-magic-cookies/

*/

/* scp command - > copy file using ssh */


/*create a usrgroup and create a user */

Friday, January 18, 2013

同步和异步的区别


 举个例子:普通B/S模式(同步)AJAX技术(异步)
同步:提交请求->等待服务器处理->处理完毕返回 这个期间客户端浏览器不能干任何事
异步: 请求通过事件触发->服务器处理(这是浏览器仍然可以作其他事情)->处理完毕
--------------------------------------------------------------------------------------------------------------------
同步就是你叫我去吃饭,我听到了就和你去吃饭;如果没有听到,你就不停的叫,直到我告诉你听到了,才一起去吃饭。
异步就是你叫我,然后自己去吃饭,我得到消息后可能立即走,也可能等到下班才去吃饭。
所以,要我请你吃饭就用同步的方法,要请我吃饭就用异步的方法,这样你可以省钱。
--------------------------------------------------------------------------------------------------------------------
举个例子 打电话时同步 发消息是异步

Wednesday, January 16, 2013

CoreJava- JNLP & Applet

1. MANIFEST.MF
In addition to class files, images, and other resources, each JAR file contains a  manifest
file that describes special features of the archive. 
The manifest file is called MANIFEST.MF  and is located in a special  META-INF  subdirectory of 
the JAR file. 

从eclipse导出来的jar包还是不能跑的,要修改一下META-INF/MANIFEST.MF

加入Main-Class: packageName/ClassName




2. Apple
<body>
<applet code="NotHelloWorldApplet.class" width="300" height="100" title="Hide this plug-in"></applet>
</body>






1/16/2013 Java Certification


1. What is wrong with the following code?
abstract class TestClass{
   transient int j;
   synchronized int k;  //Variables cannot be declared synchronized. 
   final void TestClass(){}//This is not a constructor because it has return type
   static void f(){  //cannot be declared static Because it refers to instance variables j and k
      k = j++;
   }
}


2. You cannot store primitives in an ArrayList because only Objects can be stored in it.
An ArrayList is backed by an array.

Integer can be stored in it while int cannot.

3. There is no graph in Collections.


4. Trie Structure?



5. Overriding

class A{
   A() {  print();   }
   void print() { System.out.println("A"); }
}
class B extends A{
   int i =   Math.round(3.5f);
   public static void main(String[] args){
      A a = new B();
      a.print();
   }
   void print() { System.out.println(i); }
}






世界上最浪费时间的是三个单词:WORRY, BLAME, & JUDGEMENT.


如果你问,世界上最浪费时间的是什么事?
微博?人人?魔兽世界?
不是,尽管它们排名也很靠前。
其实,世界上最浪费时间的是三个单词:WORRY, BLAME, & JUDGEMENT.
第一位:WORRY,就是担忧。
让我们感觉到担忧的事情很多,年纪越大,越是如此。然而,总体来说,让我们担忧的不过两类事情:

1. 我们准备不足的事情,如考试,如演出,如工作机会……我们担忧这些事情,因为我们害怕自己会搞砸。搞砸的原因很多,但归根究底,最可能的,最直接的原因就是准备不足。没有努力复习,没有努力准备,没有资料,没有经验,没有思想准备,没有投入足够的时间进行练习……那么既然我们准备不足,该怎么做呢?难道就坐在地上紧皱眉头担忧?当然是赶快去做准备啦!
2.我们改变不了的事情,如别人的看法,如自己天生的缺陷,如世界末日?
有的事情,不是你能够改变的,我们刻苦的亚洲人总觉得自己多努力一点,就能够获得完满,让周围的人都喜欢自己,让世界充满爱。
然而,这个世界很多事实是你无法改变的。就像有的人天生就喜欢你一样,有的人天生就不喜欢你。不管你多么努力,多么投入地去讨好,不喜欢你的人就是不喜欢你。有时候根本都不是你的问题,就是气场不合。
既然改变不了,为什么要去担心呢?担心就能改变了吗?让它随风而去吧! 改变不了就放掉它!享受你的生活。

第二浪费时间大事,就是BLAME,也就是责怪啦。
责怪是很简单的事,是人都会。 上不了大学我们怪父母教育不当;找不到工作,我们怪大学不够务实;上班迟到了我们怪公交系统;谈恋爱失败了我们怪对方自私;演出失败了我们怪音响不好;考试挂掉了我们却怪老师……
从现在开始,如果你想要成为一个快乐的成功的人,那就停止责怪吧。
自己为自己负起责任来。

你是唯一的一个有责任的人。你的人生,你的幸福,是你自己的责任。
不错,我们都有伤心往事,你哭说你爸妈从小打你,我哭说我老师曾经当众辱骂我,他说他女朋友曾经劈腿多次让他伤到不敢再去爱,她说她从小没有父亲所以总忍不住喜欢已婚大龄男人。
我就只问你一句:那你想怎么样?
从来没有过伤心的经历的举个手来看看?
我们可能会遇见对我们不好的人,我们可能会嫁给对我们不好的人。
然而,选择留在这种悲惨关系中的人,是谁?
选择不去尝试改变,不去寻求帮助的人,是谁?
相信我,不管生在何方,我们永远有选择,永远都有。

当然,有的选择并不容易,有的时候,我们不得不妥协,然而,选择妥协,也是说明我们可以,甚至愿意承受这些不幸,不是吗?既然愿意承受,可以承受,为什么还要责怪它?
责怪别人,别人一点也不会受到伤害,大多时候他们根本都不会做出改变。 气得一塌糊涂,觉得自己生活悲惨得稀里糊涂的人,只是你,你这个责怪者而已。 别再责怪了,从今天开始,一切都当作自己的责任。
如果我搞砸了,那么,从中学习经验,下一次试着做更好。实在没什么好怪责的。
那,最后一个浪费时间的单词:Judgement。
注意,这里的Judgement不是说判断力哈,判断力还是要有的。
这里的Judgement,是说评判别人。

我们总喜欢看戏,看别人的生活,然后得出结论:张三是这个样子,李四是那个样子,王五其实一文不值只是装出有钱的样子,赵钱孙是个野蛮不讲道理的人……
是的,这些结论也许都是正确的。
那又如何呢?
你看得好透彻,你说的好精彩,然后呢?

张三是傻了点可他特真诚大家都喜欢他,李四软弱是真的但是他对女朋友特别好他们这就要幸福地结婚了,王五爱装逼但是那是因为他小时候在被人瞧不起过,赵钱孙则是从小被一个喝酒的爸爸打骂长大的……
你看到那些故事了吗?那些你所不知道的东西了吗?你对自己作过剖析吗?
对别人的生活做出判断,首先是一件非常粗暴野蛮的事情,大多时候,你根本不了解这个人,你根本不明白你做出的这些判断有多么肤浅。
其次,就算你判断出来了,那又怎么样,别人继续走着他的路,即使那在你眼中是很愚蠢的路,他继续享受着他的人生,你呢?
在路边上亦步亦趋地盯着人家怎么生活的你不是更可悲吗?你得意地笑话着别人,却没有意识到,你也在画面中。经过的人们,也都在看你。你也很好笑的。
或者,应该说,我们每一个人都很好笑的。但同时,我们都有各自可爱的,可恨的,可鄙的,可敬的那一面。
既然如此,各走各的,能忍的忍,不能忍的你就躲远点。 话虽如此,世上的事永远说的比做的容易。我仍然担忧,我仍然怪责,仍然给别人下着定义……在这里读文章,试图给别人意见的我,也是一个很好笑的人。
不过,想通这一点。
至少我,很快乐。
希望你也能快乐起来