Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Sunday, August 7, 2011

Seven Java projects that revolutionized the world

http://vivta.org/web_images/7.jpg 
Over the last decade, several projects have traveled beyond mere adoption and had effects dominating the Java world, into software development in general, and some even further into the daily lives of users.

JUnit

Ported to Java by Kent Beck and Erich Gamma from Beck's work in unit testing in Smalltalk, JUnit has been largely responsible for popularizing test-driven development over the last decade. Many implementations have been created, in .NET, C, Python, Perl and just about every language in popular use.

Eclipse

As Java and its APIs matured in the early 2000s, the Eclipse IDE provided a way for programmers to be productive and negotiate the growing Java ecosystem. Eclipse was also the first major project to use the SWT UI toolkit, providing important competition to Sun's Swing and showing that Java programs can provide a rich native interface.

Spring

The Spring Framework has played an important role in enabling Java developers to be productive, managing a balance between simplicity and features. Spring gives Java developers a set of services providing commonly used application functionality such as data access and transaction management. As a competitor to Sun's Enterprise Java Beans system, Spring enabled an alternative and simpler path for Java applications.

Solr

The Solr server, and the Lucene search engine it encapsulates, has been for many years a simple and practical solution to providing search capabilities to web and enterprise applications. Solr's genius is in providing HTTP access to the powerful and fast Lucene search library, enabling it to become a part of any system, regardless of whether it is implemented in Java or not.

Hudson and Jenkins

Originally developed as Hudson, and now also as Jenkins, this continuous integration tool is a key part of a Java development setup. Jenkins provides automated build and testing of a software project, continuing in the footsteps of JUnit in enabling agile development on the Java platform. While both Hudson and Jenkins persist for now as forks of each other, it doesn't detract from the work of Kohsuke Kawaguchi in creating a world-class continuous integration platform and so enhancing the quality of much Java development.

Hadoop

This Java implementation of the famous MapReduce model is the powerhouse that has enabled most "big data" systems. By lowering the cost of extracting value from large data sets, Hadoop has made practical the personalization and advertising businesses of Facebook and Yahoo, and many other companies.Hadoop enables large-scale distributed computing by handling failure at the software level.

Android

Android programs undergo a further step to convert JVM bytecode to Dalvik bytecode — Dalvik being a virtual machine optimized for mobile devices. Google has been able to leverage Eclipse to provide software developers with a mature development environment for creating Android applications.
Oracle and Google are currently engaged in a lawsuit over a claim that Android infringes on multiple patents held by Oracle.

via [radar.oreilly.com]

Java Programming Tutorial - 6 - Getting User Input

http://verticalhorizons.in/wp-content/uploads/2011/08/JOptionPane_User_Input_In_Java.bmp

The package that needs to be imported to accept user input is java.io. The java.io package contains classes and interfaces used for input and output.
The setup:
import java.io.*; 
class GetUserInput{ }

User input classes

To get user input, use the BufferedReader and InputStreamReader classes.
  • The InputStreamReader class - reads the user's input.
  • The BufferedReader class - buffers the user's input to make it work more efficiently.
  1. package com.tctalk.myapp.java.src;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. /**
  6. * ReaduserInput.java - [This code reads the user input data from command prompt]
  7. *
  8. * @author TechCuBeTalk.com
  9. * @version 1.0
  10. */
  11. public class ReaduserInput {
  12.     public static void main(String[] args) {
  13.         //  Ask the user to enter their name
  14.         System.out.print("Please enter your name: ");
  15.         //  To read user input create a reader object
  16.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  17.         String userName = null;
  18.         //  read the user input from command prompt by readLine() method
  19.         try {
  20.             userName = br.readLine();
  21.         } catch (IOException ioExcption) {
  22.             System.out.println("IO exception occurred!");
  23.             System.exit(1);
  24.         }
  25.         System.out.println("Welcome " + userName + "!! Have a Good day!!");
  26.     }
  27. }

For more practice, here's a demo:


via[techcubetalk.com]

Java Programming Tutorial - 5 - Variables

http://i.ytimg.com/vi/pXBJwFBvyjA/0.jpg

What is a variable?

A variable is a container that stores a meaningful value that can be used throughout a program. For example one variable that stores the regular price of an item for calculating tax on it. Variables store this information in a computer's memory and the value of a variable can change all through out a program.

Declaring variables

Use these keywords when declaring your variables to set the data type of the variable.
Java data types
Keyword Type of data the variable will store Size in memory
boolean true/false value 1 bit
byte byte size integer 8 bits
char a single character 16 bits
double double precision floating point decimal number 64 bits
float single precision floating point decimal number 32 bits
int a whole number 32 bits
long a whole number (used for long numbers) 64 bits
short a whole number (used for short numbers) 16 bits

