Building a Web Application Using EJB, JPA, and JavaServer Faces – Annotations

Any symbol in Java code beginning with @ is known as an annotation.  

The use of annotations allows you to add metadata to your objects. Examples of annotations follow:

Annotation Description
@Entity Identifies the file as an EJB 3.0 entity
@NamedQuery A query that can be used at run time to retrieve data
@Table Specifies the primary table for the entity
@Id Can define which property is the identifier for the entity
@Column Specifies a mapped column for a persistent property or field
@ManyToOne Specifies a type of foreign key relationship between tables
@JoinColumn Specifies the join column and referenced column for a foreign key relationship

Python – Coding with fun

How to reverse a string?

s = 'abcdef'

s = s[::-1]

print s 

Explanation: “::” is known as stride notation

s[::2]
s[::-2]

Returns “ace” and “fdb” respectively.

How to read from console in Python?

name = raw_input()

Want to read an integer?

num = raw_input()
num = int(num) # raw_input returns string, so convert it to integer

Swap values in python:

a, b = b, a

My motivation to learn python is: life is short – you need Python

Installing Apache Maven-Java tool

Download maven.

Windows OS:

  1. Unzip the distribution archive, i.e. apache-maven-3.0.4-bin.zip to the directory you wish to install Maven 3.0.4. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-3.0.4 will be created from the archive.
  2. Add the M2_HOME environment variable. [almost similar as this]: adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.0.4. Be sure to omit any quotation marks around the path even if it contains spaces.
  3. In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.
  4. In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.
  5. In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g.C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in your Path environment variable.
  6. Open a new command prompt and run mvn –version to verify that it is correctly installed.

Linux based/Ubuntu Operating Systems:

  1. Extract the distribution archive, to the directory you wish to install Maven 3.0.4. These instructions assume you chose /home/username/java/tools/maven.
  2. Open terminal and type:  gedit ~/.bashrc
  3. Set environment variable by adding the following lines at the bottom of .bashrc :
    •  export M2_HOME=/home/username/java/tools/maven
    • export M2=$M2_HOME/bin
    • export PATH=$M2:$PATH
    • export JAVA_HOME=/usr/lib/jvm/jdk-default #if JAVA_HOME not exist.
  4. Run mvn –version to verify that it is correctly installed.

Send and receive SMS using GSM modem or phone on Ubuntu | TechyTalk.info

Send and receive SMS using GSM modem or phone on Ubuntu | TechyTalk.info.

#go to terminal and give the msg as below
#sudo python sms.py 'CellNumber Msg you want to send'
import gammu
import sys
def main():
	words = sys.argv[1].split(None, 1)
	dest = words[0]
	msg = words[1]
	print msg + "-----" + dest
	#return
	sms = gammu.StateMachine()
	sms.ReadConfig()
	sms.Init()
	message = {
	    'Text': msg,
	    'SMSC': {'Location': 1},
	    'Number': destinationNumber,
	}
	print sms.SendSMS(message)

if  __name__ =='__main__':
	main()

How to create non-editable JTable:

Override the method “isCellEditable” and implement as needed, such as:

//instance table model
DefaultTableModel tableModel = new DefaultTableModel(){
   @Override
   public boolean isCellEditable(int row, int column) {
      return false;
   }
};
//...others
table.setModel(tableModel);

System.getProperty(key) key list for java:

 


java.version Java Runtime Environment version
java.vendor Java Runtime Environment vendor
java.vendor.url Java vendor URL
java.home Java installation directory
java.vm.specification.version Java Virtual Machine specification version
java.vm.specification.vendor Java Virtual Machine specification vendor
java.vm.specification.name Java Virtual Machine specification name
java.vm.version Java Virtual Machine implementation version
java.vm.vendor Java Virtual Machine implementation vendor
java.vm.name Java Virtual Machine implementation name
java.specification.version Java Runtime Environment specification version
java.specification.vendor Java Runtime Environment specification vendor
java.specification.name Java Runtime Environment specification name
java.class.version Java class format version number
java.class.path Java class path
java.library.path List of paths to search when loading libraries
java.io.tmpdir Default temp file path
java.compiler Name of JIT compiler to use
java.ext.dirs Path of extension directory or directories
os.name Operating system name
os.arch Operating system architecture
os.version Operating system version
file.separator File separator (“/” on UNIX)
path.separator Path separator (“:” on UNIX)
line.separator Line separator (“\n” on UNIX)
user.name User’s account name
user.home User’s home directory
user.dir User’s current working directory

 

Installing Oracle-JDK in Ubuntu

Download JDK from ORacle. Run Terminal:

chmod u+x jdk-6u31-linux-i586.bin
./jdk-6u31-linux-i586.bin
sudo mv jdk1.6.0_31 /usr/lib/jvm/

#Next line will add java to symlink

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_31/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.6.0_31/bin/javac" 1

Or, you can set environment variable by adding the following lines at the bottom of .bashrc by “gedit ~/.bashrc”:

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_03
export PATH=$PATH:$JAVA_HOME/bin

You can now check if the java is installed properly in terminal:

java -version
javac -version

These will return the version of java and javac.

Generics are not supported in -source 1.3 error in Maven Project

When compiling via maven project, you may have encountered following error:

generics are not supported in -source 1.3 error in Maven Project. use -source 5 or higher to enable generics.

Annotation is not allowed in -source 1.3 use -source 5 or higher to enable annotation.

To solve this you must add the below lines at your pom.xml :

<build>
 <plugins>
  <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
    <source>1.5</source>
    <target>1.5</target>
   </configuration>
  </plugin>
 </plugins>
</build>

C++ : keywords

32 keywords defined by standard C.

auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

A list of some commonly used extended keywords:

asm  _cs  _ds  _es
_ss  cdecl  far  huge
interrupt  near  pascal  

All C (and C++) keywords are lowercase. Also, uppercase and lowercase are
different: else is a keyword; ELSE is not.