How to install and compiling a source code with JDK

This tutorial will show you how to compile a source code with Java Development Kit in the most simply way.

Dropbox configuration

When was the last time you have a virtual drive that can store your file and you can view it on different computer without copying it?

Meet Processing

An open project initiated by Ben Fry and Casey Reas from MIT.

A simple way to work Java, introducing BlueJ

BlueJ, just as simply as its name.

Data Types

Bring you explanations of all Data Types in Computer Programming.

Kamis, 08 Januari 2015

Flow control in Programming


Flow control explanation
Good morning, in this post, i'm going to resume an explanation about flow control in programming.

In computer science, control flow (or alternatively, flow of control) refers to the order in which the individual statements, instructions or function calls of an imperative or a declarative program are executed or evaluated.

Within an imperative programming language, a control flow statement is a statement whose execution results in a choice being made as to which of two or more paths should be followed. For non-strict functional languages, functions and language constructs exist to achieve the same result, but they are not necessarily called control flow statements.

The kinds of control flow statements supported by different languages vary, but can be categorized by their effect:

  • continuation at a different statement (unconditional branch or jump),
  • executing a set of statements only if some condition is met (choice - i.e., conditional branch),
  • executing a set of statements zero or more times, until some condition is met (i.e., loop - the same as conditional branch),
  • executing a set of distant statements, after which the flow of control usually returns (subroutines, coroutines, and continuations),
  • stopping the program, preventing any further execution (unconditional halt).


A set of statements is in turn generally structured as a block, which in addition to grouping also defines a lexical scope.

Interrupts and signals are low-level mechanisms that can alter the flow of control in a way similar to a subroutine, but usually occur as a response to some external stimulus or event (that can occur asynchronously), rather than execution of an 'in-line' control flow statement.

At the level of machine or assembly language, control flow instructions usually work by altering the program counter. For some CPUs the only control flow instructions available are conditional or unconditional branch instructions (also called jumps).


Labels
A label is an explicit name or number assigned to a fixed position within the source code, and which may be referenced by control flow statements appearing elsewhere in the source code. Other than marking a position within the source code a label has no effect.

Line numbers are an alternative to a named label (and used in some languages such as Fortran and BASIC), that are whole numbers placed at the beginning of each line of text within the source code. Languages which use these often impose the constraint that the line numbers must increase in value in each subsequent line, but may not require that they be consecutive. For example, in BASIC:
10 LET X = 3
20 PRINT X

In other languages such as C and Ada a label is an identifier, usually appearing at the beginning of a line and immediately followed by a colon. For example, in C:
Success: printf("The operation was successful.\n");

The Algol 60 language allowed both whole numbers and identifiers as labels (both attached by colons to the following statement), but few if any other variants of Algol allowed whole numbers.


Goto
The goto statement (a combination of the English words go and to, and pronounced accordingly) is the most basic form of unconditional transfer of control.

Although the keyword may either be in upper or lower case depending on the language, it is usually written as:
   goto label

The effect of a goto statement is to cause the next statement to be executed to be the statement appearing at (or immediately after) the indicated label.

Goto statements have been considered harmful by many computer scientists, notably Dijkstra.


Subroutines
The terminology for subroutines varies; they may alternatively be known as routines, procedures, functions (especially if they return results) or methods (especially if they belong to classes or type classes).

In the 1950s, computer memories were very small by current standards so subroutines were used primarily to reduce program size; a piece of code was written once and then used many times from various other places in the program.

Nowadays, subroutines are more frequently used to help make a program that is more structured, e.g. by isolating some particular algorithm or hiding some particular data access method. If many programmers are working on a single program, subroutines are one kind of modularity that can help split up the work.

Minimal structured control flow
In May 1966, Böhm and Jacopini published an article in Communications of the ACM which showed that any program with gotos could be transformed into a goto-free form involving only choice (IF THEN ELSE) and loops (WHILE condition DO xxx), possibly with duplicated code and/or the addition of Boolean variables (true/false flags). Later authors have shown that choice can be replaced by loops (and yet more Boolean variables).

The fact that such minimalism is possible does not necessarily mean that it is desirable; after all, computers theoretically only need one machine instruction (subtract one number from another and branch if the result is negative), but practical computers have dozens or even hundreds of machine instructions.

What Böhm and Jacopini's article showed was that all programs could be goto-free. Other research showed that control structures with one entry and one exit were much easier to understand than any other form, primarily because they could be used anywhere as a statement without disrupting the control flow. In other words, they were composable. (Later developments, such as non-strict programming languages - and more recently, composable software transactions - have continued this line of thought, making components of programs even more freely composable.)

Some academics took a purist approach to the Böhm-Jacopini result and argued that even instructions like break and return from the middle of loops are bad practice as they are not needed in the Böhm-Jacopini proof, and thus they advocated that all loops should have a single exit point. This purist approach is embodied in the Pascal programming language (designed in 1968–1969), which up to the mid-1990s was the preferred tool for teaching introductory programming in academia. The direct application of the Böhm-Jacopini theorem may result in additional local variables being introduced in the structured chart, and may also result in some code duplication. The latter issue is called the loop and a half problem in this context. Pascal is affected by both of these problems and according to empirical studies cited by Eric S. Roberts, student programmers had difficulty formulating correct solutions in Pascal for several simple problems, including writing a function for searching an element in an array. A 1980 study by Henry Shapiro cited by Roberts found that using only the Pascal-provided control structures, the correct solution was given by only 20% of the subjects, while no subject wrote incorrect code for this problem if allowed to write a return from the middle of a loop.