Example:
char aCharacter; int aNumber;
You can assign a value to a variable at the same time that it is declared. This process is known as initialization:
Example:
char aCharacter = 'a'; int aNumber = 10;
Declaring a variable and then giving it a value:
char aCharacter; aCharacter = 'a'; int aNumber; aNumber = 10;
NOTE: A variable must be declared with a data type or an error will be generated!

Naming variables

Rules that must be followed when naming variables or errors will be generated and your program will not work:
  • No spaces in variable names
  • No special symbols in variable names such as !@#%^&*
  • Variable names can only contain letters, numbers, and the underscore ( _ ) symbol
  • Variable names can not start with numbers, only letters or the underscore ( _ ) symbol (but variable names can contain numbers)



via [landofcode.com]

Java Programming Tutorial - 4 - First Program

http://pradigital-susel-duarte.wikispaces.com/file/view/apostila-java-350x328%5B1%5D.png/173374337/apostila-java-350x328%5B1%5D.png

Note: Before you start, you must have downloaded and installed the Java SE Development Kit.
It’s traditional to start learning a new programming language by writing a program called "Hello World". You can think of it as a very simple initiation into the ranks of Java programmers. All the program does is write the text "Hello World!" to your computer screen.
The basic steps we will follow for our Hello World program are:
  1. Write the program in Java
  2. Compile the source code
  3. Run the program
Note: Java is case sensitive. Remember this.
Here's a complete tutorial:



via [java.about.com]

Java Programming Tutorial - 3 - Downloading Eclipse

http://www.amscontrols.com/Libraries/Home_Page_Graphics/EclipseLogo.sflb.ashx 
Language IDE

Eclipse is well known for its Java IDE. However, there are Eclipse base language IDEs for most of the popular languages. Some are popular Eclipse open source project, such as CDT, and others are popular open source projects and commercial solutions.



Download Package
Eclipse IDE for Java Developers




Download Link: http://www.eclipse.org/

Java Programming Tutorial - 2 - Running a Java Program

http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/Art/platform.gif
Creating Your First Application
Your first application, HelloWorld, will simply display the greeting "Hello world!". To create this program, you will: 
  • Create a source file
    A source file contains code, written in the Java programming language, that you and other programmers can understand. You can use any text editor to create and edit source files.
  • Compile the source file into a .class file
    The Java programming language compiler (javac) takes your source file and translates its text into instructions that the Java virtual machine can understand. The instructions contained within this file are known as bytecodes.
  • Run the program
    The Java application launcher tool (java) uses the Java virtual machine to run your application.
via [download.oracle.com]

Java Programming Tutorial - 1- Installing the JDK


http://javaboutique.internet.com/articles/ITJ/Images/jdk_install.gif

Installing the JDK on Windows

  1. For the Sun version of the JDK, enter the URL http://java.sun.com/j2se/1.4.2/download.html.
  2. From the Sun Developer Network page, scroll to find the heading J2SE v 1.4.2_12 SDK (that is, .12 or the latest version).
  3. Select Download J2SE SDK.
  4. From the Sun Developer Network page, accept the license agreement and scroll to the heading "Windows Platform - Java(TM) 2 SDK, Standard Edition 1.4.2_12".
  5. Select and download Windows Installation, Multi-language.
  6. Save and install the .exe file.
  7. If prompted, install the JDK to C:\j2sdk1.4.2_10.
  8. Set the JAVA_HOME environment variable to C:\j2sdk1.4.2_12

Sunday, July 31, 2011

C++ Bits Operators

A bit related operation allows you to control how values are stored in bits. This is not an operation you will need to perform very often, especially not in the early stages of your C++ journey. Nevertheless, bit operations (and related overloaded operators) are present on all GUI or application programming environments, so much that you should be aware of what they do or what they offer. At this time, you should (must) be aware of what a bit, byte, and a word are.
Bits Operators: The Bitwise NOT Operator
 One of the operations you can perform on a bit consists of reversing its value. That is, if a bit holds a value of 1, you may want to change it to 0 and vice-versa. This operation can be taken care of by the bitwise NOT operator that is represented with the tilde symbol ~
The bitwise NOT is a unary operator that must be placed on the left side of its operand as in

 To perform this operation, the compiler considers each bit that is part of the operand and inverts the value of each bit from 1 to 0 or from 0 to 1 depending on the value the bit is holding. This operation can be resumed in the following table:

Bit ~Bit
1 0
0 1
 Consider a number with a byte value such as 248. In our study of numeric systems, we define how to convert numbers from one system to another (this could be a good time to review or study the numeric systems). Based on this, the binary value of decimal 248 is 1111 1000 (and its hexadecimal value is 0xF8). If you apply the bitwise NOT operator on it to reverse the values of its bits, you would get the following result:

 Value 1 1 1 1 1 0 0 0
~Value 0 0 0 0 0 1 1 1


via [functionx]

