Thursday, 26 December 2013

what is SSL , https ?

SSL stands for Secure Sockets Layer. It is a protocol which creates a secure connection between a client and the server over which to send information.

SSL works by using a cryptographic system that uses two keys to encrypt data. The first key is a private or secret key, only known to the recipient of the message. The second key is a public key, known to everyone. Netscape Navigator and Internet Explorer both support SSL and many websites use the protocol to obtain confidential user information, such as credit card numbers.

As a general rule, you can tell whether a URL requires an SSL connection if it begins with “https” instead of “http”.
A valid SSL Certificate is an assurance that information which you will share on this site, will be sent in an encrypted, safe way.

An SSL Certificate will contain information on the domain name, its owner and the physical location of the owner and the validity dates of the certificate. SSL Certificates are thus a useful tool in determining whether websites are trustworthy or not. Many online shoppers will not risk buying items on a non-secure site.



More Reference :




Monday, 9 December 2013

SAX / DOM / STAX




here is a small comparison between SAX, DOM and STAX

╔══════════════════════════════════════╦═════════════════════════╦═════════════════════════╦═══════════════════════╦═══════════════════════════╗
║          JAXP API Property           ║          StAX           ║           SAX           ║          DOM          ║           TrAX            ║
╠══════════════════════════════════════╬═════════════════════════╬═════════════════════════╬═══════════════════════╬═══════════════════════════╣
║ API Style                            ║ Pull events; streaming  ║ Push events; streaming  ║ In memory tree based  ║ XSLT Rule based templates ║
║ Ease of Use                          ║ High                    ║ Medium                  ║ High                  ║ Medium                    ║
║ XPath Capability                     ║ No                      ║ No                      ║ Yes                   ║ Yes                       ║
║ CPU and Memory Utilization           ║ Good                    ║ Good                    ║ Depends               ║ Depends                   ║
║ Forward Only                         ║ Yes                     ║ Yes                     ║ No                    ║ No                        ║
║ Reading                              ║ Yes                     ║ Yes                     ║ Yes                   ║ Yes                       ║
║ Writing                              ║ Yes                     ║ No                      ║ Yes                   ║ Yes                       ║
║ Create, Read, Update, Delete (CRUD)  ║ No                      ║ No                      ║ Yes                   ║ No                        ║
╚══════════════════════════════════════╩═════════════════════════╩═════════════════════════╩═══════════════════════╩═══════════════════════════╝

there are different approaches for parsing an xml source. You should select proper approach for your needs. You may choose one of these:
  • DOM - Document Object Model,
  • SAX - Simple API for XML,
  • StAX – Streaming API for XML
Let’s discuss each one.

Monday, 4 November 2013

The "Reference" reference is not defined by the implementation. #Solving #SCA #RSA #RDA

when you are trying to make a components and composites in SCA using RAD ,

you will found that there are an error due to the naming in Reference in the compost file.


Sunday, 3 November 2013

how to add “Server view” in Eclipse / RSA Rational Software Architect ?

I had installed my RSA 

while I was working , I wanted to configure my web-sphere server , so I searched over to Server view "windows --> show view --> servers"

and they didn't show up !!


Wednesday, 30 October 2013

How to configure proxy settings in eclipse

Often times, Eclipse IDE may need access to the Internet for some plugins install and update. If your computer is behind a proxy server

then you need to handle the proxy of in the Eclipse to go throw the internet


What is GWT ? Why we want to use GWT ?

GWT :

Google Web Toolkit (GWT) is an open source Java software development framework that makes writing AJAX applications easy.

Sunday, 27 October 2013

Named Native Query Vs Native Query Vs HQL / JPQL

there are some missing up with understanding the difference between the Native Named Query and Native Query and HQL , and a lot of headache about the the performance issue in using them.

Tuesday, 22 October 2013

How can we make a Empty interface ?

we can make an empty interface that to call it and make that configuration to the Compiler to take care about how to deal with the class that implement that interface.


Monday, 21 October 2013

What is SQL Injection ? how to prevent my website from it?

