9lessons Programming Blog - Tutorials about Angular, ReactJS, PHP, MySQL and Web Development
Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
Monday, October 08, 2012

RESTful Web Services JSON API Transformer with Java

This post is the continuation of my previous last post, I had explained how to create a basic RESTful web services API using Java, now I want to explain JSON transformer to work with input Get and Post methods parameters. Just added a new class called transformer it converts object data into JSON text output format.

RESTful Web Services with input parameters
Sunday, September 16, 2012

RESTful Web Services API using Java and MySQL

Are you working with multiple devices like iPhone, Android and Web, then take a look at this post that explains you how to develop a RESTful API in Java. Representational state transfer (REST) is a software system for distributing the data to different kind of applications. The web service system produce status code response in JSON or XML format.

RESTful Web Services using Java and MySQL
Monday, August 27, 2012

Java MySQL JSON Display Records using Jquery.

This is the continuation of my previous Java tutorial Insert Records into MySQL database using Jquery, now I want to explain how to convert records data into JSON data format and display JSON data feed using Jquery. It's simple just follow few steps with Eclipse IDE, hope you understand the Model View Controller pattern Thanks!

Java JSON Jquery Display Records
Wednesday, July 25, 2012

Java MySQL Insert Record using Jquery.

If you know Java concepts, you can easily understand any kind of language very quickly. If you want to became a good programmer, I strongly suggest start with J2EE programming. I heard that many people feels that it's though After long time I decided to write about J2EE programming with Jquery in a simple and better understanding way, hope you like it. Thanks!

Menu Design with JSON Data.
Wednesday, July 27, 2011

Get Started Developing for BlackBerry.

Are you looking for BlackBerry application development tutorial. Take a quick look at this post my friend want to explain how to download and install BlackBerry standard development kit with eclipse IDE. It's very simple just follow these steps and you can create Hello World program.

Get Started Developing for Blackberry with Eclipse
Sunday, February 14, 2010

Live Availability Checking with Java.

Some days I had posted an article about User name live availability checking with PHP and jquery. In this post my brother Ravi Tamada explained the same with Java technologies like JSP and servelts using MySQL database.

Live Availability Checking with Java.

Friday, May 22, 2009

Update a Record with Animation effect using JSP and jQuery.

I received a lot of requests about integration of JQuery and Ajax with Java (JSP). After long time again I'm working on JSP. I prepared a tutorial to update a record with animation effect using jQuery and JSP. Its very simple example contains some lines of Java and HTML code.

Tuesday, November 11, 2008

What is an Object? - Easy Lesson

Before the development of Object Oriented programming, the variables were considered as isolated entities. For example, suppose a program needs to handle data in car manufacturing company, here testing the cars having number, Color, Speed. Three separated variables will be declared for this.

int number,speed;
String color;




These two statements do two things:
1)It says that the variable number and speed are integers and color is a string variable.
2)It also allocates storage for these variables.

This approach has two disadvantages:
If the program needs to keep track of various cars records. There will be more declarations that would be needed for each car, for example.

int number1,speed1;
String color1;

int number2,speed2;
String color2;

This approach can become very cumbersome.
The other drawback is that this approach completely ignores the fact that the three variables number,speed and color, are related and are a data associated with a single car.
In order to address these to drawbacks java use a class to create new types. For example to define a type that represents a car, we need storage space for two integers and a string. this is defined as follows:

class Car
{
int number;
int speed;
String color;
}

A variable can be declared as of type car as follows:

Car c,c1;

The car variables of this class(number,speed and color) can be accessed using the dot(.) operator.

Creating an Object
The allocaton of memory of the reference type does not happen when the reference types are declared, as was the case of the primitive types, Simple diclaration of Non-primitive types does not allocate meomory space for the object.


In fact, a variable that is declared with a class type is not the data itself, but it is a

reference to the data, The actual storage is allocated to the object as follows.

Car c;
c=new Car();


