শনিবার, ২৩ জুলাই, ২০১১

Basic Math

Divisibility Rules


Dividing by 3
    Add up the digits: if the sum is divisible by three, then the number is as well. Examples:
    1. 111111: the digits add to 6 so the whole number is divisible by three.
    2. 87687687. The digits add up to 57, and 5 plus seven is 12, so the original number is divisible by three.

Dividing by 4

    Look at the last two digits. If the number formed by its last two digits is divisible by 4, the original number is as well.
    Examples:
    1. 100 is divisible by 4.
    2. 1732782989264864826421834612 is divisible by four also, because 12 is divisible by four.

Dividing by 5

    If the last digit is a five or a zero, then the number is divisible by 5.

Dividing by 6

    Check 3 and 2. If the number is divisible by both 3 and 2, it is divisible by 6 as well.

Dividing by 7

    To find out if a number is divisible by seven, take the last digit, double it, and subtract it from the rest of the number.
    Example: If you had 203, you would double the last digit to get six, and subtract that from 20 to get 14. If you get an answer divisible by 7 (including zero), then the original number is divisible by seven. If you don't know the new number's divisibility, you can apply the rule again.

Dividing by 8
    Check the last three digits. Since 1000 is divisible by 8, if the last three digits of a number are divisible by 8, then so is the whole number.
    Example: 33333888 is divisible by 8; 33333886 isn't.

Dividing by 9

    Add the digits. If that sum is divisible by nine, then the original number is as well.

Dividing by 10

    If the number ends in 0, it is divisible by 10.

Dividing by 11

    Let's look at 352, which is divisible by 11; the answer is 32. 3+2 is 5; another way to say this is that 35 -2 is 33.

    Now look at 3531, which is also divisible by 11. It is not a coincidence that 353-1 is 352 and 11 × 321 is 3531.

Dividing by 12

    Check for divisibility by 3 and 4.

Dividing by 13

Dividing by 14

মঙ্গলবার, ১৯ জুলাই, ২০১১

Restfull in grails

Restfull for Grails :

grails create-app RestFullTest
cd RestFullTest

grails create-domain-class book

grails create-controller Book



You can add some code this /grails-app/conf/BootStrap.groovy file:
def init = { servletContext ->
new Book(author:"S.M. Mahmudul Hasan",title:"Grails").save()
new Book(author:"Shohan",title:"Restfull").save()
}

or U can insert value in db
or U can insert by programatically
Final project structure will be:




















RESTful server
We need to create controller that will be performing base CRUD operations and map its methods to REST style URLs.

Edit /grails-app/conf/UrlMappings.groovy:
class UrlMappings {

static mappings = {
"/$controller/$action?/$id?" {
constraints {
// apply constraints here
}
}

"/"(view: "/index")
"500"(view: '/error')
"/book"(controller: "book") {
action = [GET: "list", POST: "create"]
}
"/book/$id"(resource: "book")
}

Entry with /book maps GET and POST HTTP requests to this URL to list and create controller methods. Below we map URLs like /book/$id using default grails REST mapping:
  • GET -> show
  • PUT -> update
  • POST -> save (used when you know ID of item you create - not our case;)
  • DELETE -> delete
Implementation of our controller will use GORM for data storage and will communicate with client application using JSON format. Edit /grails-app/controllers/BookController.groovy:

import grails.converters.*

class BookController {
def list = {
response.setHeader("Cache-Control", "no-store")
render Book.list(params) as JSON
}

def show = {
Book b=Book.get(params.id)
render b as JSON
}

def create = {
def json = JSON.parse(request);
def b = new Book(json)
b.save()
response.status = 201
response.setHeader('Location', '/book/'+b.id)
render b as JSON
}

def delete = {
Book b=Book.get(params.id)
b.delete()
render(status: 200)
}
}

Run this code with grails run-app and point your browser to http://localhost:8080/GrailsRestTest/book. You should get following response:
[{"class":"Book","id":1,"author":"S.M. Mahmudul Hasan","title":"Grails"},{"class":"Book","id":2,"author":"Shohan","title":"Restfull"}]
To get particular item try http://localhost:8080/GrailsRestTest/book/1 - response should be:
{"class":"Book","id":1,"author":"S.M. Mahmudul Hasan","title":"Grails"}

সোমবার, ১৮ জুলাই, ২০১১

রবিবার, ১৭ জুলাই, ২০১১

About JSF

basic link

বৃহস্পতিবার, ১৪ জুলাই, ২০১১

About basic Java

What Is Java

Java is a computer programming language created by Sun Microsystems.

The Java programming language is a high-level language that can be characterized by all of the following buzzwords:

  • Simple

  • Architecture neutral

  • bject oriented

  • Portable

  • istributed

  • High performance

  • Multithreaded

  • Robust

  • Dynamic

  • Secure

Why Java is so popular

1. It is free unlike the other rivals.

2. Platform independence (Write Once Run Anywhere).

3. Automatic Garbage collection (Memory management)


Java Object: Object is a real time entity and it has state and behavior.

Java Class: Java class is a blue print of java object.

Abstract class: Abstract classes are super classes which contain abstract methods and are defined such that concrete subclasses are to extend them by implementing the methods.

Concrete class: A concrete class, however, is a class for which entities (instances) may be created. This contrasts with abstract classes which can not be instantiated because it defeats its purpose of being an 'abstract'.


Identifiers:

1. Identifiers must start with a letter, a currency character ($), or a connecting
character such as the underscore ( _ ). Identifiers cannot start with a number!
2. After the first character, identifiers can contain any combination of letters,
currency characters, connecting characters, or numbers.
3. In practice, there is no limit to the number of characters an identifier can
contain.
4. You can't use a Java keyword as an identifier. Table 1-1 lists all of the Java
keywords including one new one for 5.0, enum.
5. Identifiers in Java are case-sensitive; name and NAME are two different identifiers.


JavaBeans: JavaBeans are Java classes that have properties with setter and getter.


JavaBean Property Naming Rules:

1. If the property is not a boolean, the getter method's prefix must be get. getSize()

2. If the property is a boolean, the getter method's prefix is either get or is .getStopped() or isStopped()

3. The setter method's prefix must be set. setSize()

4. Setter method signatures must be marked public, with a void return type
and an argument that represents the property type.

5. Getter method signatures must be marked public, take no arguments, and
have a return type.

Source File Declaration Rules


1. There can be only one public class per source code file.
2. Comments can appear at the beginning or end of any line in the source code
file.
3. If there is a public class in a file, the name of the file must match the name
of the public class. For example, a class declared as public class Dog { }
must be in a source code file named Dog.java.
4. If the class is part of a package, the package statement must be the first line
in the source code file, before any import statements that may be present.
If there are import statements, they must go between the package statement
(if there is one) and the class declaration. If there isn't a package statement,
then the import statement(s) must be the first line(s) in the source code file.
If there are no package or import statements, the class declaration must be
the first line in the source code file.
5. import and package statements apply to all classes within a source code file.
In other words, there's no way to declare multiple classes in a file and have
them in different packages, or use different imports.
6. A file can have more than one nonpublic class.
7. Files with no public classes can have a name that does not match any of the
classes in the file.


Modifiers fall into two categories:
1. Access modifiers: public, protected, private.
2. Non-access modifiers (including strictfp, final, and abstract).

strictfp :

strictfp is a keyword and can be used to modify a class or a method, but never a
variable. Marking a class as strictfp means that any method code in the class will
conform to the IEEE 754 standard rules for floating points. Without that modifier,
floating points used in the methods might behave in a platform-dependent way.



Online Groovy Console

This is very nice console for groovy code compiling. link