If-then-(else) statements
Conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false.


  • IF..GOTO. A form found in unstructured languages, mimicking a typical machine code instruction, would jump to (GOTO) a label or line number when the condition was met.
  • IF..THEN..(ENDIF). Rather than being restricted to a jump, any simple statement, or nested block, could follow the THEN key keyword. This a structured form.
  • IF..THEN..ELSE..(ENDIF). As above, but with a second action to be performed if the condition is false. This is one of the most common forms, with many variations. Some require a terminal ENDIF, others do not. C and related languages do not require a terminal keyword, or a 'then', but do require parentheses around the condition.

Conditional statements can be and often are nested inside other conditional statements. Some languages allow ELSE and IF to be combined into ELSEIF, avoiding the need to have a series of ENDIF or other final statements at the end of a compound statement.

Loops
A loop is a sequence of statements which is specified once but which may be carried out several times in succession. The code "inside" the loop (the body of the loop, shown below as xxx) is obeyed a specified number of times, or once for each of a collection of items, or until some condition is met, or indefinitely.

In functional programming languages, such as Haskell and Scheme, loops can be expressed by using recursion or fixed point iteration rather than explicit looping constructs. Tail recursion is a special case of recursion which can be easily transformed to iteration.

Count-controlled loops
Most programming languages have constructions for repeating a loop a certain number of times. Note that if N is less than 1 in these examples then the language may specify that the body is skipped completely, or that the body is executed just once with N = 1. In most cases counting can go downwards instead of upwards and step sizes other than 1 can be used.

Infinite loops
Infinite loops are used to assure a program segment loops forever or until an exceptional condition arises, such as an error. For instance, an event-driven program (such as a server) should loop forever, handling events as they occur, only stopping when the process is terminated by an operator.

Often, an infinite loop is unintentionally created by a programming error in a condition-controlled loop, wherein the loop condition uses variables that never change within the loop.

Input/Output in Java

Java Input/Output

Hello(again) :D

After we understand about Basic Input/Output, now i'm going to post about Input/Output in Java Programming.

The Java platform is an isolated entity, a space on your OS in a way, where everything outside this system is its environment. The interaction between the system and its environment is a two-way dialog of sorts. Either the system receives messages from its environment, or it conveys its messages to the same. When a message is received to the system, it is called an input, its opposite is an output. On a whole, this communication is termed input/output abbreviated as I/O.

The following chapters are designed to introduce basic input and output in Java, including reading text input from the keyboard, outputting text to the monitor, and reading/writing files from the file system. More advanced user interaction using Graphics and Graphical User Interface (GUI) programs is taken up in the later section on Swing.

Simple Java Output: Writing to the Screen :
Writing to the screen is very easy, and can be accomplished using this method :

Print "Hello world" :

System.out.print("Hello world");

On the screen it will look like this :












Simple Java Input: Inputting from the keyboard
As of version 1.5.0, Java provides a class in the java.util package called Scanner that simplifies keyboard input.

Inputting with Scanner :

Scanner kbdIn = new Scanner(System.in); // Instantiating a new Scanner object
System.out.print("Enter your name: "); // Printing out the prompt
String name = kbdIn.nextLine(); // Reading a line of input (until the user hits enter) from the keyboard
// and putting it in a String variable called name
System.out.println("Welcome, " + name); // Printing out welcome, followed by the user's name.

On the scree it will look like this :












Just like that, it is some simple input/output in Java Programming. Hope it help you.

Basic Input/Output


Basic of Input/Output
In computing, input/output or I/O (or informally, io or IO) is the communication between an information processing system (such as a computer) and the outside world, possibly a human or another information processing system. Inputs are the signals or data received by the system and outputs are the signals or data sent from it. The term can also be used as part of an action; to "perform I/O" is to perform an input or output operation. I/O devices are used by a human (or other system) to communicate with a computer. For instance, a keyboard or mouse is an input device for a computer, while monitors and printers are output devices. Devices for communication between computers, such as modems and network cards, typically perform both input and output operations.

Note that the designation of a device as either input or output depends on perspective. Mice and keyboards take physical movements that the human user outputs and convert them into input signals that a computer can understand; the output from these devices is the computer's input. Similarly, printers and monitors take signals that a computer outputs as input, and they convert these signals into a representation that human users can understand. From the human user's perspective, the process of reading or seeing these representations is receiving input; this type of interaction between computers and humans is studied in the field of human–computer interaction.

In computer architecture, the combination of the CPU and main memory, to which the CPU can read or write directly using individual instructions, is considered the brain of a computer. Any transfer of information to or from the CPU/memory combo, for example by reading data from a disk drive, is considered I/O. The CPU and its supporting circuitry may provide memory-mapped I/O that is used in low-level computer programming, such as in the implementation of device drivers, or may provide access to I/O channels. An I/O algorithm is one designed to exploit locality and perform efficiently when exchanging data with a secondary storage device, such as a disk drive.

Higher-level operating system and programming facilities employ separate, more abstract I/O concepts and primitives. For example, most operating systems provide application programs with the concept of files. The C and C++ programming languages, and operating systems in the Unix family, traditionally abstract files and devices as streams, which can be read or written, or sometimes both. The C standard library provides functions for manipulating streams for input and output.