The first statement just allocates enough space for the reference. The second statement allocates the space, called an Object, for the two integers and a string. After these two statements are executed, the contents of the Car can be accessed through c.

Example using Object.

Let us now write a example that creates an object of the class Car and display the

number,speed, etc....

class Car
{
    int number;
    int speed;
    String color;

    void print_Number()
   {
    System.out.println("Car Number = " + number);
    }

    void print_Speed()
   {
    System.out.println("Car Speed = " + speed);
    }

    void Stop()
    {
    System.out.println("Car Stopped");
    }

    void Horn()
    {
    System.out.println("Hooooooo.......rn");
    }

    void Go()
    {
    System.out.println("Car Going");
    }
}


public class Object_Car
{
    public static void main(String args[])
   {
    Car c;
    c=new Car();
    c.number=401;
    c.speed=90;
    c.print_number();
    c.print_speed();
    c.Horn();
    c.Stop();

    Car c1;
    c1=new Car();
    c1.number=402;
    c1.speed=80;
    c1.print_number();
    c1.print_speed();
    c1.Go();
    c1.Horn();

    }
}

Output:
>javac Object_Car.java
>java Object_Car

Car Number = 401
Car Speed = 90
Car Stopped
Hooooooo.......rn

Car Number = 402
Car Speed = 80
Hooooooo.......rn
Car Going

Do you have an Information? Add a comment with you link!
Friday, October 31, 2008

What Web Server Do?

A Web Server takes a Client request and gives something back to the Client.
A web browser lets a user request a resource. The web server gets the request,
finds the resource, and returns something to the Client Sometimes that resouce is an HTML page. Sometimes it's a picture. Or a PDF file(Data). Doesn't matter- the client asks for the resouce and server sends it back.

When we say "server", we mean either the physical machine (hardware) or the web server application (software). Real time example.



Above picture some transaction between Client House and Server House for transportation using Truck(Web Server). Client House need package (Truck Driver taking Request- URL) and pass the information to Server House. In the Server House Workers( Helper - JSP Files, Server side files) load the package into the Truck. It taking back to the Client House.

For Transportation people are using different vehicles(Airbus, Ship, Truck). Same way Web Servers(software) also diffrent products like Tomcate(Open source), Bea Web Logic, IBM Websphere,etc...

When we talk about clients, througn, we usally mean both(or either) the human user and the browse application.

The browser is the piece of software(Firefox or Opera) that knows how to communicate with the server. The browser's other big job is iterpreting the HTML code and rendeing the web page for the user.

HTTP is the protocal Client and Servers use on the web to communicate. The server uses HTTP to send HTML to the client.

The HTTP protocol has serveral methods, but the onew we'll use most often are GET and POST.

GET is te simples HTTP method, and its main job in life is to ask the server to get a resource and send it back. That resource might be an HTML page ,a PDF etc. Doesn't matter. The poing of GET is to Get someting back from the server.

POST is a more powerful request, IT' like a GET plus plus. With POST, we can request something and at the same time send form data to the server.

Web Server softwares having different tree stuctures and defalut port numbers. Weblogic running at http://localhost:7001, Tomcat at http://localhost:8080, IBM Websphere at http://localhost:9080

If you know any information about this topic please comment..
Wednesday, October 29, 2008

Java Inheritance Easy Lesson

Inheritance involves creating new classes from the existing ones. it provides the ability to take the data and methods from an existing class and derive a new class. The keyword extends is used to inherit data and methods from a existing class. the extends keyword is used as

class New_Class extends Old_Class { ....... }



The inherited methods and data are those that are declared public or protected inside the super class. Using(Extending) same Engine.

Note: private members are not inherited. Here key is private

Java Access Modifiers Lesson

Eg How Inheritance works.

class Add
{

int x;
int y;

public int Add_xy()

{
int sum=0;
sum=x+y;
return sum;

}

}
class Sub extends Add
{
public int Sub_xy()
{
int sub;
sub=x-y;
return sub;
}
}