Conditional Statements in C++

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO6AYHJH2f5ZPUjr2MfbypO36qxwd3tJRGm12t4Qh3zdnxSFj-j2SK4QyuGQLcG1EclRZ9EVNSKlAes7Xz29Jd9De_dA-l6GTd7KKY7khrrWcMVvJje95CldTBOwe66x9fggc_FygkIf6U/s400/IfElse.bmp


There are techniques you can use to combine conditional statements when one of them cannot fully implement the desired behavior.
We will continue with our traffic light analogy.
 
Nesting Conditions
A condition can be created inside of another to write a more effective statement. This is referred to as nesting conditions. Almost any condition can be part of another and multiple conditions can be included inside of others.
As we have learned, different conditional statements are applied in specific circumstances. In some situations, they are interchangeable or one can be applied just like another, which becomes a matter of choice. Statements can be combined to render a better result with each playing an appropriate role.
To continue with our ergonomic program, imagine that you would really like the user to sit down and your program would continue only once she answers that she is sitting down, you can use the do…while statement to wait for the user to sit down; but as the do…while is checking the condition, you can insert an if statement to enforce your request. Here is an example of how you can do it:
#include <iostream>
using namespace std;

int main()
{
 char SittingDown;
 
 do {
  cout << "Are you sitting down now(y/n)? ";
  cin >> SittingDown;
  
  if( SittingDown != 'y' )
   cout << "\nCould you please sit down for the next exercise?\n";
 }
 while( !(SittingDown == 'y') );
 
 cout << "\nWonderful!!!\n";
 return 0;
}
Here is an example of running the program:
Are you sitting down now(y/n)? n
Could you please sit down for the next exercise?

Are you sitting down now(y/n)? n
Could you please sit down for the next exercise?

Are you sitting down now(y/n)? y

Wonderful!!!

Press any key to continue...
Continue Reading.....
via [functionx]

Creating and Using References in C++

http://fwallpapers.com/files/images/c-programming-language.jpg


#include <iostream>
 
 int main()
 {
     int  intValue;
     int &intReference = intValue;
 
     intValue = 5;
     std::cout << "intValue: " << intValue << std::endl;
     std::cout << "intReference: " << intReference << std::endl;
 
     intReference = 7;
     std::cout << "intValue: " << intValue << std::endl;
     std::cout << "intReference: " << intReference << std::endl;
     return 0;
 }
 
Output:
intValue: 5
intReference: 5
intValue: 7
intReference: 7
 
Read More..... 
 
via[java2s] 

Data structures in C++

http://s3.hubimg.com/u/3160990_f496.jpg


A data structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths. Data structures are declared in C++ using the following syntax:

struct structure_name {
member_type1 member_name1;
member_type2 member_name2;
member_type3 member_name3;
.
.
} object_names;

where structure_name is a name for the structure type, object_name can be a set of valid identifiers for objects that have the type of this structure. Within braces { } there is a list with the data members, each one is specified with a type and a valid identifier as its name.

The first thing we have to know is that a data structure creates a new type: Once a data structure is declared, a new type with the identifier specified as structure_name is created and can be used in the rest of the program as if it was any other type. For example:


1
2
3
4
5
6
7
struct product {
  int weight;
  float price;
} ;

product apple;
product banana, melon;


We have first declared a structure type called product with two members: weight and price, each of a different fundamental type. We have then used this name of the structure type (product) to declare three objects of that type: apple, banana and melon as we would have done with any fundamental data type.


more reading



via [cplusplus]

Printing Leading Zeros in C++ using setw

http://www.itguide.co.in/images/3006_C___Language_Tutorial.png.gif
setw sets the number of characters to be used as the field width for the next insertion operation.

Behaves as if a call to the stream's member ios_base::width with n as its argument was made.

The field width determines the minimum number of characters to be written in some output representations. If the standard width of the representation is shorter than the field width, the representation is padded with fill characters (see setfill) at a point determined by the format flag adjustfield (left, right or internal).

This manipulator is declared in header <iomanip>, along with the other parameterized manipulators: resetiosflags, setiosflags, setbase, setfill and setprecision. This header file declares the implementation-specific smanip type, plus any additional operator overload function needed to allow these manipulators to be inserted and extracted to/from streams with their parameters.

Here's a simple example for displaying leading zeros using setw function.


#include <iomanip>
#include <iostream>

using namespace std;

int main( )
{
   const int num_members = 6;
   const int id[num_members]    6518,3};
   const int month[num_members9111210};
   const int day[num_members]   21133031};
   const int year[num_members2000200320041998,20012003 };

   cout << setfill'0' );
   forint i = 0; i < num_members; ++i )
      cout << " : " << setw<< id[i]
           << " : " << setw<< month[i<< "/"
           << setw<< day[i<< "/" << setw)
           << year[i100 << endl;
}

  Out Put:                                
via [java2s]