What is SQL Injection

  • SQL Injection is a type of web application security vulnerability in which an attacker is able to submit a database SQL command which is executed by a web application, exposing the back-end database. 

Wednesday, 9 October 2013

Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules

I had this problem when I was adding my new server(Tomcat 6), While I was configured an old server (Tomcat 7) for the same project



Monday, 23 September 2013

Difference between Database and Data Source ?

A data source is simply something your program relies on to get data. A database is a kind of data source that persists data to some digitized form. Other data sources include files, services, etc — these all provide data to your programs.

which is better to Packaging EJB in JavaEE 6 WAR vs EAR ?



An important motivation for having EJB beans in a separate JAR is for the age old separation of business logic and view logic.
Since EJBs are supposed to concentrate solely on business logic, it makes sense to put them into a separate module.
This is exactly what the

What is the difference between EJB2 and EJB3?

EJB2 vs EJB3



EJB (Enterprise JavaBeans) is a Java API (Application Programming Interface) found within Java EE (Java Platform, Enterprise Edition) specification. EJB describes an architectural model for the development of enterprise applications. This is a managed server-side model that is able to capture the business logic of the enterprise application. IBM is EJB’s original creator who developed it in 1997. Sun Microsystems adopted it in 1999.

Before the introduction of EJB, it was found that solutions to problems found in back-end business code were frequently re-implemented by the programmers. As a result, EJB was introduced to address these common problems such as persistence, transactional integrity and security. EJB provides standard ways to handle these back end problems, by specifying how the application server should process transactions, integrate with JPA (Java Persistence API) services, handle concurrency control, handle JMS (Java Message Service) Events, resolve naming issues with JNDI (Java Naming and Directory Interface), develop secure programs with JCE (Java Cryptography Extension) and JAAS (Java Authentication and Authorization Service), deploy components, communicate remotely with RMI-IIOP (Java Remote Method Invocation interface over the Internet Inter-Orb Protocol), develop web services, invoke asynchronous methods and use the Timer service.

Monday, 26 August 2013

what MCV design patterns and entity bean ?

Introduction

MVC is a design pattern (a general design solution for problem solving) widely used in software design. 
MVC Stands for Model Controller View. 
MVC is achieved through 3 components: 
  • the model contains the data and provides methods for accessing them;
  • The view displays the data in the model;
  • the controller receives the commands(usually through the view) and implement them by changing the status of the other two components

This pattern ensures the division between business logic(managed by the model) and user interface (run by and view controller). 
Wanting to apply this pattern to the Java EE, you can use the following Java technologies applied to various components of the pattern. 
Model: This component can be implemented through the entity bean and session bean Controller: It can be implemented by the servlet. View: The latter through jsp and / or jsf. 
In general terms, entity objects encapsulate the business policy and data for
  • the logical structure of the business, such as product lines, departments, sales, and regions
  • business documents, such as invoices, change orders, and service requests
  • physical items, such as warehouses, employees, and equipment

The entity bean will be an abstraction and then to represent the data, the session bean can perform operations on the entity, the servlet will collect input from jsp (you) to make requests to the session bean and communicate results to jsp and so on. 


Related issue :


Java Web Services #Interview Questions and Answers ?

Q. What are the different application integration styles?

A. There are a number of different integration styles like

1. Shared database
2. batch file transfer
3. Invoking remote procedures (RPC)
4. Exchanging asynchronous messages over a message oriented middle-ware (MOM).

What is functional/declarative programming versus imperative programming?

Imperative Programming 

is what most professional programmers use in their day-to-day jobs.
It's the name given to languages like C, C++, Java, COBOL, etc. In imperative programming, you tell the computer what to do. "Computer, add x and y," or "Computer, slap a dialog box onto the screen." And (usually) the computer goes and does it. This is where most of us spend our lives, in looping structures and if-then-else statements and the like.

Functional Programming

it seeks to describe what you want done rather than specify how you want something done..
It's probably best understood in contrast to imperative programming. 

What is HTTP methods ? #web

  • Options Get information about how the server allows to communicate with.
  • GET Retrieve a resource.
  • POST Create a new resource.
  • PUT Send data to the server.
  • DELETE Delete an existing resource.
  • TRACE Return the request headers sent by the client.

