Showing posts with label Programming. Show all posts

QR Code Generator in JAVA

Short Description...

QR (abbreviated as Quick Response) is the trademark for a type of matrix barcode (or two-dimensional or 2D barcode) first designed for the automotive industry in Japan. A barcode is a machine-readable optical label that contains information about the item to which it is attached.

A QR code consists of black modules (square dots) arranged in a square grid on a white background, which can be read by an imaging device (such as a camera, scanner, etc.) and processed using Reed-Solomon error correction until the image can be appropriately interpreted. The required data are then extracted from patterns that are present in both horizontal and vertical components of the image.

Output...
Scan this code and Comment the secret written in it.
Lets Code...

Lets do some magic in JAVA to create own program to generate QR Code. If you are familiar with JAVA then it ok otherwise you must first follow some good tutorial of Java. They can be found at www.javatpoint.com, www.tutorialspoint.com etc

In JAVA creating a whole program to create QR Code is a little bit tricky to do but don't worry I am not going to teach you whole programming. Yes, we are going to use some pre-build libraries by ZXing (get on github).

Prerequisite...

  • Netbeans (IDE) with JAVA latest SDK
  • ZXing QR Code generator libraries (Download)

Libraries...

  • qrgen-1.3.jar
  • zxing-core-2.0.jar
  • zxing-1.7.jar
Get them from official ZXing github repository or download them directly from HERE.

Lets Do it...

Step 1 :  

Create a new JAVA project in Netbeans IDE and name it QRCodeGenerator.

Step 2

Expand the project folder on left of Netbeans IDE and right click on Libraries and select Add JAVR/Folder

Step 3

Move to the folder where you have downloaded jar files on the left and select all three file on the right box and click OK

Step 4

Write the following java code in main java file

/*
 * 
 * QRCodeGenerator.java
 * 
 */

package qrcodegenerator;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;

/**
 * @author anujsharma
 **/
public class QRCodeGenerator {

