Thursday, July 31, 2014

Three Men Show: Disclaimer Is Injurious To Movies

Three Men Show: Disclaimer Is Injurious To Movies: A common man in India has planned to escape his stressful life, by going to a movie theatre. You know what he’ll face first? Yes, an a...

Tuesday, August 6, 2013

JSF (JavaServer Faces) Tutorial

This article describes how to develop JavaServer Faces web applications with Eclipse WTP JSF tooling. It demonstrates managed beans, validators, external resource bundles and the JSF navigation concept.
This tutorial was developed with Java 1.6, JavaServerFaces 1.2, the Apache MyFaces JSF implementation, Tomcat 6.0 and Eclipse 3.6.

Table of Contents
1. JavaServer Faces - JSF
1.1. What is JSF
1.2. A JSF application
1.3. Value and Method Binding
1.4. Prerequisites to use JSF
1.5. JSF Main features
1.6. JSP and JSF
2. JSF configuration files
2.1. Overview
2.2. web.xml
2.3. faces-config.xml
3. Installation
3.1. Eclipse
3.2. JSF library
3.3. JSLT library
4. Your first JSF project
4.1. Create JSF Project
4.2. Review the generated project
4.3. Domain Model
4.4. Define managed bean
4.5. Create JSP
4.6. Run your webapplication
4.7. Layout via css
5. Your second JSF application
5.1. Create JSF Project
5.2. Domain model
5.3. Register your managed beans
5.4. Validators
5.5. Resource bundle for messages
5.6. JavaServer Page with JSF components
5.7. Navigation Rule
5.8. Run your webapplication
6. JSF application with a controller
6.1. Create JSF Project
6.2. Domain model
6.3. Controller
6.4. Register your managed beans- Dependency injection
6.5. Resource bundle for messages
6.6. JavaServer Page with JSF components
6.7. Run your webapplication
7. A Todo JSF application
7.1. Create JSF Project
7.2. Domain model
7.3. Controller
7.4. Register your managed beans
7.5. Create css
7.6. JavaServer Page with JSF components
7.7. Run your webapplication
8. Thank you
9. Questions and Discussion
10. Links and Literature
10.1. Tutorials and Websites
10.2. JSF component libraries

1. JavaServer Faces - JSF

1.1. What is JSF

JavaServer Faces (JSF) is a UI component based Java Web application framework. JSF is serverbased, e.g. the JSF UI components and their state are represented on the server with a defined life-cycle of the UI components. JSF is part of the Java EE standard.
A JSF application run in a standard web container, for example Tomcat or Jetty.
This articles provides an introduction to JSF using only standard JSF features. For the usage of special Apache Trinidad features please see Apache Myfaces Trinidad with Eclipse - Tutorial .

Java Snake Game

Snake

In this part of the Java 2D games tutorial, we will create a Java Snake game clone.

Snake

Snake is an older classic video game. It was first created in late 70s. Later it was brought to PCs. In this game the player controls a snake. The objective is to eat as many apples as possible. Each time the snake eats an apple, its body grows. The snake must avoid the walls and its own body. This game is sometimes called Nibbles.

Development

The size of each of the joints of a snake is 10px. The snake is controlled with the cursor keys. Initially the snake has three joints. The game is started by pressing one of the cursor keys. If the game is finished, we display Game Over message in the middle of the Board.

Java 2D games tutorial

Basics

This is Java 2D games tutorial. It is aimed at beginners. This tutorial will teach you basics of programming 2D games in Java programming language and Swing GUI toolkit. All images used in this tutorial can be downloaded here.

Skeleton

We will show the skeleton of each of our Java 2D games.
Board.java
package skeleton;

import javax.swing.JPanel;

public class Board extends JPanel {
    public Board() {
    }
}
The Board is a panel, where the game takes place.
Skeleton.java
package skeleton;

import javax.swing.JFrame;

public class Skeleton extends JFrame {

    public Skeleton() {
        add(new Board());
        setTitle("Skeleton");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300, 280);
        setLocationRelativeTo(null);
        setVisible(true);
        setResizable(false);
    }
    public static void main(String[] args) {
        new Skeleton();
    }
}
This is the entry point of the game. Here we have the main method.
add(new Board());
Here we put the Board to the center of the JFrame component.
setDefaultCloseOperation(EXIT_ON_CLOSE);
This will close the application when we click on the close button. It is not the default behaviour.
setSize(300, 280);
This line sets the size for our window.
setLocationRelativeTo(null);
We center the window.
setVisible(true);
Show the window on the screen.
setResizable(false);
Make the window unresizable.
Skeleton
Figure: Skeleton