class Inheritance
{
pubic static void main(String args[])
{
Sub sub_obj=new Sub();
sub_obj.x=10;
sub_obj.y=4;
int a=sub_obj.Add_xy();
int s=sub_obj.Sub_xy();
System.out.println("x value is "+sub_obj.x);
System.out.println("y value is "+sub_obj.y);
System.out.println("sum is "+a);
System.out.println("subtraction is "+s);
}
}

Download Source
>javac Inheritance.java

>java Inheritance

output:

x value is 10;
y value is 4;
sum is 14;
subtraction is 6;

Note : The object of the sub-class was created inside the main. The class Sub extends the class Add. This ist derives all the protected and public members of the class Add. The class Sub contains a method of it own, Sub_xy()/ The Object of class Sub in the main() is used to assign values to x and y and then the two methods are called.

Java does not support multiple inheritance directly. This means that the class in Java cannot have more than one super class.

Eg:

class Derived extends Super_one, Super_two
{
-----------------
-----------------
}


is illegal/not permitted in Java.

However, to be able to let the java programmers use the immense functionality provided by multiple inheritance, the java language developers incorporated this concept with the use of interfaces. (I will post an article about Interfaces with in few days)
Saturday, October 25, 2008

Java (JDK) Bin Directory Files Information


JAVAC.EXE
"javac" is the standard compiler in JDK.
"-sourcepath" specifies places where to search for source definitions of new types.
"-classpath" specifies places where to search for class definitions of new types.
Two types of "import" statements behave differently with "javac".
Never distribute your class files with debugging information in them.

>javac 9lesson.java

JAVA.EXE
"java" is the standard application launcher in JDK.
"-sourcepath" specifies places where to search for class definitions of new types.
"-jar" specifies a JAR file and launches the class specified in the manifest file.
"javaw" is identical to "java" except that it will not create the console window.

>java 9lesson

JDB.EXE
"jdb" is a nice debugging tool. But it only offers a command line interface, not so easy to use. It is much more efficient to use graphical interface debugger.
JPDA is well designed, allowing us to debug Java applications remotely.
Debugging multi-thread application is tricky. The following "jdb" notes may help you.
Whenever one thread reaches a break point, all other threads are stopped also.
The command prompt tells what is the current thread.
"where all" tells where the execution are currently in all threads.
"threads" lists all the threads with thread indexes as Hex numbers.

>jdb 9lesson

JAR.EXE
JAR files are ZIP files.
JAR files can have attributes stored in the META-INF/MANIFEST.MF file.
JAR files can be used in Java class paths.
JAR files can be "executable".

>jar xf src.jar

JAVAP.EXE
Used to get back the discription of bitecode:
Eg. If you deleted original source file (9lesson.java). You have only 9lesson.class file

>javap 9lesson

JAVADOC.EXE
Used to create Html file for webpage. 9lesson.java to 9lesson.html

>javadoc 9lesson.java

JVISUALVM.EXE
VisualVM is a visual tool integrating several commandline JDK tools and lightweight profiling capabilities. Designed for both production and development time use, it further enhances the capability of monitoring and performance analysis for the Java SE platform.


JRUNSCRIPT.EXE
Using jrunscript to test regular expressions

>jrunscript.exe
js> "!if:companyname[a!=b]".split(":")[0]
!if
js> "abcdef".match(/bc/)[0];
bc
js>

JAVA-RMI.EXE
If java-rmi.exe is running on your PC, you should verify that it is authentic. A file name alone is insufficient for identification. Run ProgramChecker Personal Edition and FileAnalyzer to be sure you are running the actual version.

JCONSOLE.EXE
jconsole is a GUI tool that allows you to monitor a local or remote JVM process using the JMX (Java Management Extension) technology.
JVM processes must be launched with the default JMX properties turned on in order to be connected by jconsole.
jconsole displays monitoring diagrams for heap memory usage, counts on loaded classes, counts on threads, and CPU usages.