In the context of the ALGOL 68 programming language, the input and output facilities are collectively referred to as transput. The ALGOL 68 transput library recognizes the following standard files/devices: stand in, stand out, stand errors and stand back.

An alternative to special primitive functions is the I/O monad, which permits programs to just describe I/O, and the actions are carried out outside the program. This is notable because the I/O functions would introduce side-effects to any programming language, but this allows purely functional programming to be practical.

So now how are these all related to input/output? The answer is, the input/output is the main aspect of the computer science. It defines the whole system. It is related to system theory of Bertalanffy. Every system in the world is an open system. An open system always has input and output. No system can live if it won't adhere to this rule; it will be destroyed. In contrast, a closed system can live without an input or output. It is a self sufficient system. No closed system has ever been discovered.

I recommend the lecture of Bertalanffy to gain further knowledge on this. So a computer is an open system that needs an input and makes an output. Input and output is not only related to personal computers but also other devices. About this I recommend a lecture on the theory of communication, especially Claude Shannon and Norbert Wiener.

Input and output is abbreviated I/O. There are many levels of input on today's personal computers. To first understand I/O I will talk about the computer input and output. So here is the plan of our study:

  • Machine level I/O
  • Coding level I/O
  • And finally End user level I/O

As you may see here all of these levels need special expertise. The further you go here, the more you will get special knowledge on the level you chose. And any level you choose here, the expertise is infinite, and you will arrive finally to the end of this knowledge where you can contribute to today's science.

Input/Output on the Coding Level
On the coding level we can analyze the input and the output by the use of algorithms. On the coding level not all input produces output. There are five categories of inputted data:

  • Remarks. No action and no calculation by the computer is done here.
  • Declarations. These inputs are preliminary to a calculation. You say here to the computer "Get ready!"
  • Conditions. The computer is confronted with a choice. This is post-preliminary input.
  • Variables. The computer inializes a variable with a value of null and can receive additional values subsequently.
  • Calculations. Here the computer is confronted with a calculation. The computer got into this level as the result of declarations, choices, and variables with values. Now it is using these to prepare the output.

Output passes through several stages on the way from its origin as electric signals to human-readable data:

  • Electric signals. All calculations produce a result coded in electronic signals. These signals may be passed to RAM as input.
  • Zeros and ones. Electric signals readily transfer to values of 0 or 1 stored as bits: a signal means 1, a gap without signals means 0.
  • Binary numbers. Binary digits can be combined into eight- or sixteen-bit binary numbers, like 00000000, 11111111, or 10101000.
  • Machine language. These binary numbers can be interpreted as instructions to be executed by the CPU.
  • Coder language. Through a compiler, machine code and its corresponding assembly language correlates to a language such as programmers write in.


Input/Output on End-User Level
From an end-user point of view, the initial electric signals may turn into a letter on the screen, motion of a robot arm, a laser shot, or a car engine start. One should consider here that we use disguised computers in our cellular phones, televisions, robots, toys, trains, airplanes, warheads, and missiles.

  • For example, a kitchen robot with knives to cut and extract juice from fruit receives the fruit as its input and produces the juice as its output.
  • In a personal computer, the input may be the age of school-children and the output their average age as displayed on the screen or directed to a printer or file.
  • The input for an iron cutting machine could be the iron cutting style designed and recorded in the memory of the machine, and the output could be the laser movement so as to cut iron according to the project.