Comparison of Java and Android API

This article compares the Java and Android API and virtual machines.
While most Android applications are written in Java, there are many differences between the Java API and the Android API, and Android does not use a Java Virtual Machine but another one called Dalvik.

Android's Process Virtual machine

There is no Java Virtual Machine in the Android platform. Java byte code is not executed. Instead Java classes are compiled into Dalvik executables and run on Dalvik, a specialized virtual machine (VM) designed specifically for Android. Unlike Java VMs, which are stack machines, the Dalvik VM is a register-based architecture.

Dalvik has some specific characteristics that differentiate it from other standard VMs:
  • The VM was designed to use less space.
  • The constant pool has been modified to use only 32-bit indexes to simplify the interpreter.
  • Standard Java bytecode executes 8-bit stack instructions. Local variables must be copied to or from the operand stack by separate instructions. Dalvik instead uses its own 16-bit instruction set that works directly on local variables. The local variable is commonly picked by a 4-bit 'virtual register' field.
Because the bytecode loaded by the Dalvik virtual machine is not Java bytecode, and of the specific way Dalvik load classes, it is not possible to load Java libraries packages as jar files, and even a specific logic must be used to load Android libraries (specifically the content of the underlying dex file must be copied in the application private internal storage area, before being able to be loaded).

System properties

As it is the case for the Java SE class System, the Android System class allows the retrieval of system properties. However, some mandatory properties defined with the Java Virtual Machine have no meaning or a different meaning on Android. For example:

  • "java.version" property returns 0 because it is not used on Android,
  • "java.specification.version" invariably returns 0.9 independently of the version of Android used,
  • "java.class.version" invariably returns 50 independently of the version of Android used,
  • "user.dir" has a different meaning on Android,
  • "user.home" and "user.name" properties do not exist on Android

Class library

Dalvik does not align to Java SE nor Java ME class library profiles (e.g., Java ME classes, AWT or Swing are not supported). Instead it uses its own library ,built on a subset of the Apache Harmony Java implementation.

java.lang package

By default, the default output stream System.out and System.err do not output anything,[6] and developers are encouraged to use the Log class, which logs Strings on the LogCat tool.[7] (this has changed at least from HoneyComb, and they now output to the log console as well)

Graphics and Widget library

Android does not use the Abstract Window Toolkit nor the Swing library. User Interface is built using View objects. Android uses a framework similar to Swing based around Views rather thanJComponents. However, Android widgets are not JavaBeans: the Android application Context must be provided to the widget at creation.

Look and feel

Android widget library does not support a Pluggable look and feel architecture; The Look and Feel of Android widgets must be embedded in the widgets themselves. There is, however, a limited capability to set styles and themes for an application.

Layout manager

Contrary to Java where Layout managers can be applied to any container widget, Android layout behavior is encoded in the containers.

J2ME Tutorial

Introduction

This tutorial assumes that you have some familiarity with general programming concepts and the Java language.

What is J2ME?

J2ME stands for Java 2, Micro Edition. It is a stripped-down version of Java targeted at devices which have limited processing power and storage capabilities and intermittent or fairly low-bandwidth network connections. These include mobile phones, pagers,wireless devices and set-top boxes among others.

A Sample Wireless Stack would consist of:
  • Profiles
  • Configurations
  • Java Virtual Machines
  • Host Operating System

What is a J2ME Configuration?

A configuration defines the minimum Java technology that an application developer can expect on a broad range of implementing devices.

J2ME Connected, Limited Device Configuration (CLDC)

  • specifies the Java environment for mobile phone, pager and wireless devices
  • CLDC devices are usually wireless
  • 160 - 512k of memory available for Java
  • typically has limited power or battery operated
  • network connectivity, often wireless, intermittent, low-bandwidth (9600bps or less)

J2ME Connected Device Configuration (CDC)

  • describes the Java environment for digital television set-top boxes, high end wireless devices and automotive telematics systems.
  • device is powered by a 32-bit processor
  • 2MB or more of total memory available for Java
  • network connectivity, often wireless, intermittent, low-bandwidth (9600bps or less)
