Showing posts with label Tutorials. Show all posts
Showing posts with label Tutorials. Show all posts

Saturday, November 9, 2019

Benefits of Spring Framework

Benefits of Spring Framework in Java

Spring Framework's fundamental mission is to simplify Java development. 

Four key strategies which Spring  uses for simplifying java development are :

1. Lightweight nature of Spring and non invasive POJO development.
2. Using Dependency Injection for Loose coupling.
3. Declarative programming through aspects.
4. Boilerplate code is eliminated with aspects and templates 


Spring is Light weight .Spring provides different modules and allow us to use any one based on the requirement, Ideally the spring jar is just 2-3 MB. 

Increasing the power of Non Invasive Pojos.
While using most of the frameworks during java development like Struts 1  and Ejb 2, we have to extend framework related classes or implement interfaces. This makes our Java beans coupled up with the framework decreasing its re-usability. Spring avoids (as much as possible) littering your application code with its API

While using Spring we are not forced to implement a Spring-specific interface or extend a Spring-specific class. Although these Spring POJOs are very simple but can be powerful through the use of Dependenct Injection and AOP. 



For Training Check my Website Online Spring Framework Training From India 











Tuesday, November 5, 2019

Rock Paper Scissors Java Program Code

Developing Rock Paper Scissors Game using Java

In this example we are going to develop a Rock Paper Scissors Game using Java. Developing games while learning java enhances our programming skills.

The Rule of the Game are as follows:

  1. Rock beats Scissors.
  2. Scissors beats Paper.
  3. Paper beats Rock.
  4. Who ever wins 5 times first is the Winner.
  5. In this example the game will be between a user and the computer.





Learn Core Java Properly through my Private Core Java Online Training to be able to write games in java easily.

Rock paper Scissors Java Program Video Tutorial


Steps of the Rock Paper Scissors Java Program

  1. We will create a class Player.java that represents the user who is going to play the game with the computer.
  2. The class Computer.java represents the Computer that is playing with the user.
  3. Driver.java is a helper class containing the Rock Paper Scissor constant variables and the business logic code.
  4. RPS.java is the class containing the main function where the program execution will begin.
  5. We will ask the user to enter his name. Then select one among ROCK PAPER SCISSORS.
  6. Then we will let the computer randomly select ROCK PAPER SCISSORS.
  7. We will use the business logic function to find out who wins. And every time we will display the selections made and who won.
  8. The user can decide to end the game any time.
  9. We will keep a track of who wins 5 times first. And then display the winner.

Player.java will represent the User playing with the computer.



Sunday, March 27, 2011

Important Servlet Interview Questions

1) Servlet Life Cycle?
2) How can you extract configuration information from web.xml inside your servlet?
3) How can you use ServletContext object to share information among servlets?
4) Difference between using response.sendRedirect() and requestDispatcher object for forwarding from one servlet to another? Which one should be used and when?
5) What are the different ways to do session management in servlets?
6) How do u implement urlrewriting,hiddenfields,cookies and HttpSession objects?
7) How to send session identifier to client machine if cookie is disabled? Hints response.encodeURL() method.
8) What are the use of servlet filters.
9) Interfaces implemented to create a filter?
10) What is the difference between doFilter() method of Filter interface and doFilter() method of FilterChain interface?
11) How to use Servlet Listener to create a website counter, and how to use it to show how many users are online?


Click for Private Tuition by a Professional 

Important Jsp Interview Questions

1) Advantage of Jsp over Servlets.
2) Jsp Life Cycle?
3) Packages & Interfaces used When pagecompiler Servlet converts Jsp into Servlet?
4) What are Implicit Objects in Jsp?
5) What are the elements present in a jsp code apart from template data?
6) What are three types of directives used in jsp?
7) Difference between Scriptlet, Declarations and Expressions?
8) What are the different Action elements?
9) What is the difference between static include and dynamic include?
10)What are the different comments used in jsp?
11)What are the different scopes in which you can place bean objects?
12)When should we use Java Beans and when should we use custom tags?