An infinite number of examples of inputs exists. Inputs can be grouped as follows:

  • numeric or alphanumeric input as record (e.g., names, birthrates, ages, census data) (See the previous lesson about record strings and arrays).)
  • graphic analog input (e.g., GIF, BMP, JPEG)
  • graphic numeric input (e.g., drawing programs, cameras)
  • mechanical input (non-electric computers, such as the paper-with-holes input for the textile machine.
  • biochemical input (e.g., the pill that is taken)

With outputs there is also an infinite number of possibilities. For example:

  • numeric or alphanumeric output (e.g., display of children's names on computer screen)
  • graphic analog output (e.g., JPEG picture)
  • graphic numeric output (e.g., CAD screen output of museum plan)
  • mechanical output (e.g., flower picture drawn on iron plate)
  • mind output (e.g., collaborative work)
  • biochemical output (e.g., pill-induced hormone control, destruction of AIDS virus by microscopic AI robots)

Rabu, 07 Januari 2015

Other Data Types (Pointer)


Pointer Explanation
What is your first thought when hear "pointer"? You must be thinking about a small arrow which always moving around when you move your mouse, isn't it? :D

No no, what i mean about "pointer" here is, in computer science, a pointer is a programming language object, whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address. For high-level programming languages, pointers effectively take the place of general purpose registers in low-level languages such as assembly language or machine code, but may be in available memory. A pointer references a location in memory, and obtaining the value stored at that location is known as dereferencing the pointer. A pointer is a simple, more concrete implementation of the more abstract reference data type. Several languages support some type of pointer, although some have more restrictions on their use than others. As an analogy, a page number in a book's index could be considered a pointer to the corresponding page; dereferencing such a pointer would be done by flipping to the page with the given page number.

Pointers to data significantly improve performance for repetitive operations such as traversing strings, lookup tables, control tables and tree structures. In particular, it is often much cheaper in time and space to copy and dereference pointers than it is to copy and access the data to which the pointers point.

Pointers are also used to hold the addresses of entry points for called subroutines in procedural programming and for run-time linking to dynamic link libraries (DLLs). In object-oriented programming, pointers to functions are used for binding methods, often using what are called virtual method tables.

While "pointer" has been used to refer to references in general, it more properly applies to data structures whose interface explicitly allows the pointer to be manipulated (arithmetically via pointer arithmetic) as a memory address, as opposed to a magic cookie or capability where this is not possible. Because pointers allow both protected and unprotected access to memory addresses, there are risks associated with using them particularly in the latter case. Primitive pointers are often stored in a format similar to an integer; however, attempting to dereference or "look up" a pointer whose value was never a valid memory address would cause a program to crash. To alleviate this potential problem, as a matter of type safety, pointers are considered a separate type parameterized by the type of data they point to, even if the underlying representation is an integer. Other measures may also be taken (such as validation & bounds checking, to verify the contents of the pointer variable contain a value that is both a valid memory address and within the numerical range that the processor is capable of addressing).

Formal Description
A pointer is a kind of reference.
A data primitive (or just primitive) is any datum that can be read from or written to computer memory using one memory access (for instance, both a byte and a word are primitives).
A data aggregate (or just aggregate) is a group of primitives that are logically contiguous in memory and that are viewed collectively as one datum (for instance, an aggregate could be 3 logically contiguous bytes, the values of which represent the 3 coordinates of a point in space). When an aggregate is entirely composed of the same type of primitive, the aggregate may be called an array; in a sense, a multi-byte word primitive is an array of bytes, and some programs use words in this way.
In the context of these definitions, a byte is the smallest primitive; each memory address specifies a different byte. The memory address of the initial byte of a datum is considered the memory address (or base memory address) of the entire datum.

A memory pointer (or just pointer) is a primitive, the value of which is intended to be used as a memory address; it is said that a pointer points to a memory address. It is also said that a pointer points to a datum when the pointer's value is the datum's memory address.

More generally, a pointer is a kind of reference, and it is said that a pointer references a datum stored somewhere in memory; to obtain that datum is to dereference the pointer. The feature that separates pointers from other kinds of reference is that a pointer's value is meant to be interpreted as a memory address, which is a rather low-level concept.

References serve as a level of indirection: A pointer's value determines which memory address (that is, which datum) is to be used in a calculation. Because indirection is a fundamental aspect of algorithms, pointers are often expressed as a fundamental data type in programming languages; in statically (or strongly) typed programming languages, the type of a pointer determines the type of the datum to which the pointer points.

Uses
Pointers are directly supported without restrictions in languages such as PL/I, C, C++, Pascal, and most assembly languages. They are primarily used for constructing references, which in turn are fundamental to constructing nearly all data structures, as well as in passing data between different parts of a program.

In functional programming languages that rely heavily on lists, pointers and references are managed abstractly by the language using internal constructs like cons.

When dealing with arrays, the critical lookup operation typically involves a stage called address calculation which involves constructing a pointer to the desired data element in the array. If the data elements in the array have lengths that are divisible by powers of two, this arithmetic is usually a bit more efficient. Padding is frequently used as a mechanism for ensuring this is the case, despite the increased memory requirement. In other data structures, such as linked lists, pointers are used as references to explicitly tie one piece of the structure to another.

Pointers are used to pass parameters by reference. This is useful if the programmer wants a function's modifications to a parameter to be visible to the function's caller. This is also useful for returning multiple values from a function.

Pointers can also be used to allocate and deallocate dynamic variables and arrays in memory. Since a variable will often become redundant after it has served its purpose, it is a waste of memory to keep it, and therefore it is good practice to deallocate it (using the original pointer reference) when it is no longer needed. Failure to do so may result in a memory leak (where available free memory gradually, or in severe cases rapidly, diminishes because of an accumulation of numerous redundant memory blocks).

Function Pointer
In some languages, a pointer can reference executable code, i.e., it can point to a function, method, or procedure. A function pointer will store the address of a function to be invoked. While this facility can be used to call functions dynamically, it is often a favorite technique of virus and other malicious software writers.


int  a, b, x, y;
int  sum(int n1, int n2);   // Function with two integer parameters returning an integer value
int  (*fp)(int, int);           // Function pointer which can point to a function like sum

fp = ∑                    // fp now points to function sum
x = (*fp)(a, b);              // Calls function sum with arguments a and b
y = sum(a, b);               // Calls function sum with arguments a and b


Pointers in Java
Unlike C, C++, or Pascal, there is no explicit representation of pointers in Java. Instead, more complex data structures like objects and arrays are implemented using references. The language does not provide any explicit pointer manipulation operators. It is still possible for code to attempt to dereference a null reference (null pointer), however, which results in a run-time exception being thrown. The space occupied by unreferenced memory objects is recovered automatically by garbage collection at run-time.

Numeric Data Types (Integer)



Good morning :D

Like i said in the previous article, i will post explanation of every Data Types and this time is about Numeric Data Types (Integer).

Numeric Data Types are consist of such as the integer data types, the floating point, fixed point, bignum or abitory position.

Numeric Types (Integer) Explanation
Integer, you sure have known what an integer is, in computer science, an integer is a datum of integral data type, a data type which represents some finite subset of the mathematical integers. Integral data types may be of different sizes and may or may not be allowed to contain negative values. Integers are commonly represented in a computer as a group of binary digits. The size of the grouping varies so the set of integer sizes available varies between different types of computers. Computer hardware, including virtual machines, nearly always provide a way to represent a processor register or memory address as an integer.

The value of an item with an integral type is the mathematical integer that it corresponds to. Integral types may be unsigned (capable of representing only non-negative integers) or signed (capable of representing negative integers as well).

An integer value is typically specified in the source code of a program as a sequence of digits optionally prefixed with + or −. Some programming languages allow other notations, such as hexadecimal (base 16) or octal (base 8). Some programming languages also permit digit group separators.

The internal representation of this datum is the way the value is stored in the computer's memory. Unlike mathematical integers, a typical datum in a computer has some minimal and maximum possible value.

The most common representation of a positive integer is a string of bits, using the binary numeral system. The order of the memory bytes storing the bits varies; see endianness. The width or precision of an integral type is the number of bits in its representation. An integral type with n bits can encode 2n numbers; for example an unsigned type typically represents the non-negative values 0 through 2n−1. Other encodings of integer values to bit patterns are sometimes used, for example Binary-coded decimal or Gray code, or as printed character codes such as ASCII.

There are four well-known ways to represent signed numbers in a binary computing system. The most common is two's complement, which allows a signed integral type with n bits to represent numbers from −2(n−1) through 2(n−1)−1. Two's complement arithmetic is convenient because there is a perfect one-to-one correspondence between representations and values (in particular, no separate +0 and −0), and because addition, subtraction and multiplication do not need to distinguish between signed and unsigned types. Other possibilities include offset binary, sign-magnitude, and ones' complement.

Some computer languages define integer sizes in a machine-independent way; others have varying definitions depending on the underlying processor word size. Not all language implementations define variables of all integer sizes, and defined sizes may not even be distinct in a particular implementation. An integer in one programming language may be a different size in a different language or on a different processor.


Common Integral Data Types























Note :

  1. Not all SQL dialects have unsigned datatypes.
  2. The sizes of char, short, int, long and long long in C/C++ are dependent upon the implementation of the language.
  3. The sizes of Delphi's Integer and Cardinal are not guaranteed, varying from platform to platform; usually defined as LongInt and LongWord respectively.
  4. Java does not directly support arithmetic on char types. The results must be cast back into char from an int.

Bytes and octets
The term byte initially meant 'the smallest addressable unit of memory'. In the past, 5-, 6-, 7-, 8-, and 9-bit bytes have all been used. There have also been computers that could address individual bits ('bit-addressed machine'), or that could only address 16- or 32-bit quantities ('word-addressed machine'). The term byte was usually not used at all in connection with bit- and word-addressed machines.

The term octet always refers to an 8-bit quantity. It is mostly used in the field of computer networking, where computers with different byte widths might have to communicate.
In modern usage byte almost invariably means eight bits, since all other sizes have fallen into disuse; thus byte has come to be synonymous with octet.

Words
 The term 'word' is used for a small group of bits which are handled simultaneously by processors of a particular architecture. The size of a word is thus CPU-specific. Many different word sizes have been used, including 6-, 8-, 12-, 16-, 18-, 24-, 32-, 36-, 39-, 48-, 60-, and 64-bit. Since it is architectural, the size of a word is usually set by the first CPU in a family, rather than the characteristics of a later compatible CPU. The meanings of terms derived from word, such as longword, doubleword, quadword, and halfword, also vary with the CPU and OS.

Practically all new desktop processors are capable of using 64-bit words, though embedded processors with 8- and 16-bit word size are still common. The 36-bit word length was common in the early days of computers.

One important cause of non-portability of software is the incorrect assumption that all computers have the same word size as the computer used by the programmer. For example, if a programmer using the C language incorrectly declares as int a variable that will be used to store values greater than 215−1, the program will fail on computers with 16-bit integers. That variable should have been declared as long, which has at least 32 bits on any computer. Programmers may also incorrectly assume that a pointer can be converted to an integer without loss of information, which may work on (some) 32-bit computers, but fail on 64-bit computers with 64-bit pointers and 32-bit integers.

Short integer
A short integer can represent a whole number which may take less storage, while having a smaller range, compared with a standard integer on the same machine.

In C, it is denoted by short. It is required to be at least 16 bits, and is often smaller than a standard integer, but this is not required. A conforming program can assume that it can safely store values between −(215−1) and 215−1, but it may not assume that the range isn't larger. In Java, a short is always a 16-bit integer. In the Windows API, the datatype SHORT is defined as a 16-bit signed integer on all machines

Long integer
A long integer can represent a whole integer whose range is greater than or equal to that of a standard integer on the same machine.

In C, it is denoted by long. It is required to be at least 32 bits, and may or may not be larger than a standard integer. A conforming program can assume that it can safely store values between −(231−1) and 231−1, but it may not assume that the range isn't larger.

Long long
In the C99 version of the C programming language and the C++11 version of C++, a long long type is supported that has double the minimum capacity of the standard long, 64 bits. This type is not supported by compilers that require C code to be compliant with the previous C++ standard, C++03, because the long long type did not exist in C++03. For an ANSI/ISO compliant compiler the minimum requirements for the specified ranges, that is −(231) to 231−1 for signed and 0 to 232−1 for unsigned, must be fulfilled; however, extending this range is permitted. This can be an issue when exchanging code and data between platforms, or doing direct hardware access. Thus, there are several sets of headers providing platform independent exact width types. The C standard library provides stdint.h; this was introduced in C99 and C++11.

Selasa, 06 Januari 2015

Boolean Data Types



Boolean explanation

In computer science, the Boolean data type is a data type, having two values (usually denoted true and false), intended to represent the truth values of logic and Boolean algebra. It is named after George Boole, who first defined an algebraic system of logic in the mid 19th century. The Boolean data type is primarily associated with conditional statements, which allow different actions and change control flow depending on whether a programmer-specified Boolean condition evaluates to true or false. It is a special case of a more general logical data type; logic does not always have to be Boolean.

In programming languages that have a built-in Boolean data type, such as Pascal and Java, the comparison operators such as > and ≠ are usually defined to return a Boolean value. Conditional and iterative commands may be defined to test Boolean-valued expressions.

Languages without an explicit Boolean data type, like C90 and Lisp, may still represent truth values by some other data type. Lisp uses an empty list for false, and any other value for true. C uses an integer type, where relational expressions like i > j and logical expressions connected by && and || are defined to have value 1 if true and 0 if false, whereas the test parts of if, while, for, etc., treat any non-zero value as true.[1][2] Indeed, a Boolean variable may be regarded (and be implemented) as a numerical variable with a single binary digit (bit), which can store only two values. It is worth noting that the implementation of Booleans in computers are most likely represented as a full word, rather than a bit; this is usually due to the ways computers transfer blocks of information.

Most programming languages, even those that do not have an explicit Boolean type, have support for Boolean algebraic operations such as conjunction (AND, &, *), disjunction (OR, |, +), equivalence (EQV, =, ==), exclusive or/non-equivalence (XOR, NEQV, ^, !=), and negation (NOT, ~, !).

In some languages, like Ruby, Smalltalk, and Alice the "true" and "false" values belong to separate classes—e.g. True and False, resp.—so there is no single Boolean "type."

In SQL, which uses a three-valued logic for explicit comparisons because of its special treatment of Nulls, the Boolean data type (introduced in SQL:1999) is also defined to include more than two truth values, so that SQL "Booleans" can store all logical values resulting from the evaluation of predicates in SQL. A column of Boolean type can also be restricted to just TRUE and FALSE though.

In the lambda calculus model of computing, Boolean values can be represented as Church Booleans.


Boolean Examples

Below is an example chart that help explains the Boolean operations even more by giving examples and explanations of each of the different Boolean situations.

Example data = "Rull's computer is a location where users can find free computer help and information"


Boolean Value_1 Value_2 Explanation Results
AND Free Help Because the above example data contains both "free" and "help" the results would be TRUE. TRUE
AND Expensive Help Although the above example does have "help", it does not contain "expensive," which makes the result FALSE. FALSE
OR Free Help The above example data has both "free" and "help" but the OR Boolean only requires one or the other, which makes this TRUE. TRUE
OR Expensive Help Although "expensive" is not in the example data, it still does contain "help," which makes the TRUE. TRUE
NOT Free The above example does contain "free", which makes the result FALSE. FALSE
NOT Expensive The above example does not contain "expensive," which makes the result TRUE. TRUE
XOR Free Help The above example contains both "free" and "help", the XOR Boolean only requires one or the other, but not both, making this FALSE. FALSE
XOR Expensive Help The above example does not contain "expensive" but does contain "help," which makes this TRUE. TRUE

Boolean in programming

When programming, a boolean can be done with conditional statements (i.e. if statement) as shown in the example below using Perl.

use strict;
my ($name, $password);
print "\nName: ";
chomp($name = <STDIN>);
print "\nPassword: ";
chomp($password = <STDIN>);
if (($name eq "rull") && ($password eq "pirates")) {
print "Success\n";
} else {
print "Fail\n";
die;
}

In the above example, the if statement is looking for a username that is equal to "rull" and a password that is equal to "pirates". If either the name or password is not correct the program will print "Fail" and die.

Data Type in Computer Science and Programming


Hello again :D

In this post i'm going to resume some article that i've got on the Internet and make a simple article to you all. The focus in this article is about Data type in Computer Science and Programming. Do you know what that mean?

Well, In computer science and computer programming, a data type or simply type is a classification identifying one of various types of data, such as real, integer or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of that type can be stored.

Data types are used within type systems, which offer various ways of defining, implementing and using them. Different type systems ensure varying degrees of type safety.

Almost all programming languages explicitly include the notion of data type, though different languages may use different terminology. Common data types include:


  1. Integers,
  2. Booleans,
  3. Characters,
  4. Floating-point numbers,
  5. Alphanumeric strings.


For example, in the Java programming language, the "int" type represents the set of 32-bit integers ranging in value from -2,147,483,648 to 2,147,483,647, as well as the operations that can be performed on integers, such as addition, subtraction, and multiplication. Colors, on the other hand, are represented by three bytes denoting the amounts each of red, green, and blue, and one string representing that color's name; allowable operations include addition and subtraction, but not multiplication.

Most programming languages also allow the programmer to define additional data types, usually by combining multiple elements of other types and defining the valid operations of the new data type. For example, a programmer might create a new data type named "complex number" that would include real and imaginary parts. A data type also represents a constraint placed upon the interpretation of data in a type system, describing representation, interpretation and structure of values or objects stored in computer memory. The type system uses data type information to check correctness of computer programs that access or manipulate the data.


(Parnas, Shore & Weiss 1976) identified five definitions of a "type" that were used—sometimes implicitly—in the literature:

Syntactic
A type is a purely syntactic label associated with a variable when it is declared. Such definitions of "type" do not give any semantic meaning to types.

Representation
A type is defined in terms of its composition of more primitive types—often machine types.

Representation and behaviour
A type is defined as its representation and a set of operators manipulating these representations.

Value space
A type is a set of possible values which a variable can possess. Such definitions make it possible to speak about (disjoint) unions or Cartesian products of types.

Value space and behaviour
A type is a set of values which a variable can possess and a set of functions that one can apply to these values.

The definition in terms of a representation was often done in imperative languages such as ALGOL and Pascal, while the definition in terms of a value space and behaviour was used in higher-level languages such as Simula and CLU.


Classes of data types

There are 5 classes of data types, Primitive, Composite, Others, Abstract and Utility Types, but don't worry, I will post those 5 details in another article, in here, i'm just posting the basic explanation of each classes.


Primitive Data Types :
In computer science, primitive data type is either of the following:
  • a basic type is a data type provided by a programming language as a basic building block. Most languages allow more complicated composite types to be recursively constructed starting from basic types.
  • a built-in type is a data type for which the programming language provides built-in support.
Primitive Data Types is divided into 3, consist of :

1. Machine Data Types :
Machine data types need to be exposed or made available in systems or low-level programming languages, allowing fine-grained control over hardware. The C programming language, for instance, supplies integer types of various widths, such as short and long. If a corresponding native type does not exist on the target platform, the compiler will break them down into code using types that do exist. For instance, if a 32-bit integer is requested on a 16 bit platform, the compiler will tacitly treat it as an array of two 16 bit integers.

The Boolean type represents the values true and false. Although only two values are possible, they are rarely implemented as a single binary digit for efficiency reasons. Many programming languages do not have an explicit boolean type, instead interpreting (for instance) 0 as false and other values as true.

3. Numeric Data Types :
Such as, the integer data types, the floating point, fixed point, bignum or abitory position.



Composite Data Types : 
Composite types are derived from more than one primitive type. This can be done in a number of ways. The ways they are combined are called data structures. Composing a primitive type into a compound type generally results in a new type, e.g. array-of-integer is a different type to integer.
It divided into 2, consist of :

1. Enumerations Data Types :
The enumerated type. This has values which are different from each other, and which can be compared and assigned, but which do not necessarily have any particular concrete representation in the computer's memory; compilers and interpreters can represent them arbitrarily. For example, the four suits in a deck of playing cards may be four enumerators named CLUB, DIAMOND, HEART, SPADE, belonging to an enumerated type named suit. If a variable V is declared having suit as its data type, one can assign any of those four values to it. Some implementations allow programmers to assign integer values to the enumeration values, or even treat them as type-equivalent to integers.

2. String and text Data Types :
Character and string types can have different subtypes according to the required character "width". The original 7-bit wide ASCII was found to be limited, and superseded by 8 and 16-bit sets, which can encode a wide variety of non-Latin alphabets (Hebrew, Chinese) and other symbols. Strings may be either stretch-to-fit or of fixed size, even in the same programming language. They may also be subtyped by their maximum size.


Other types :
Types can be based on, or derived from, the basic types explained above. In some languages, such as C, functions have a type derived from the type of their return value.
It divided into 2, consist of :

1. Pointers and references :
The main non-composite, derived type is the pointer, a data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address. It is a primitive kind of reference.

2. Function Types :
A function type depends on the type of the parameters and the result type of the function (it, or more accurately the unapplied type constructor is a higher-kinded type).


Abstract Data Types : 
Any type that does not specify an implementation is an abstract data type. For instance, a stack (which is an abstract type) can be implemented as an array (a contiguous block of memory containing multiple values), or as a linked list (a set of non-contiguous memory blocks linked by pointers).


Utility Data Types :
For convenience, high-level languages may supply ready-made "real world" data types, for instance times, dates and monetary values and memory, even where the language allows them to be built from primitive types.




Senin, 05 Januari 2015

If you want it simple, BlueJ is the answer

Good morning, it's a nice day, isn't it? :D

Have you ever heard of BlueJ before?


BlueJ is a development environment that allows you to develop Java programs quickly and easily. I repeat. Quickly and Easily. Its main features are that it is:




  • Simple. BlueJ has a deliberately smaller and simpler interface than professional environments like NetBeans or Eclipse. This allows beginners to get started more quickly, and without being overwhelmed.
  • Designed for teaching. BlueJ is deliberately designed with good pedagogy in mind. There is a popular textbook designed for teaching introductory university/college courses with BlueJ, and a site full of teaching resources.
  • Interactive. BlueJ allows you to interact with objects. You can inspect their value, call methods on them, pass them as parameters and more. You can also directly invoke Java expressions without compiling. Thus BlueJ is a powerful graphical shell/REPL for Java.
  • Portable. BlueJ runs on Windows, Mac OS X, Linux and other platforms which run Java. It can also run without installation from a USB stick.
  • Mature. BlueJ is over fifteen years old, but continues to be updated and supported by a full-time team. We aim to respond to all technical support requests within one working day.
  • Innovative. BlueJ has several features not seen before in other IDEs. Its object bench, code pad, and scope colouring were all original BlueJ features.
It's awesome, right?Next i'm going to show you how simple working with BlueJ.Oh right, first you have to install Java Development Kit before you can run BlueJ. You can read my previous article in here to get the download link. After you installed it, you have to download BlueJ Application. You can get it from here. Once you finished, run the setup and this window will show up.














Just click "Next".















In this window, you can choose what user can use BlueJ on your computer. Is it only you? or all of the users. If you want just yourself using it, choose "Install just for you" and click "Next".














If you want to add BlueJ's file associations, shortcut in your window and start menu, check all of the box and click "Next"














And if you want to change destination folder to install BlueJ, click "Change" and choose your folder. If not, just click "Next"













And we're good to go, just click "Install" and the installation will begin.

















Wait for a couple of minutes and this window will show up. Click "Finish" and congratulations, you have installed BlueJ.


Next, i'm going to compile a simple source code using BlueJ. The first thing you need to do is run it, of course.


Double click BlueJ shortcut that you have made on the desktop and this window will show up.
















This is the first view of BlueJ working ground.















Click "Project" -> "New Project" to start a new project. And this window will show up.
















Just like another IDE Editor for Java, you have to save the file first. In this case, i will name it "HelloWorld" Project and save it on "MyJavaProject" folder and click save.















After that, you have to make a new "class" , just click on "New Class" and give a name same by the project name and click "OK".















And if succeed, there will be an icon named "HelloWorld" with a brown box with diagonal shape. This diagonal shape means that class haven't compiled yet. If you want to compile it, just click on the diagonal and choose compile on the left. But no hurry, we have to edit the source code before that. To do it, right-click on the "HelloWorld" and choose "Open Editor".















And new window will show up.















On the right side, there is a source code brought by BlueJ default. Just delete it and replace with this code.


public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }

}