    /**
     * @param args the command line arguments
     * @throws java.io.FileNotFoundException
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        // TODO code application logic here
        
        Scanner sc = new Scanner(System.in);
        
        System.out.println("QR CODE Generator....");
        System.out.println("********************************");
        System.out.println("Enter The String to create QR : ");
        String details = sc.nextLine();
        System.out.println("Enter the path to export QR File : ");
        String path = sc.nextLine();
        
        ByteArrayOutputStream out = QRCode.from(details).to(ImageType.PNG).withSize(300, 300).stream();
        
        File f = new File(path+"qr.png");
        
        FileOutputStream fos = new FileOutputStream(f);
        
        fos.write(out.toByteArray());
        fos.flush();
        
        System.out.println("QR Code Created Successfully.");
    }   
}



Step 5 

Thats it... Now run your file and get your QR Code generated

NOTE:::
User Inputs....
PATH : to produce QR Code at the location given.

Want to Make Your First Android App ? Here is Over 200 Video Tutorials for you.

Making Andriod app has become one of the easiest ways for developers to make money. Of course, you need to make a great app for that. To help you in the process, we are presenting over 200 video tutorials on Android application development. Happy making!


1. Android Application Development Tutorial

   Here is a playlist of 200 video tutorial on Android Application Development, Courtesy The New Boston !



2. Free Android Application Development Tutorial - Beginner Level



3. Android Application Development - UI




4. Android Application Development - Android Basics | Android Development Course




5. Make your First Android App !




6. Programming for Android - Step 1, Everything you need to install

Learn To Compile And Run C/C++ Code In Linux: 10 Steps To Follow

Are you interested in writing C or C++ programs on Ubuntu Linux instead of MS-Windows? Using the bash Terminal application you can compile a C or C++ program on any Linux distro, like Ubuntu, Red Hat, Fedora, Debian and others. You just need to install GNU C and C++ compiler collection, development tools, development libraries and IDE or text editor to write programs. Let's discuss the process step-wise:




Step #1: Install C/C++ compiler and related tools: 

Use the following yum command to install GNU C/C++ compiler, on Fedora, Red Hat, CentOS or Scientific Linux:
 # yum groupinstall 'Development Tools'

In case you are using Debian or Ubuntu Linux then you need the following apt-get command to install the same:
 $ sudo apt-get update
$ sudo apt-get install build-essential manpages-dev

Step #2: Verify installation: 

Type the following command to display the version number and location of the compiler on Linux:
$ whereis gcc
$ which gcc
$ gcc –version

Here is a sample of the output:



Step #3: How to Compile and Run C/C++ program on Linux: 

Create a file called demo.c using a text editor such as vi, emacs or joe:
#include
/* demo.c: My first C program on a Linux */
int main(void)
{
printf("Hello! This is a test prgoram.\n");
return 0;

Step #4: How to Compile the program on Linux? 

Use any one of the following syntax to compile the program called demo.c:

cc program-source-code.c -o executable-file-name

OR
gcc program-source-code.c -o executable-file-name

OR ## assuming that executable-file-name.c exists ##

cc demo.c -o demo

OR
## assuming demo.c exists in the current directory ##
make demo

If your code or C program has no error, then an executable file called demo will be successfully created by the compiler in the current directory, otherwise the code can be fixed. To verify this, type:
$ ls -l demo*

Step #5:How to run or execute the program called demo on Linux? 

Simply type the the program name:
$ ./demo
OR
$ /path/to/demo

Compiling and running a simple C++ program
Create a program called demo2.C as follows:
#include "iostream"
// demo2.C - Sample C++ prgoram
int main(void)
{
std::cout << "Hello! This is a C++ program.\n";
return 0;
}
To compile this program, enter:

make demo2


To run this program, type:

./demo2


Step #6: How to generate symbolic information for gdb and warning messages? 

The syntax is as follows C compiler:
cc -g -Wall input.c -o executable
The syntax is as follows C++ compiler:
g++ -g -Wall input.C -o executable

Step #7: How to generate optimized code on a Linux machine? 

The syntax is as follows C compiler:
cc -O input.c -o executable
The syntax is as follows C++ compiler:
g++ -O -Wall input.C -o executable
Step #8: How to compile a C program that uses math functions? 

The syntax is as follows when need pass the -lm option with gcc to link with the math libraries:
cc myth1.c -o executable -lm

Step #9: How to compile a C++ program that uses Xlib graphics functions? 

The syntax is as follows when need pass the -lX11 option with gcc to link with the Xlib libraries:
g++ fireworks.C -o executable -lX11

Step #10: How to compile a program with multiple source files? 

The syntax is as follows if the source code is in several files (such as light.c, sky.c, fireworks.c):
cc light.c sky.c fireworks.c -o executable
C++ syntax is as follows if the source code is in several files:
g++ ac.C bc.C file3.C -o my-program-name

Color-Table in C

Color-Table in C Programming Language

Following colors are available for use in c graphics programming.




Color Table :


COLORVALUE
BLACK0
BLUE1
GREEN2
CYAN3
RED4
MAGENTA5
BROWN6
LIGHTBLUE7
DARKGRAY8
LIGHTBLUE9
LIGHTGREEN10
LIGHTCYAN11
LIGHTRED12
LIGHTMAGENTA13
YELLOW14
WHITE15

Total number of colors available depend on current graphics driver and mode. Use colors name in capital letters, for example use setcolor(RED) not setcolor(red) the latter will give you an error. You may use number instead of color for example setbkcolor(GREEN) or setbkcolor(2) are same, but you are advised to use color name as it will improve readability of program.

Changing Text Color In C/C++ Programming Language

Are you a newbie programmer learning C/C++ Programming Languages. Here is a new trick for you to make others and your classmates surprise. This trick will tell you, how you can change the Text Color, Blink a Text, or Change the Background Color.


textcolor function is used to change the color of drawing text in c programs.

Declaration :- void textcolor(int color);
where color is an integer variable. For example 0 means BLACK color, 1 means BLUE, 2 means GREEN and soon. You can also use write appropriate color instead of integer. For example you can write textcolor(YELLOW); to change text color to YELLOW. But use colors in capital letters only.

A List of Color codes can be found here : Color-Table

1. C programming code to change text color

#include<stdio.h>
#include<conio.h>
 
void main()
{
   textcolor(RED);
   cprintf("C programming");
 
   getch();
   
}

2. C programming code to BLINK the Text

#include<stdio.h>
#include<conio.h>
 
void main()
{
   textcolor(MAGENTA+BLINK);
   cprintf("C programming");
 
   getch();
   
}

Note that we have used cprintf function instead of printf. This is because cprintf send formatted output to text window on screen and printf sends it to stdin.