Click for Private Tuition by a Professional 

Sunday, March 20, 2011

What is Call by Value & Call by Reference in Java-Swap Example-Java Interview Queston

Call By Value

Definition: It is a type of function call wherein the argument passed is of a primitive data type and the value of the argument gets copied to the parameter of the function and in the function definition even if we are swapping the values of the parameter we are actually swapping the copies of the argument not the actual argument.

Example


Call By Reference 

Definition: The argument passed in this type of function is an object type and not a primitive data type. Using call by reference the modifications can be done on the actual arguments because the references of the arguments are passed during the function call. 

Example

For details regarding Online Java J2ee Training please visit www.javatutoronline.com

Jsp FreeMarker Velocity What should be used?


Although you can do mainly most of the view part through jsp there are enough reasons to use Velocity and/or FreeMarker.

Both Velocity and FreeMarker templates can be packaged in a JAR. Struts plugins are distributed through JAR. One cannot distribute JSP's in JAR that easily. This can be one of the reasons why Velocity or FreeMarker may be used. FreeMarker is more advanced then Velocity. So FreeMarker gets the upper hand. Even WebWork developers have switched from Velocity to FreeMarker.




Saturday, March 19, 2011

Struts2 FilterDispatcher and its Working



A FilterDispatcher is used as the Controller in Struts2. Its name in packaged Structure is org.apache.struts2.dispatcher.FilterDispatcher. Prior to using it in the application, it has to be registered in the web.xml as below.



     
The task processing going to be done in the FilterDispatcher is splitted into several subcomponents called interceptors. One of the first interceptor will be used to populate the action object.

The action method in a struts application is executed only after the properties of struts action is populated.

A String value is returned by the method of a struts action. And depending upon the returned value, the page to which control is forwarded is decided.

The view to which the action forwards need not necessarily a jsp

At first the FilterDispatcher verifies the request URI and determines the right action for it.
The mappings of  URI’s and the action classes are present in the struts.xml file found in the WEB-INF/classes directory.

FilterDispatcher does the following for eact action invocation.

1)Determines which action to invoke for a requested URI by consulting the Configuration manager
2) Interceptors registered for the action are invoked one after the other.
3)Then the action method is executed.
4)Then the FilterDispatcher executes the Result.




For details regarding Java J2ee Online Training please visit www.javatutoronline.com



Sunday, June 14, 2009

Important Struts Interview Questions

Important Struts Interview Questions
1) What is struts and what does struts constitute of?
2) What is ActionServlet?
3) Explain control flow in struts.
4) What are the tld files that comes packaged with struts?
5) What is ActionForm class?
6) What are Action class?
7) Difference between ActionServlet and Action class?
8)How data flows from user interface to the model layer and how does it come back to the view layer ?
9) What is struts-config.xml?
10) How to write action mapping?
11)What is the use of the properties file in struts?
12)How do we use validator framework?

Click for private tuition by a professional

Getting Database Connection Using JNDI and JDBC Datasource in Tomcat


Tomcat 5 provides a JNDI InitialContext implementation instance for each web application running under it, in a manner that is compatible with those provided by a Java2 Enterprise Edition application server. The J2EE standard provides a standard set of elements in the /WEB-INF/web.xmlfile to reference resources; resources referenced in these elements must be defined in an application-server-specific configuration.
For Tomcat 5, these entries in per-web-application InitialContext are configured in the elements that can be specified in either$CATALINA_HOME/conf/server.xml or, preferably, the per-web-application context XML file (either META-INF/context.xml).
The InitialContext is configured as a web application is initially deployed, and is made available to web application components (for read-only access). All configured entries and resources are placed in the java:comp/env portion of the JNDI namespace, so a typical access to a resource - in this case, to a JDBC DataSource - would look something like this:

// Obtain our environment naming context
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");

// Look up our data source
DataSource ds = (DataSource) envCtx.lookup("jdbc/EmployeeDB");

// Allocate and use a connection from the pool

Connection conn = ds.getConnection();
... use this connection to access the database ...