And now you can compile it, just click compile on the left corner. And if nothing wrong, you will have a notification that tell you "there is no syntax error" and the diagonal shape on the box will dissapear.















Next, close the source code editor, and right click on the "HelloWorld" box, and choose "void main (String[] args)" , and a window will pop-up, just click "OK" and it will runs the source code and see the result. 




























This is the result.













Voila, simple, right?
You have any question? Don't bother to ask in the comment section.

Okay, this is the end of the post. See you soon...


Meet Processing, an awesome IDE/Editor for Java.

Hello again :D

This time, i want to introduce you to an IDE/Editor for Java named Processing.

Processing is an open source programming language and integrated development environment (IDE) built for the electronic arts, new media art, and visual design communities with the purpose of teaching the fundamentals of computer programming in a visual context, and to serve as the foundation for electronic sketchbooks. The project was initiated in 2001 by Casey Reas and Benjamin Fry, both formerly of the Aesthetics and Computation Group at the MIT Media Lab. One of the stated aims of Processing is to act as a tool to get non-programmers started with programming, through the instant gratification of visual feedback. The language builds on the Java language, but uses a simplified syntax and graphics programming model. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology. Initially created to serve as a software sketchbook and to teach computer programming fundamentals within a visual context, Processing evolved into a development tool for professionals. Today, there are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning, prototyping, and production. Told you, it's awesome right?