Thursday, 22 August 2013

How To Check If Two Or More Rows Have The Same Field Value ?


you want to filter details from db.


The Problem :


I want to select the first row with the last name "usama" and then I want to skip the next row which has the same field "usama".

Sunday, 18 August 2013

Read file and convert it to Array list #java

here is an simple demo of how to read a file and insert it's data into array list separated by new lines.


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class FileArrayProvider {

    public String[] readLines(String filename) throws IOException {
        FileReader fileReader = new FileReader(filename);
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        List<String> lines = new ArrayList<String>();
        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            lines.add(line);
        }
        bufferedReader.close();
        return lines.toArray(new String[lines.size()]);
    }
}

Monday, 12 August 2013

how to start PHP / Mysql Connection

here is a simple connection between php and mysql. in 5 steps .


Step 1
create the db 

CREATE DATABASE `mydb`;
USE `mydb`;
CREATE TABLE `employee` (
   `id` int UNIQUE NOT NULL AUTO_INCREMENT,
   `first_name` varchar(40),
   `last_name` varchar(50),
   PRIMARY KEY(id)
);
INSERT INTO cars VALUES('usama','saad');
INSERT INTO cars VALUES('hasan','hamaky');
INSERT INTO cars VALUES('noor','sobhy');

Friday, 26 July 2013

Total Validation on JTextFiled inputs #java #swing 3 steps

I had found a simple and created an util class that can help in easy way to handle a lot of validations in JText files.

Only in 3 steps in easy way :


how to load Image with relative path and re-size it #java


I had faced it while i was trying to add some image to desktop Applications.

and found many ways by buffered image and loading images itself , here is an easy-way to handle it


Wednesday, 24 July 2013

How To insert and Retrieve image from DB #jdbc #java #MySQL

here is a few steps to insert and retrieve image files from DB.

1. Creating the Image column:


how to change the coffee cup in #Java Frames #GUI

it's weird when you install your program to customer and found that cup in your frames,

While handling this issue is very easy.


you just want to change the icon Image of your fame.

Sunday, 21 July 2013

Two ways to validate email address #regular expression #java

 validation on the email address will be handled using two ways below :


  • Regular expression 
  • apache-commons Email validator.( you need to download the Jar.)


Thursday, 18 July 2013

How to Make All .Jar and lip files in one JAR file . #net-Beans. #java

How to make my project in only one jar file using  net-beans?


In order to make the created JAR include the lips jar.
All what you need is to add below data in Build.xml of your project :


How To convert .jar to .exe #java

How to change jar file and make it executable ".exe" file ?


that's a serious question and there are a lot of programs do it.

but I prefer that one and will make it ease to use it in few steps


How to make a jar file ? #java #net-beans #eclipse #batch file #Windows

In this post, you will know how to create a jar file using net-beans , Eclipse and using ant scripts in easy and straightforward way.

Net-beans.

Step 1: you had to right click on the project 
Step 2: Click Clean and Build.
Step 3: check out the Jar that already created under the project folder (./dist)

PS. to change the entry man class. choose it and edit in MANIFEST.MF       
    Main-Class: package.MainClass

OR 

change the Build.xml  and add below tag.

<manifest file="MANIFEST.MF">
    <attribute name="Main-Class" value="package.MainClass" />
</manifest>


How to run .jar file by #double click #batch file #java

Well. I had faced this issue a lot while I was installing the product to my clients.
and I found just a simple way to handle it easy :)

Double  click into the jar file:


Step 1: Start Control panel
Step 2: Click Default Programs
Step 3: Click Associate a file type or protocol with a specific program
Step 4: Double click .jar
Step 5: Browse C:\Program Files\Java\jre7\bin\javaw.exe
Step 6: Click the button Open
Step 7: Click the button OK

OR
Step 1:  right-click  on the jar file
Step 2: Open With a Java Runtime listed ( C:\Program Files\Java\jre7\bin\javaw.exe)
Step 3: make it the default program to run with.



Wednesday, 17 July 2013