KEYTOOL.EXE
A key entry in keystore contains a private key and a certificate of the public key.
Certificates can be exported into certificate files out of keystore.
Certificates can be imported from certificate back into keystore.
There seems be to no way to export private keys.
There seems be to no way to generate a certificate of a given public key - signing a public key.

native2ascii.exe
"native2ascii": A command line tool that reads a text file stored in a non-ASCII encoding and converts it to an ASCII text file. All non-ASCII characters will be converted into \udddd sequences, where dddd is the Unicode code value of the non-ASCII character.

"native2ascii" is an important Java tool, because Java compiler and other Java tools can only process files which contain ASCII characters and \udddd Unicode code sequences. If you have any non-ASCII character strings written in a native encoding included in your Java source code, you need to run this "native2ascii" tool to convert your Java source code.

"native2ascii" has the following command syntax:
native2ascii [options] inputfile outputfile

JSTAT.EXE
JDK 1.6 offers 3 nice JVM monitoring tools: jps, jstatd, and jstat.
jps is simple tool that allows you to list all running JVM processes on the local machine or a remote machine.
jstatd is an RMI server that allows you to access local JVM processes by jps and jstat from remote machines.
jstat is a monitoring tool that allows you to obtain sample data periodically from a local or remote JVM process.

APPLETVIEWER.EXE
We talked about how a web browser uses the applet tag to resolve and load an applet from a web server to the browsers JVM. Also, during class we commented that for development purposes, reasons for creating an extra source file. If the Appletviewer is a tool used during development, and if all that it does is scan the HTML file for the applet tag, why not include the applet tag within the Java source file as part of your program documentation.

/*
<APPLET CODE="HelloWorld.class" WIDTH=300 HEIGHT=300>
</APPLET>
*/

>appletviewer HelloWorld.java

Post your information. Please comment
Friday, October 24, 2008

Why Java is The Most Popular Language now?

Java is definitely the most popular programming language now, why? Why C,C++ and C# is not popular like Java?

Every Operating system having some executable formats
Eg. Windows - .exe, .cmd, .bat
Eg. Linux - .bin

These files operating system execute directly. Then what about .mp3,.class,.avi...... file. These files Windows can not execute directly its taking media player(Supporters) help.

Winamp software understant the .mp3 file formate. So Windows, Linux Operting System execute this file with the help of Media Players.

Same way after compile the C, C++ programs Compiler creates a executable file (.exe)

Eg : 9lessons.c ----> 9lessons.exe

Windows Operating System Directly access this 9lessons.exe file and print the output. But in Linux(os) can not understand this *.exe format. So C, C++ Dependent Languages

But Java Compiler convert .java file to .class format. Windows execute this file with the help of JRE (Java Runtime Enviroment).

Sun Microsystems Providing Different JREs for Different Operating System


Virus Programmer's Main Aim to interrupt the User's work. So the programmer creates a virus file in Operating System Executable format like .exe, .cmd, .bat (for windows)

If you did a project in C, C++ Language. If any virus attack means it damage the total executable(.exe) files. so C, C++ project files also damage. But java file creates a .class file its like byte code formate. If attact means JRE (Java Runtime Enviroment) only damage. So you java project safe....

What about .Net. It is a best software development package. Why it's not independent ?.

Microsoft People can Write the code for .Net Independent platform. If they will make the next moment onwards no one will buy the Windows Operating System.

Company business aspects they will give Preference to open source operating System like Linux and Solaris.

C, C++ --> Console application programs
Java --> Console - Windows Frames - Web

Links :
Java (JDK) Bin Directory Files Information
Analysis of a Java Class
What Web Server Do?
Google Search Architecture Diagram Overview
The Stock Market Story

Most Popular Articles:-Most Popular Articles Links

If any mistakes please comment me...
Wednesday, October 15, 2008

Java Access Modifiers Lesson

A modifiers assigns characteristics to the methods, data and variables. It specifies the availability of the method to other methods or classes. Variables and methods can be at any of the following access levels:

Default | Public | Private | Protected



public :

No doubt public variable any one can acess, class or methods are universally accessible.

Oxigen public propery...

default :

Classes can be at default level. If you do not give any explicit modifier to a variable, class or method they will be automatically treated as Default.
It means that access is permitted from any method only in classes that are members of the same package as the target.

Eg:

class 9lesson
{
int i; (Default)
}


private :

private variables or methods can be accessed only from the methods of the class to which it belongs. A subclass also does not have access to the private variables.

Debit card having security pin number

protected :

a protected variable or method is accessible from any class of the same package or from any subclass is in a different package.

This is like father and child relation.





The first class is SubclassInSamePackage.java which is present in pckage1 package. This java file contains the Base class and a subclass within the enclosing class that belongs to the same class as shown below.


package pckage1;

class BaseClass {

public int x = 10;
private int y = 10;
protected int z = 10;
int a = 10; //Implicit Default Access Modifier
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
private int getY() {
return y;
}
private void setY(int y) {
this.y = y;
}
protected int getZ() {
return z;
}
protected void setZ(int z) {
this.z = z;
}
int getA() {
return a;
}
void setA(int a) {
this.a = a;
}
}

public class SubclassInSamePackage extends BaseClass {

public static void main(String args[]) {
BaseClass rr = new BaseClass();
rr.z = 0;
SubclassInSamePackage subClassObj = new SubclassInSamePackage();
//Access Modifiers - Public
System.out.println("Value of x is : " + subClassObj.x);
subClassObj.setX(20);
System.out.println("Value of x is : " + subClassObj.x);
//Access Modifiers - Public
// If we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are private
/* System.out.println("Value of y is : "+subClassObj.y);

subClassObj.setY(20);

System.out.println("Value of y is : "+subClassObj.y);*/
//Access Modifiers - Protected
System.out.println("Value of z is : " + subClassObj.z);
subClassObj.setZ(30);
System.out.println("Value of z is : " + subClassObj.z);
//Access Modifiers - Default
System.out.println("Value of x is : " + subClassObj.a);
subClassObj.setA(20);
System.out.println("Value of x is : " + subClassObj.a);
}
}

Output

Value of x is : 10
Value of x is : 20
Value of z is : 10
Value of z is : 30
Value of x is : 10
Value of x is : 20

The second class is SubClassInDifferentPackage.java which is present in a different package then the first one. This java class extends First class (SubclassInSamePackage.java).


import pckage1.*;

public class SubClassInDifferentPackage extends SubclassInSamePackage {

public int getZZZ() {
return z;
}

public static void main(String args[]) {
SubClassInDifferentPackage subClassDiffObj = new SubClassInDifferentPackage();
SubclassInSamePackage subClassObj = new SubclassInSamePackage();
//Access specifiers - Public
System.out.println("Value of x is : " + subClassObj.x);
subClassObj.setX(30);
System.out.println("Value of x is : " + subClassObj.x);
//Access specifiers - Private
// if we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are private
/* System.out.println("Value of y is : "+subClassObj.y);

subClassObj.setY(20);

System.out.println("Value of y is : "+subClassObj.y);*/
//Access specifiers - Protected
// If we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are protected.
/* System.out.println("Value of z is : "+subClassObj.z);

subClassObj.setZ(30);

System.out.println("Value of z is : "+subClassObj.z);*/
System.out.println("Value of z is : " + subClassDiffObj.getZZZ());
//Access Modifiers - Default
// If we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are default.
/*

System.out.println("Value of a is : "+subClassObj.a);

subClassObj.setA(20);

System.out.println("Value of a is : "+subClassObj.a);*/
}
}

Output

Value of x is : 10
Value of x is : 30
Value of z is : 10

The third class is ClassInDifferentPackage.java which is present in a different package then the first one.


import pckage1.*;