These two configurations differ only in their respective memory and display capabilities.

What is a J2ME Profile?

A specification layer above the configuration which describes the Java configuration for a specific vertical market or device type.

J2ME Profiles

J2ME Mobile Information Device Profile (MIDP)

  • this is the application environment for wireless devices based on the CLDC
  • contains classes for user interface, storage and networking

J2ME Foundation Profile, Personal Basis, Personal and RMI profiles

  • these are profiles for devices based on the CDC, which are not addressed in this tutorial

Virtual Machines

The CLDC and the CDC each require their own virtual machine because of their different memory and display capabilities. The CLDC virtual machine is far smaller than that required by the CDC and supports less features. The virtual machine for the CLDC is called the Kilo Virtual Machine (KVM) and the virtual machine for the CDC is called the CVM.

Java Cryptography

Cryptography is a field looking at techniques for "encoding and verifying things securely". It tends to focus on the following issues:

  • encryption of data so that an unauthorised third party cannot read it without a key of some sort;
  • authentication and validation (or certification): broadly speaking, checking that a piece of data is "what it should be" or "hasn't been tampered with"— e.g. whether the data was transmitted error-free, whether it was deliberately altered by third parties, and indeed whether the parties are who we believe they are;
  • computer protocols for using the previous two techniques correctly and in a way that allows all parties to know how they're being used (e.g. the TLS protocol allows a client to connect to a server over the Internet without the two machines previously knowing things such as session key or even preferred encryption method, maximum key length etc).
Indirectly at least, it is also concerned with human protocols for using these techniques (e.g. "don't make your password less than X characters", "don't just use letters in your password" etc).
When used appropriately, cryptography brings developers some very powerful tools, allowing us to do things like transmit login information securely across an untrusted network. Java is an excellent choice for building secure applications from the point of view that it has various standard cryptographical functions built in to the standard runtime libraries. But just as the existence of the Swing library doesn't automatically give your application a fantastic user interface, a cryptography library does not bring automatic security. There are still various challenges that we need to address beyond the simple "how do I perform such-and-such a function", for example:
  • we need to understand which tool/algorithm we need when;
  • where there's a choice, we need to assess the strengths and weaknesses of each;
  • some algorithms have various parameters that we need to understand;
  • using some algorithms correctly can be tricky and requires a little understanding of what is going on (e.g. using "128-bit encryption" with a key generated by java.util.Random doesn't give anything like 128 bits of security...);
  • even issues such as "what data should we encrypt when" can be a problem;
  • we need to take account of the security risks and needs, vs other needs, of different parts of our application and system as a whole.
On the following pages, we therefore discuss various topics:
  • we start with an introduction to encryption in general, considering why key-based encryption with a public algorithm is generally a better solution than "security through obscurity";
  • we look at symmetric encryption, which gives generally fast encryption via a shared secret key, generally using a type of algorithm called a block cipher whose weaknesses we need to assess;
  • asymmetric encryption, including how to use the common RSA encryption scheme in Java;
  • we give a comparison of encryption algorithms, showing performance data and an overview of current security opinion on the various symmetric ciphers;
  • key sizes: how to choose an encryption key size for symmetric encryption and how to enable and use larger key sizes in Java;
  • Secure hash functions, used for a variety of purpoes; we consider the performance and security of the various algorithms provided by standard in Java 6;
  • password-based encryption, in which we derive an encryption key from a password entered by the user.

Tuesday, July 9, 2013

Simple Search Engine Using C and CPP Project

Introduction :

This is a 'SSE' application. SSE stands for Simple Search Engine. It is a simple application that can be used to search within text file on a system.

Application Platform : GNU/Linux
Development Platform : Red Hat Linux
Programming Language : C++
Libraries used : C++ Standard Library

Project Specification:

Following is a summary of the requirements from the Requirements specification.
                1. Keyword Search: Search for a given keyword and return the set of documents containing the keyword. Rank the quesry results based on how frequently the keyword has appeared in the documents.
                2. Case-insensitivity: Keyword searches should be case insensitive.
                3. Logical operators: Define logical operators AND and OR that can be used to compose a complex query.
                4. Pharse matching: Pharses that are enclosed in quotes should match exactly.
                5. Stemming: An asterisk (*) at the end of a keyword should match all endings of the word.

                6. The result of a query should be a set of path names ordered in decending order of the number of occurences of the keywords.



Download Project Here