Okay, in this post, i will show you how to compile a simple source code with Processing and look how awesome it is.

You need to download it first, of course, you can do it by click this link and choose your Operating System. It support many operating system, so you don't have to worry.

Once you finished, open containing folder that store Processing zip-file and extract it. (You must know how to extract a zip-file, don't you?)

And open Processing folder, and click on Processing.exe. And it should look like this.

















Make sure the option on right up corner is "Java", so you won't have problems ahead.
Okay, let's try to compile some source code.
I got this code from here that will show you a better example of the look and feel of the language.


//Hello mouse.
void setup() {
       size(400, 400);
       stroke(255);
       background(192, 64, 0);
}

void draw() {
       line(150, 25, mouseX, mouseY);
}

After you type it down, just click Play symbol on the left corner, it means run and compile the code and see how it works.














A straight line will drawn by your mouse movement everywhere within the orange box.

A program written as a list of statements is called a static sketch. In a static sketch, a series of functions are used to perform tasks or create a single image without any animation or interaction. Interactive programs are drawn as a series of frames, which you can create by adding functions titled setup() and draw() as shown in the code. These are built-in functions that are called automatically.

The setup() block runs once, and the draw() block runs repeatedly. As such, setup() can be used for any initialization; in this case, setting the screen size, making the background orange, and setting the stroke color to white. The draw() block is used to handle animation. The size() function must always be the first line inside setup().

Because the background() function is used only once, the screen will fill with lines as the mouse is moved. To draw just a single line that follows the mouse, move the background() function to the draw() function, which will clear the display window (filling it with orange) each time draw() runs.

Static programs are most commonly used for extremely simple examples, or for scripts that run in a linear fashion and then exit. For instance, a static program might start, draw a page to a PDF file, and exit.

Most programs will use the setup() and draw() blocks. More advanced mouse handling can also be introduced; for instance, the mousePressed() function will be called whenever the mouse is pressed. In the following example, when the mouse is pressed, the screen is cleared via the background() function:

Do you with me so far? Feel free to ask if you have a question.
Okay, this is the end of the post. Good morning.