Observer design Pattern with Examples .#Java

Observer design pattern  is a fundamental core pattern where Observe watch for any change in state or property of Subject. 

For Example Company updates all its shareHolder for any decision .

they make here Company is Subject and Shareholders are Observers, 
any change in policy of company , the company will notifies all its Shareholders (observers).



What is Observer design Pattern?


Observer design pattern is very important pattern and as name suggest it’s used to observe things. Suppose you want to notify for change in a particular object than you observer that object and changes are notified to you. Object which is being observed is refereed as Subject and classes which observe subject are called Observer

This pattern is used heavily along with Model View Controller Design pattern where change in model is propagated to view so that it can render it with modified information.


Saturday, 13 July 2013

Difference between Enumeration and Iterator ? #java #interview

both Iterator and Enumeration provides way to traverse or navigate through entire collection in java

Enumeration is older and its there from JDK1.0 while iterator was introduced later. 
Iterator can be used with Java arraylist,  java hashmap keyset  and with any other collection classes.


As far Enumeration is older than Iterator so that  functionality of Enumeration interface is duplicated by the Iterator interface.

Only major difference is Iterator has a remove() method while Enumeration doesn't. Enumeration acts as Read-only interface, because it has the methods only to traverse and fetch the objects, where as by using Iterator we can manipulate the objects like adding and removing the objects from collection e.g. Arraylist.


Friday, 12 July 2013

Difference between Set, List and Map in #Java #interview

Set (Interface)

  • Set is an un-ordered collection which doesn’t allows duplicate (no-duplicate) elements
  • We can iterate the values by calling iterator() method

Set s = new HashSet();
Iterator iter = s.iterator();

List (Interface)

  • List is an ordered collection which allows duplicate elements
  • We can iterate the values by calling iterator() method

List li = new ArrayList();
Iterator iter = li.iterator();


Map (Interface)

  • In Map we used to store the data in key and value pairs, we may have duplicate values but no duplicate keys
  • In Map we don’t have iterator() method, but we can get the keys by calling the method keySet()

Map m; // insert values
Set s = m.keySet();
// Get Map keys into the Set and then iterate this Set object normally
// m.keySet() returns Set object with Map keys
Iterator iter = s.iterator();

 When to use List, Set and Map in Java


  1. If you need to access elements frequently by using index, than List is a way to go. Its implementation e.g. ArrayList provides faster access if you know index.
  2. If you want to store elements and want them to maintain an order on which they are inserted into collection then go for List again, as List is an ordered collection and maintain insertion order.
  3. If you want to create collection of unique elements and don't want any duplicate than choose any Set implementation e.g.HashSet, LinkedHashSet or TreeSet. All Set implementation follow there general contract e.g. uniqueness but also add addition feature e.g. TreeSet is a SortedSet and elements stored on TreeSet can be sorted by using Comparator or Comparable in Java. LinkedHashSet also maintains insertion order.
  4. If you store data in form of key and value than Map is the way to go. You can choose from Hashtable, HashMap, TreeMap based upon your subsequent need. In order to choose between first two see difference between HashSet and HashMap in Java.

References

  •  http://java67.blogspot.com/2013/01/difference-between-set-list-and-map-in-java.html
  •  http://www.java4s.com/core-java/difference-between-java-set-list-and-map-collections/

Thursday, 11 July 2013

Principles of Object-Oriented Programming #JAVA EXAPLES


it's briefly explain the 4 major principles that make a language object-oriented:
EncapsulationData AbstractionPolymorphism and Inheritence.
Encapsulation

Encapsulation hides the details of that implementation. An accessor is a method that is used to ask an object about itself. In OOP, these are usually in the form of properties, which have, under normal conditions, a get method, which is an accessor method. However, accessor methods are not restricted to properties and can be

any public method that gives information about the state of the object.

while hiding the implementation of exactly how the data gets modified. Mutilators are commonly another portion of the property discussed above, except this time its the set method that lets the caller modify the member data behind the scenes.
class Loan{
    private 
int duration;  //private variables examples of encapsulation
    private String loan
;
    private String borrower
;
    private String salary
;
   
