- Create a application(user-defined) folder inside the webapp folder of tomcat. let it be MyProject.
- Create a WEB-INF folder inside your application folder(inside MyProject folder).
- Create classes folder inside WEB-INF folder.
- Create a servlet program with .java extension like HelloServlet.java.
- Copy the path C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\servlet-api.jar where c: drive tells that tomcat is installed in c derive and 7.0 is version of tomcat i.e it is the path of servlet-api.jar file which is atomatically created in lib folder after installing tomcat.Because the set of classes required for writing servlets is available in a jar file called servlet-api.jar
- Paste above copied path under My computer->properties->Advanced->Environmental variable->System variable->classpath->Edit-> paste under variable value.
- Copy the path C:\Program Files\Java\jdk1.6.0\bin; and paste it under My computer->properties->Advanced->Environmental variable->System variable->path->Edit-> paste under variable value. It tells that it is the path where the java copiler is created after installing jdk(java development kit).
- Now copile the created HelloServlet.java file with the help of Command prompt as file path then javac HelloServlet.java. A class file is created now where HelloServlet.java file compiled.
- Copy the class file of HelloServlet.java program file.
- Paste it inside the classes folder of Step 3.
- Create a web.xml file with servlet name,URL and servlet mapping,URL of above HelloServlet.java program inside the WEB-INF folder of step 2.
- Run tomcat with path Start-> Control Panel-> Performance and Maintenance-> Administrative Tools -> Services-> Apache Software Foundation OR C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin and double click on tomcat(service runner) OR Start->Programs->Apache Tomcat 6.0 -> Monitor Tomcat. You will notice an icon appear on the right side of your Status Bar. Right click on this icon and click on Start service.
- open Browser and type URL as localhost:8080/ MyProject/ url specified in web.xml file. MyProject is application folder name created in step 1.
- .As you will enter this URL,You will see that your HelloServet.java on Browser.
Aptitude
(12)
C
(2)
C++
(10)
CSS
(1)
Data Structure
(2)
English
(6)
Fitness
(2)
General
(14)
HTML
(3)
Integration
(1)
Itinerary and Travel Cost
(2)
Java
(29)
JQ
(5)
JS
(5)
JSP
(1)
Lightning
(14)
logical
(3)
Lyrics
(1)
Math
(1)
Music Notation
(20)
MySql
(4)
Network
(1)
Regex
(1)
salesforce
(131)
Servlet
(4)
SF Admin
(31)
SF Dev
(102)
Spiritual Content
(3)
SQL
(4)
SQL_SERVER
(1)
StudyPoints
(2)
Trips
(1)
ytChannels
(2)
अन्ताक्षरी
(4)
A Process to run a servlet hello program
Types of methods
1.Concrete method
- A method having the signature and body contents and can be used and overridden in child class.By default all methods are concrete.
- A method having the signature but no body contents
- Such methods can be declared at two places
i. Abstract class
ii. Interface
- If declared inside an abstract class then use abstract keyword with the methods.
- If declared inside an interface, no keyword is required, since all methods inside an interface are public and abstract by default
- Such methods are always overridden by child class
- A method that can never be overridden is called as final method
b. Use final keyword to declare such methods
Types of classes
If we can create an object(instance) of a class then that class is called instantiated.
Inherited mean we get all the functionality (all of attributes, properties, and methods) of that class which is inherited to new class.
In java there are three types of classes----
1.concrete class:A class that can be instantiated and also can be inherited is called as concrete class.
All class are by default concrete.
2.Abstract class: A class that can never be instantiated and can be inherited is called as abstract class.
Such classes must have abstract keyword associated with them.
3.Final class: A class that can be instantiated and can never be inherited is called as final class.
Use final keyword to make such a class.
User defined type
User defined type is a way from which help an user can create variables of own type.
There is two way for creating user defind data type:
1. Using typedef keword
2. Using enum keyword(enumerated data type).
1.typedef----
typedef existing_data_type new_userdefined_type;
e.g
typedef int krish;
krish a,b,c;/* a,b,c are integer variable*/
we can further use keyword typedef to create new data type from datatype being used as:
typedef krish kg;
kg l,m; /* l,m are integer variable*?/
typedef with structures:
typedef struct class
{
……..
……..
} my;
function()
{
class var1,var2; /*simple object declaration*/
my var3; /*declaration using dublicate datatype i.e user type*/
}
2.Enumerated datatype:
Enum cricket(sachin,rahul,shehbag,…..,dhoni);
cricket a,b,c;
a=sachin; /*valid*/
b=10; /*invalid*/
c=jaysurya; /*invalid*/
Concept of class
Storage_class struct user_defined_name
{
datatype1 member1;
datatype2 member2;
.......... .............
......... .............
};
above declaration is the general format of a simple structure declaration in C.
where Storage_class refers to the scope of stucture variable it may automatic,resister,static or external.
struct is a keyword which shows the start of a structure.
user_defined_name is structure name defined by the user.
structure is a collection hetrogenous(different) type of data.structure declaration forms a template that
may be used to create structure objects(i.e instances of a structure).
once the structure type has been defined,we can create variables of that type usingdeclarations that are similar to the built-in type
declarations.
e.g
strucrt home
{
char name[10];
int age;
float income;
} father,mother,son,daughter;
OR
struct home father,mother,son,daughter;
where father ,mother,son,daughter are sturcture variables.
member variables(name,age,income) can be accessed by using dot or period operator as follows:
strcpy(father.name,"OM");/* or father.name="OM";*/
father.age=49;
father.income=15625.750;
strcpy(son.name,"Krishna");
son.age=21;
son.income=659.41;
limitations of C structure:
Ø C does not allow the struct data type to be treated like built-in types.
e.g
struct home
{
float a;
float b;
}s1,s2,s3;
ü s1,s2,s3 can easily be assigned values using the dot operator,
but can not be added or subtracted one from other as:
s3=s1+s2;
is illegal in C.
Ø Another important limitation of C structures is that they do not permit data hiding .
ü Structure members can be directly accessed by structure variables by any function anywhere in their scope i.e structure members are public members.
Extensions to Structures:-
In C++ we expended C structure as
ü C++ structure can have both variables and functions as members.
ü C++ structure can also declare some of its members as ‘private’, ’public’ or protected.
ü The keyword strucrt can be omitted in the declaration of structure variables. e.g we can declare home variable father as:
home father; //this is valid in C++ and make an error in C
ü C++ expended structure capabilities to suit OOP philosophy (abstraction, encapsulation, polymorphism, inheritance )
C++ incorporates all above extensions in another user-defined type known as class.
Most of C++ programmers tend to use the structure for holding data type,and classes to hold both data and functions.
The only difference between a structure and a class in c++ is that,
· By default,the members of a class are private.
· By default ,the members of a structure are public.
In Java the concept of structure is totally eliminated and the concept of class is implemented , also some modifications in the concept of class have done.
Tweet
Tweet
Default argument
In C++ we can call functions without specifying its all arguments.
- A default argument is checked for type at the time of declaration.
- Default argument evaluated at the time of Call.
- We must add default value of argument from Right to Left.
int function(int a,int b=9,int c=3) //Valid
int function(int a,int b=7,int c) //Invalid
int function(int a=4,int b=9,int c) //Invalid
int function(int a=6,int b=9,int c=3) //Valid
Mamory allocation n deallocation
As in C,malloc(allocates the specified number of bytes),calloc( allocates the specified number of bytes and initializes them to zero),realloc((Resize to the specified block of memory,if needed) and free(releases the specified block of memory back to the system) are used for mamory allocation and deallocation.
In c++ and java new operator is used to allocate memory,it atomatically take size of datatype which are going to be create,and initilize that with the help of constructor. For deallocating the memory deleate operator is used,it detroys the memory with the help of decunstructor.
TweetIn c++ and java new operator is used to allocate memory,it atomatically take size of datatype which are going to be create,and initilize that with the help of constructor. For deallocating the memory deleate operator is used,it detroys the memory with the help of decunstructor.
Subscribe to:
Posts (Atom)