conn.close();


To configure Tomcat's resource factory, add an elements like this to the $CATALINA_HOME/conf/server.xml file, nested inside the Context element for this web application.
...

<Resource name="jdbc/db1"
auth
="Container" type="javax.sql.DataSource"
maxActive
="100" maxIdle="30" maxWait="10000" username="root"
password
="anu" driverClassName="com.mysql.jdbc.Driver"
url
="jdbc:mysql://localhost:3306/DB1?autoReconnect=true" />


Click for private tuition by a professional

Saturday, June 13, 2009

Using Free Custom Html Editor in Jsp FCK Editor

One of the best free html editor that we can incorporate in our jsp website is the FCK Editor.








We have to download the Java integration package from FCK editor site. Then place the jar files in our lib folder of our jsp application.
Then download the FCK editor and create a folder in our application in the root directory and place the FCK editor folder.
Then Place the FCK tld file in the WEB-INF folder and place the taglib directive in the jsp page where you want to use the editor.

Click for private tuition by a professional

Friday, June 12, 2009

Free Hadoop Tutorial Links



http://wiki.apache.org/hadoop/
http://pages.cs.brandeis.edu/~cs147a/lab/hadoop-example/
http://ebiquity.umbc.edu/.../hadoop-on-windows-with-eclipse/ 
www.cs.virginia.edu/~cbs6n/hadoop/HadoopTutorial.ppt


Thursday, June 11, 2009

Free Tutorial Ejb Ql For Jboss

How to Run Java Program involving Packages by Setting Classpath

Packages and Classpath:

Lets see how to compile a Java program using packages from command line

First we created a folder 'Pac1' in D: drive.Inside 'Pac1' we created another folder called 'Pac2' and inside 'Pac2' we created another folder called 'Pac3'

Java Program : Write or copy the following code in notepad and save the file as A.java

A.java
package pac2.pac3;


Class A
{
public static void main(String[] args)
{
System.out.println("Welcome to Packages");
}
}



Method-1: Executing Java program using packages
through command line


Go to Command Prompt

For compiling Java Program:

D:\Pac1>javac Pac2\Pac3\A.java
So here we have to go to the root folder to compile the program

For running/executing the java program:

D:\Pac1>java Pac2.Pac3.A
Welcome to Packages //Output displayed

The above method will not work unless the class path has a '.' in the classpath of environment variables.See below how to set the classpath


Setting the CLASSPATH:
Definition: Classpath is that environment variables which Java thinks contains the root of the package hierarchy
i.e Java starts to search from all the paths that is present in classpath

Go to Start> Right Click My Computer>Properties>Advance System Settings>Click Environment variables>Edit the Classpath
Add the (.;) in the beginning of classpath

(.;) : The '.' (Dot) will tell Java to search for the Java program from the current folder



Method-2:
Executing Java program using packages through command line


Instead of going through all the above process.There is a easier method to set the classpath in environment variables

Go to Start> Right Click My Computer>Properties>Advance System Settings>Click Environment variables>Edit the Classpath
Add 'D:\Pac1;' in the beginning of classpath

This is telling Java to start search from 'D:\Pac1' folder, even if you somewhere in E or F or other drive or folder

This will allow you to run the Java program from any drive or folder from the command line

Click for private tuition by a professional

Very Useful & Important Eclipse Shortcuts

syso + ctrl+ space--------------->System.out.println("");

ctrl + shift+ L-------------------->Shows all the Eclipse ShortCuts to the right bottom of eclipse window.

ctrl + shift+ T-------------------->Helps to search or look for any inbuilt classes interfaces or user defined classes or interfaces in eclipse workspace.

alt + shift+ R--------------------->Renaming any class,interface.

ctrl+3----------------------------> Very useful eclipse shortcut. You can do any thing using the shortcut. Once you pressed the keys a window appears where u can type like(" new project" or compile class) anything you want to do and eclipse will guide you.

ctrl+shift+f--------
---------------> Helps in formating. Or makes the code indended.


Click for private tuition by a professional