    //public constructor can break encapsulation instead use factory method
    private Loan
(int duration, String loan, String borrower, String salary){
        this.
duration = duration;
        this.
loan = loan;
        this.
borrower = borrower;
        this.
salary = salary;
    
}
   
    //no argument consustructor omitted here
    
   // create loan can encapsulate loan creation logic
    public Loan createLoan(String loanType){
  
     //processing based on loan type and than returning loan object
      return loan;
    }
   
}

Why Encapsulation:
1. Encapsulated Code is more flexible and easy to change with new requirements.
2. Encapsulation in Java makes unit testing easy.
3. Encapsulation in Java allows you to control who can access what.
4. Encapsulation also helps to write immutable class in Java which are a good choice in multi-threading environment.
5. Encapsulation reduce coupling of modules and increase cohesion inside a module because all piece of one thing are encapsulated in one place.
6. Encapsulation allows you to change one part of code without affecting other part of code.

Abstraction
      Data abstraction and encapsulation are closely tied together, because a simple definition of data abstraction is the development of classes, objects, types in terms of their interfaces and functionality, instead of their implementation details. Abstraction denotes a model, a view, or some other focused representation for an actual item. 
      Its the development of a software object to represent an object we can find in the real world. Encapsulation hides the details of that implementation.
Why Abstraction:
1) Use abstraction if you know something needs to be in class but implementation of that varies.
2) In Java you cannot create instance of abstract class , its compiler error.
3) Abstract is a keyword in java.
4) a class automatically becomes abstract class when any of its method declared as abstract.
5) Abstract method doesn't have method body.
6) Variable cannot be made abstract, its only behavior or methods which would be abstract.
7) If a class extends an abstract class or interface it has to provide implementation to all its abstract method to be a concrete class. Alternatively this class can also be abstract.

Inheritance
      Objects can relate to each other with either a “has a”, “uses a” or an “is a” relationship.  “Is a” is the inheritance way of object relationship.  
        So, take a library, for example.  A library lends more than just books, it also lends magazines, audio-cassettes and microfilm.  On some level, all of these items can be treated the same: All four types represent assets of the library that can be loaned out to people. 
However, even though the 4 types can be viewed as the same, they are not identical.  A book has an ISBN and a magazine does not.  And audio-cassette has a play length and microfilm cannot be checked out overnight.Each of these library’s assets should be represented by its own class definition. 
Without inheritance though, each class must independently implement the characteristics that are common to all loanable assets.
Example will mentioned with Polymorphism Example.
Polymorphism
Polymorphism means  one namemany forms.  
also is the ability to create a variable, a function, or an object that has more than one form. In principle, polymorphism can arise in other computing contexts and shares important similarities with the concept of degeneracy in biology.
There are 2 basic types of polymorphism.  
  • Overridding, also called run-time polymorphism, 
  • Overloading, which is referred to as compile-time polymorphism.  
Method overloading means writing two are or more methods in the same class by using same method name, but passing the parameters is different.

Method overriding means we use the method names in the different classes,that means parent class method is used in the child class.


Example: 
public abstract class Human
{
   public abstract void printGender();
}

public class Male extends Human
{
    @Override
    public void printGender()
    {
        System.out.println("man");
    }
}

public class Female extends Human
{
    @Override
    public void printGender()
    {
        System.out.println("women");
    }
}

public class boy extends male
{
    @Override
    public void printGender()
    {
        System.out.println("teanager");
    }
    public void printGender(String name)
    {
        System.out.println(name +"teenager");
    }

}
  • Male is Inherit Human. 
  • Boy .printGender() method is override the method printGender in Man Class.
  • printGender(name)/printGender() is overloaded.

References:
  • http://stackoverflow.com/questions/154577/polymorphism-vs-overriding-vs-overloading
  • http://codebetter.com/raymondlewallen/2005/07/19/4-major-principles-of-object-oriented-programming/
  • http://javarevisited.blogspot.com/2012/03/what-is-encapsulation-in-java-and-oops.html
  • http://javarevisited.blogspot.com/2010/10/abstraction-in-java.html