public class ClassInDifferentPackage {

public static void main(String args[]) {
SubclassInSamePackage subClassObj = new SubclassInSamePackage();
//Access Modifiers - Public
System.out.println("Value of x is : " + subClassObj.x);
subClassObj.setX(30);
System.out.println("Value of x is : " + subClassObj.x);
//Access Modifiers - Private
// If we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are private
/* System.out.println("Value of y is : "+subClassObj.y);

subClassObj.setY(20);

System.out.println("Value of y is : "+subClassObj.y);*/
//Access Modifiers - Protected
// If we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are protected.
/* System.out.println("Value of z is : "+subClassObj.z);

subClassObj.setZ(30);

System.out.println("Value of z is : "+subClassObj.z);*/
//Access Modifiers - Default
// If we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are default.
/* System.out.println("Value of a is : "+subClassObj.a);

subClassObj.setA(20);

System.out.println("Value of a is : "+subClassObj.a);*/
}
}

Output

Value of x is : 10
Value of x is : 30



Please Comment...
Tuesday, September 30, 2008

Analysis of a Java Class

When the JVM(Java Virtual Machine) starts running, it looks for the class you give it an the command line. Then its starts looking for a specially-written method that looks exactly like:


public static void main(String args[])

{
//your code......
}


Next, the JVM runs everything between the curly braces{} of your main method. Every Java application has to have at least one Class, and at least one main method (not one main per class; just one main per application).



In Java, everything goes in a class. Your'll type your source code file (with a .java extension), then compile it into a new class file (with a .class extension). When your run your program, you're really running a class.

Running a program means telling the Java Virtual Machine (JVM) to "Load the 9lessons class, then start executing its main() method. Keep running till all the code in main is finished.

The main() method is where your program starts running.

9lessons.java

public class 9lessons

{

public static void main(String[] args)

{

System.out.println("Programming Blog");

}

}



step 1: javac 9lessons.java

step 2: java 9lessons

The Big Difference Between public class and Default class

9lessons.java

public class program

{

public static void main(String[] args)

{

System.out.println("Programming Blog");

}

}


Above programe file name is (9lessons.java) and public class name (program) is different



Error : Class program is public, should be declared in a file named program.java

So public class means file name and class name must be same..

Here Default Class(no public)

9lessons.java

class program

{

public static void main(String[] args)

{

System.out.println("Programming Blog");

}

}




After compiling 9lesson.java creates program.class



In the Defalult class no need to give file name and class name same..

step 1: javac 9lessons.java

step 2: java program

If any mistakes please comment me..

Related Articles:

Connecting JSP To Mysql Database Lesson

Web.xml Deployment Descriptor
Tuesday, September 23, 2008

Web.xml Deployment Descriptor

Web.xml mapping servlet names improve web app's flexibility and security..The deployment descriptor (DD), provides a "declarative" mechanism for customizing your web applications without touching source code!

Tomcat Directory Structure

Login.java


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Login extends HttpServlet{

public void doGet(HttpServletRequest request,
HttpServletResponse response)throws IOException{

PrintWriter out=response.getWriter();
java.util.Date tody=new java.util.Date();
out.println("out put html tags");

}
}


<servlet>Maps internal name to fully-qualified class name.


<servlet-mapping>Maps internal name to public URL name.

web.xml



<servlet-mapping> which servlet should i invoke for this requested URL?


<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd" version="2.4">

<servlet>
<servlet-name>Servlet_login</servlet-name>
<servlet-class>Login</servlet-class>
</servlet>

<servlet>
<servlet-name>Servlet_inbox</servlet-name>
<servlet-class>inbox</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>Servlet_login</servlet-name>
<url-pattern>/signin.do</usr-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Servlet_inbox</servlet-name>
<url-pattern>/view.do</usr-pattern>
</servlet-mapping>

</web-app>


signin.do file mapping to Login.class. So the client or users to get to the servlet.. but it's a made-up name that is NOT the name of the actual servlet class.
mailxengine Youtueb channel
Make in India
X