Thursday, December 31, 2009

HAPPY NEW YEAR 2010

 


                      I WISH YOU

                                  A

                 HAPPY NEW YEAR
                              2010
                                                  By
                                               Mallik

Tuesday, December 22, 2009

WEB 3.0



The next generation of the web is WEB 3.0 .
The applications will make the user to feel comfortable and easier.


Many of the experts believe that the Web 3.0 browser will act like a personal assistant. In web 3.0 as you search the Web, the browser learns what you are interested in. The more you use the Web, the more your browser learns about you and the less specific you'll need to be with your questions. Eventually you might be able to ask your browser open questions like "where should I go for lunch?" Your browser would consult its records of what you like and dislike, take into account your current location and then suggest a list of restaurants.


The third web 3.0 search engines will take a great revolution in the web. The web 3.0 search engines searches phrases along with the words. This will act like human brain to summarize the results obtained by it.


As you heard the word web 3.0 you may think like what is web 1.0 or what is web 1.0 .


The term web 2.0 is coined by O'Reilly media. After knowing web 2.0 word people used to think about web 1.0 . With out confusion these terms are purely related to the web.


Web1.0 :
Web 1.0 is just like a library from there user can read the information and view the images. For the web 1.0 applications you cannot contribute the information.


Web 2.0:
Web 2.0 allows user to interact with the content on the web and he can share his content on it. The user will get rich experience with web 2.0.


As per the experts the web 3.0 should give every thing by depending on your like and dislikes. As per conversation this might look interesting and it may give good feel to visualize but it will give the headache for the experts while designing and developing.


Julie & JuliaJulie & Julia [Blu-ray] To Wong Foo Thanks for Everything Julie Newmar   The Sound of Music (Two-Disc 40th Anniversary Special Edition)

Monday, December 21, 2009

WEB 2.0



Web 2.0 is commonly used term in the software industry. Most of the people search in the web for this word. Most of the people tries to know about this word. why?


The term Web 2.0 purely related to the web application/Internet applications. As per Wikipedia "A Web 2.0 site allows its users to interact with other users or to change website content, in contrast to non-interactive websites where users are limited to the passive viewing of information that is provided to them".




The web 1.0 applications are the applications which gives information to the user but it won't interact with the user decision. In web 2.0 applications user interacts with the application and he share his decisions, he can own data and he can have control over data .


Web 2.0 sites may have an "Architecture of participation" that encourages users to add value to the application as they use it. Some people calls Web 2.0 as the “participatory Web” and Web 1.0 as “Informatory Web”.

Tuesday, December 15, 2009

Where we need to Store images, in SQL database or in separate folder while development?

These two ways are OK. My suggestion is to store images into sql database if there are no much more images, otherwise, it's better store them into file system because you can store them no matter how many there are.

Advantages of Storing BLOB Data in the Database:

Storing BLOB data in the database offers a number of advantages:
It is easier to keep the BLOB data synchronized with the remaining items in the row.
  1. BLOB data is backed up with the database. Having a single storage system can ease administration.
  2. BLOB data can be accessed through XML support in SQL Server 2005, which can return a base 64–encoded representation of the data in the XML stream.
  3. SQL Server Full Text Search (FTS) operations can be performed against columns that contain fixed or variable-length character (including Unicode) data. You can also perform FTS operations against formatted text-based data contained within image fields—for example, Microsoft Word or Microsoft Excel documents.
Disadvantages of Storing BLOB Data in the Database:
Carefully consider what resources might be better stored on the file system rather than in a database. Good examples are images that are typically referenced via HTTP HREF. This is because:
  1. Retrieving an image from a database incurs significant overhead compared to using the file system.
  2. Disk storage on database SANs is typically more expensive than storage on disks used in Web server farms. 
 Storing Image in a folder:
Storing Image in a folder and using URL or relative path in the database is the way I would recommend. They are having many advantages and here are some of them.
  1. Normally sql server space is more expensive than ordinary disk space in hosting environment.
  2. You can name images in a Search Engine optimized way
  3. Essay to manage, backup and restore images and database.
  4. More suitable for static pages, (if you optimize some pages for performance).

As per my opinion  storing images in the folder is more acceptable.

Saturday, November 7, 2009

Read Image into JSP




In the last post i explained about the reading of image from database to jsp file. This jsp will writes the image as it is in the uploaded size into the jsp. In that case you are fowarding byte array to the jsp and you are writing that byte array in the jsp.
You can also get the image from the database by specifying the action in the src attribute of the image tag as in the below tag.

<img height="600" width="500" src="readImage.do" id="image"/>

In this case the acion will get the byte array of the image from the database and you need to write that byte array into the response as show below....

byte imageArray[] = dao.readImage(imageid);
OutputStream output = response.getOutputStream();
output.write(imageArray);
output.close();

Using output stream you are writing the image array to response this will display the image in the jsp/browser.

In this case you can display the image size as you wish by specifying the height and width.

How to write image into jsp?




WriteIamge.jsp


<%
byte[] imagedata=(byte[])request.getAttribute("imageData");
OutputStream output = null;
if(imagedata!=null){ response.setContentType("image/gif"); try{
output = response.getOutputStream();
output.write(imagedata);
out.clear ();
out = pageContext.pushBody ();
}
catch(Exception e)
{
System.out.println("ERROR OCCURED IN Image jsp");
e.printStackTrace();
}
finally
{
output.flush();
output.close();
}
}else{
out.println("Image not available");
}
%>

How to Upload Image into data base using Spring




Using Multipart Resolver:

To work with images or files with spring you should use the multipart resorver. There are two multipart resolvers in the spring
  •       CommonsMultipartResolver: you need commons-fileupload.jar to work with this resolver.
  •       CosmultipartResolver : You need Cos.jar to work with resolver.
Apart from these jar files add the dependent jar files also into the application.
You can specify the maximum size of the image in the bits with the <property /> tag under the <bean > tag.
<bean id="multipartResolver"class="org.springframework.web.multipart.              commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
  <property name="maxUploadSize" value="100000"/>
</bean>
                             (or)


<bean id="multipartResolver" class="org.springframework.web.multipart .cos.CosMultipartResolver">
                       <!-- one of the properties available; the maximum file size in bytes -->
                        <property name="maxUploadSize" value="100000"/>
</bean>


uploadfile.jsp:

Create the jsp to upload the image. The form enctype should be 'multipart/form-data' and use the file tag to get the browse option in the page.
<html>
<head>
         <title>Upload a file Example</title>
</head>
<body>
        <h1>Browse a file</h1>
        <form method="post" action="upload.form" name='uploadForm'   enctype="multipart/form-  data">
             <input type="file" name="file"/>
             <input type="submit"/>
         </form>
</body>
</html>


Form Bean:

Write the Bean class for the fileUpload.jsp. You can specify the file data type as MultipartFile or byte or
public class FileUploadBean {
private MultipartFile file;
public void setFile(MultipartFile file) {
this.file = file;
}
public MultipartFile getFile() {
return file;

}
}

FileUploadController.java:

Read the image using the controller class.
public class FileUploadController extends SimpleFormController {
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws ServletException, IOException {
// cast the bean
FileUploadBean bean = (FileUploadBean) command;
MultipartFile file = bean.getFile();
if (file == null) {
System.out.println("Unable to rad the image from Jsp");
}
//While writing it into data base if you want to use in the byte array you can convert it
byte imageArray[] = file.getBytes();
//once you got the byte array you can save it in database get the database connection
//save it in the database


return super.onSubmit(request, response, command, errors);
}
}


Configuring in Dispatcher Servletxml:

<beans>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
               <property name="mappings">
                      <value>
                              /upload.form=fileUploadController
                    </value>
        </property>
</bean>
<bean id="fileUploadController" lass="examples.FileUploadController">
               <property name="commandClass" value="examples.FileUploadBean"/>
               <property name="formView" value="fileuploadform"/>
               <property name="successView" value="confirmation"/>
          </bean>
</beans>

Monday, October 26, 2009

How to get selected text from the dropdown ?


The below function explains how to get selected text of the drop down menu using javascript.


function getSelectedText(){
     var subText = document.getElementById("subject");
     var selectedText = subText.options[subText.selectedIndex].text
     alert(selectedText);
}
"subText.selectedIndex" gives index of the selected value, By passing that index value to array of the subtext options you will get the selected text from the drop down menu.


Monday, October 12, 2009

Java Try catch block


 /**
 *
 */
package com.myapp.testpackage;


/**
 * @author sunil.chand
 *
 */
public class Exc1 {
  public static void main(String args[]){
      int d,a;
      try{
          d=0;
          a=42/d;
          System.out.println("never printed");
      }
      catch (ArithmeticException e){
          System.out.println("Division by zero not possible"); 
      }
            
  }
}

Monday, October 5, 2009

Struts2 Eclipse plugins

               Struts2 is the Java based framework developed by Apache. This is combination of Struts1.x and the webwork.
              I feel, to develop Struts2 based applications using the Eclipse ide is little bit easy and comfortable. So that i searched for the plugins for eclipse ide. Generally you can dump the struts2 jar files in lib folder of the web application and use the struts2 functionalities.
As we know, plug ins provide the extra functionality in the development.
These are the two links which i felt food.


and



find the installation procedure,  license and terms and conditions over the sites and enjoy the development of Struts 2 applications.


All the best.............

Friday, September 25, 2009

MVC Design pattern with Struts.

Struts Framework:(1.3 version)
Struts is MVC based framework developed by Apache. Framework generally provides the basic functionality for a project. Struts provides the set of Action classes, set of tag-libraries, set of Form beans and etc.
Struts combines the most of the design patterns in to a single framework. Struts implements the Single-ton design pattern, Delegate design pattern, Factory Design pattern, Chain of responsibilities.
Struts is Strongly Model View Controller (MVC)based framework MVC fallows the three tier architecture. The model, view and controllers regarding to the Struts are explained as fallows.

View:
View is used to show something to user. Struts allows to use htmls, jsps as view components. To develop the more friendly views struts provided the set of tag libraries. You can download these libraries from the apache site and you can use those into your view components. The set of tag libraries are
struts-html : These tags are replacement of normal html tags. The struts html tags are binds with the form bean properties.
Ex: <html:text property=”userName” />
tag replaces the normal html tag like
<input type=”text” name=”userName” />
struts-bean : These tags are replacement for the jsp action tags. The bean properties are defined with this tags, you can get the bean properties using struts-bean tags.
Ex: <bean:define id=”tempVar” value=”10” />
Above tag defines a variable as 'tempVar' and assign 10 to it as string value.
<bean:write name=”Employee” property=”empId” />
Above tag get the value of empId from the Employee form bean.
Struts-logic: These tags are used to write the logical operations. To validate the if conditions or equals conditions you can use these tags.
Ex: <logic:equal name=”empId” value=”100” >Adimin</logic:equal>
Admin is displayed when the empId equals to 100 only.
To get the for loop type iterations you can use the <logic:iterate /> tag.
struts-nested: To display the group of objects you can use the nested tags.
You can implement most of the functionality of above three tags with the nested tags.
Inplace of <bean:write /> you have <nested:write /> and so on.......

Model:
Business logic and persistence logic (database dependent logic) will be developed in Model. In struts you can use normal Java beans, DTOs, Dos as models. You can develop the Model layer using other tools also. Struts allows to use Hibernate, spring in the model layer.

Controller:
Controller is most important concept in the Struts 1.3. In struts ActionServlet acts as Front controller. Each and every request must passes through the ActionServlet. You can change the ActionServlet functionality by extending ActionServlet to your own class.

RequestProcessor class also acts as the controller to process the request. In struts 1.3 Request processor is the ComposableRequestProcessor. It has processXXX() methods. These methods are controls the execution of action classes, controlling of form beans ..etc.

Actions, Dispatch actions, Action Forms , Validator forms ..etc all are come under the controller.


Difference between Struts html tags and normal html tags


What is the difference Normal HTML tags and Struts HTML tags in the way of performance?

Apache struts provided the struts html tags as the replacement of normal html tags for the Jsps. These Struts html tags are directly bind to the form bean using ActionForm where as normal html tags cannot bind with form beans. HTML tags are static but Struts tags are Dynamic (At the run-time struts tags are called)


But coming to performance half of the code in struts tags is pre-compiled one. If we use normal html tags web container has to load the jsp from the scratch. Where as struts tags loads with the pre-compiled code. So that struts tags improves the performance.




Thursday, September 24, 2009

Inner classes in Java

There are four types inner classes in Java. Those are
1. Regular Inner classes
2. Method-local inner classes
3. Anonymous inner classes
4. Static nested classes.

Javascript Dynamic row Addition

Please copy this code and create as test.html and see the functionality
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function addRow(div,value,x){

var ni = document.getElementById(div);
var numi = document.getElementById(value);
var num = (document.getElementById(value).value -1)+ 2;
numi.value = num;

var divIdName = "my"+num+x+"Div";
var newdiv = document.createElement(div);
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "<table width=\'100%\' class=\'listTable\' >"
+"<tr class=\'listTR"+(num%2)+"\' onMouseOver=this.style.backgroundColor=\'DEDEBE\' onMouseOut=this.style.backgroundColor=\'\'>"
+"<td><input type='text' name='studNo'/></td>"
+"<td><input type='text' name='studName'/></td>"
+"<td><a href=\"javascript:;\" class=\"menu\" onclick=\"removeEvent(\'"+divIdName+"\',\'"+div+"\')\">Remove</a></td>"
+"</tr></table>";
ni.appendChild(newdiv);
}
function removeEvent(divNum,div){
var d = document.getElementById(div);
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}
</script>
</head>
<body>
<form action="">
<table>
<tr bgcolor="#737328"><td>
<table>
<tr><td>Student No</td><td>Student Name</td><td>Actions</td></tr>
<tr><td><input type="text" name="studNo"/></td><td><input type="text" name="studName"/></td><td> </td></tr>
</table>
</td></tr>
<tr bgcolor="#737328"><td>
<input type="hidden" name="theValue" id="theValue" value="0"/>
<div id="myDiv"></div>
</td></tr>
<tr>
<td><p><a href="javascript:;" onclick="addRow('myDiv','theValue','');"><strong>Add More</strong></a></p></td>
</tr>
</table>
</form>
</body>
</html>

Adding Dynamic rows to table using javascript

Please copy this code and create as test.html and see the functionality

<html>
<head>
<script LANGUAGE="JavaScript">
function addRow(tableID){
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "text";
element1.name = "empNo";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
var element2 = document.createElement("input");
element2.type = "text";
cell2.appendChild(element2);

var cell3 = row.insertCell(2);
var element3 = document.createElement("textarea");
element3.setAttribute("name","mytextarea");
element3.setAttribute("cols","10");
element3.setAttribute("rows","1");
cell3.appendChild(element3);
}
function deleteRow(tableID) {

var table = document.getElementById(tableID);
var rowCount = table.rows.length;
if(rowCount > 1) {
table.deleteRow(rowCount - 1);
}

}
</script>
</head>
<body>
<form name="f1" id="f1">
<input type="button"value="Add" onclick="addRow('datatable')">
<table id="datatable" cellspacing="0" border="1" bgcolor="#738711">
<tbody>
<tr>
<td><input type="text" ></td><td><input type="text"></td><td><textarea rows="1" cols="10"></textarea></td>

<td><a href="javascript:void(0);" onclick="deleteRow('datatable')" >Remove</a></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

Wednesday, September 23, 2009

Java Interview Questions

Please post answers for fallowing Questions:

1. What is serial version id which generated in Eclipse.
2. What is the difference between implementing an interface and extending a class
3. What is servlet lifecycle?
4. can static variables are bind with objects?
5. what is the difference between Servlet and Servlet filter?
6. What is the difference between filter and listener?
7. What are features swing has over the awt?
8. what are the features of hibernate?. What is hibernate?
9. What are adapting classes?
10. What are the differences between string and StringBuffer?
11. What is mutable?
12. What are the differences between Arraylist and Vector?
13. How can you deploy an application in tomcat and JBoss?
14. How many layers do you used to develop the web application?

Wednesday, September 16, 2009

Hibernate Questions

Please post the Answers for the fallowing Questions:

1Q: How the web server or applications server knows that you are using Hibernate?
2Q: What are the parameters has to use to create a database resource in the hibernate.cfg.xml?
3Q: What is hivernate mapping file and what is the use of it?
4Q: What is ORM mapping software and how hibernate differs from other ORM mapping softwares?
5Q: What are the features of hibernate?
6Q: What is sessionFactory and when the sessionFactory is created?
7Q: What is the use of dialect in the hibernate mapping file?
8Q: What is HQL ?
9Q: What are the ways you have to get data from database in hiberanate?
10Q: What is the difference between Hibernate session and HTTP session.

Monday, September 14, 2009

Example to create thread by implementing runnable interface

class Thread1{
static public void main(String[] args){
Thread myThreadA = new Thread(new MyThread1(),"threadA");
Thread myThreadB = new Thread(new MyThread1(),"threadB");
//run the two threads
myThreadA.start();
myThreadB.start();

try{
Thread.currentThread().sleep(1000);
}catch(InterruptedException e){}
//Display info about the main thread
System.out.println(Thread.currentThread());
}
}
class MyThread1 implements Runnable{
public void run(){
for(int i= 0;i <10;>
System.out.println(Thread.currentThread());
}
}

Write into file Example

import java.io.*;

class Bistream{
public static void main (String args[]){
try{
BufferedInputStream in =new BufferedInputStream(new FileInputStream("test.txt"));
int i,j=1;
while((i = in.read ())!= -1){
System.out.print((char)i);
if (j==10)
in.skip(10);
if (j==20)
in.mark(199); //mark at 20th byte so that we can come back
if(j==30)
in.reset();
j++;
}
in.close();
} catch (Exception e){};
}
}

Wednesday, September 9, 2009

Java Collection Frame work

Java collection pages are more useful in the development of the applications. Collection is an object which stores the objects such as ArrayList, Vector...etc

The basic interface in collection frame work is Collection. Other interfaces are Set, List, SortedList.
List:
1. When sequence matters
2. When you know index position
3. Duplicates are allowed.

Set:
1. When uniqueness matters
2. You can never have more then one element referencing the same object
3. Does not allow Duplicates.

Map:
1. Key value pairs
2. Maps know the value associated with the given key.
3. You can have two keys that refer the same value but you cannot have a duplicate key(A key can be any object).

The basic advantages of Collection frame work are:
By providing data structures and Algorithms internally the reduces the Programming effort.

Saturday, April 11, 2009

JAVA PROGRAMMS1

class Bistream{
Void static main (String args[]){
Try{
BufferedInputStream in = new new BufferedInputStream (new FileInputStream("test.txt))); //create an object of fileinputstream type
//and construct BufferedInputStream from it.
Int i;
while((i = in.read ())!= -1)
System.out.Print(i);
in.close();
} catch (exception e){};
}
}


--------------------------------------------------


/* Program to create thread by implementing runnable interface
Author : Team -J
Version : 1.0 */
class Thread1{
static public void main(String[] args){
Thread myThreadA = new Thread(new MyThread1(),"threadA");
Thread myThreadB = new Thread(new MyThread1(),"threadB");
//run the two threads
myThreadA.start();
myThreadB.start();

try{
Thread.currentThread().sleep(1000);
}catch(InterruptedException e){}
//Display info about the main thread
System.out.println(Thread.currentThread());
}
}
class MyThread1 implements Runnable{
public void run(){
for(int i= 0;i <10; i++)
System.out.println(Thread.currentThread());
}
}


-------------------------------------


/* Program to create thread by implementing runnable interface
Author : Team -J
Version : 1.0 */
class Thread2{
static public void main(String[] args){
Thread myThreadA = new Thread(new MyThread2(),"threadA");
Thread myThreadB = new Thread(new MyThread2(),"threadB");
//run the two threads
myThreadA.start();
myThreadB.start();

try{
Thread.currentThread().sleep(1000);
}catch(InterruptedException e){}
//Display info about the main thread
System.out.println(Thread.currentThread());
}
}
class MyThread2 extends Thread{
public void run(){
for(int i= 0;i <10; i++)
System.out.println(Thread.currentThread());
}
}


-------------------------------------------------


/* Program to demonstrate producer/consumer problem
Author : Team -J
Version : 1.0 */
class sharedvar{
int i;
sharedvar(){
i=0;
}
int incvar(){
return i++;
}
int getvar(){
return i;
}
}
class MyThread3A extends Thread{
sharedvar v;
MyThread3A(sharedvar v){
this.v = v;
}
public void run(){
for(int i= 0;i <10; i++)
System.out.println("Value of shared variable "+ v.getvar());
}

}
class MyThread3B extends Thread{
sharedvar v;
MyThread3B(sharedvar v){
this.v = v;
}
public void run(){
for(int i= 0;i <10; i++){
System.out.println("value of shared variable after incrimenting "+v.incvar());
}
}
}
class Thread3{
static public void main(String[] args){
sharedvar v = new sharedvar();
Thread myThread3A = (Thread) new MyThread3A (v);
myThread3A.start();
Thread myThread3B = (Thread) new MyThread3B (v);
myThread3B.start();
}
}

--------------------------------


/* Program to demonstrate producer/consumer problem
Author : Team -J
Version : 1.0 */
class sharedvar{
int i;
sharedvar(){
i=0;
}
int incvar(){
return i++;
}
int getvar(){
return i;
}
}
class MyThread3A extends Thread{
sharedvar v;
MyThread3A(sharedvar v){
this.v = v;
Thread t = new Thread (this,"Thread3A");
t.run();
}
public void run(){
for(int i= 0;i <10; i++)
System.out.println("Value of shared variable "+ v.getvar());
}

}
class MyThread3B extends Thread{
sharedvar v;
MyThread3B(sharedvar v){
this.v = v;
Thread t = new Thread (this,"Thread3B");
t.run();
}
public void run(){
for(int i= 0;i <10; i++){
System.out.println("value of shared variable after incrimenting "+v.incvar());
}
}
}
class Thread3{
static public void main(String[] args){
sharedvar v = new sharedvar();
new MyThread3A (v);
new MyThread3B (v);
}
}

------------------------------------------------------------

/* Program to solve producer/consumer problem
Author : Team -J
Version : 1.0 */
class sharedvar{
int i;
boolean isvarset;
sharedvar(){
i=0;
isvarset=false;
}
synchronized int incvar(){
if( isvarset) //if var is set wait till the other thread reads it
try{
wait();
}catch(InterruptedException e){};
i++;
isvarset = true;
notify();
return i;
}
synchronized int getvar(){
if (!isvarset)try{
wait();
}catch(InterruptedException e){};
isvarset=false;
notify(); //notify the other thread which is waiting to incerment the value
return i;
}
}
//consumer
class MyThread4A extends Thread{
sharedvar v;
MyThread4A(sharedvar v){
this.v = v;
}
public void run(){
for(int i= 0;i <10; i++)
System.out.println("Value of shared variable "+ v.getvar());
}

}
//producer
class MyThread4B extends Thread{
sharedvar v;
MyThread4B(sharedvar v){
this.v = v;
}
public void run(){
for(int i= 0;i <10; i++)
System.out.println("value of shared variable after incrementing "+v.incvar());

}
}
class Thread4{
static public void main(String[] args){
sharedvar v = new sharedvar();
Thread myThread4A = (Thread) new MyThread4A (v);
myThread4A.start();
Thread myThread4B = (Thread) new MyThread4B (v);
myThread4B.start();
}
}

------------------------------------------------------------
/*Version : 1.0
Program to compute x pow 1 /1 ! + x pow 2 / 2! + x pow 3/ 3!
using for construct
Author : Team - J
*/
public class for2
{
public static void main(String args[]){
int i,j,no=3;
float sum=1.0f;
int prod,nopowx;
for(i=1 ; i<5;i++){
//find no power i
nopowx=no;
for(j=1;j
nopowx= nopowx * no;
System.out.println(" power = " + nopowx);
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;
}
System.out.println(prod);
sum=sum + nopowx/prod;
}
System.out.println(" sum = " + sum);
}

}


---------------------------------------

/*Version : 1
This program displays a pattern
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
using for construct
Author : Team - J
*/
public class for3
{
public static void main(String args[]){
int no=10;
int i=1,j;
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
System.out.print(" ");
else
System.out.print("&");

for(j=2;j <10;j++)
System.out.print("&");
if ( (i %2 ) == 0)
System.out.print(" ");
else
System.out.print("&");
System.out.println();
}

}
}


-----------------------------------------------------

/*Version : 1
This program uses break and continue
using for construct
Author : Team - J
*/
public class for4
{
public static void main(String args[]){
int no=10;
int i=1,j;
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
continue;
/* break;*/
System.out.println(i);
}

}
}


-------------------------------------------------

/*Version : 1
This program uses break and continue
using for construct
Author : Team - J
*/
public class for5
{
public static void main(String args[]){
int no=10;
int i=1,j;
outer_for: for(j=0;j<10;j++){
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
/* continue;*/
break outer_for;
System.out.println(i);
}
}

}
}


---------------------------------------


/*Version : 1
This program prints the following pattern
*********
*******
*****
***
*
using for construct
Author : Team - J
*/
public class for6
{
public static void main(String args[]){
int max=9,lines=5,spaces=0;
int i=1,j,k;
for(i=0;i
// print spaces first
for(k=0;k
System.out.print(" ");
for(j=0;j<(max- spaces*2);j++)
System.out.print("*");
spaces++;
System.out.println();
}

}
}



-----------------------------


/*Version : 1.0
This program prints the following pattern
*
***
*****
*******
*********
using for construct
Author : Team - J
*/
public class for7
{
public static void main(String args[]){
int stars=1,lines=5,spaces=5;
int i=1,j,k;
for(i=0;i
// print spaces first
for(k=0;k
System.out.print(" ");
for(j=0;j<(stars);j++)
System.out.print("*");
spaces--;
stars +=2;
System.out.println();
}

}
}


--------------------------------


/*Version : 1
This program prints the following pattern
*
***
*****
*******
*********
using for construct
Author : Team - J
*/
public class for8
{
public static void main(String args[]){
int stars=1,lines=5;
int i=1,j,k;
for(i=0;i
for(j=0;j<(stars);j++)
System.out.print("*");
stars+=2;
System.out.println();
}

}
}


---------------------------------------


/*Version : 1
This program prints the following pattern
using for construct
Author : Team - J
*/
public class for9
{
public static void main(String args[]){
int stars=1,lines=5;
int i=1,j,k;
for(i=0;;i++){
System.out.println(i);
}

}
}


-----------------------------------------

/*Version : 1.0
Program to show how multiple statements can be included in For init
using for construct
Author : Team - J
*/
public class for10
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
int prod,nopowx;
for(i=1,j=0,no=3 ; i<5;i++,f++,k+=99){
//find no power i
nopowx=no;
for(j=1;j
nopowx= nopowx * no;
System.out.println(" power = " + nopowx);
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;
}
System.out.println(prod);
sum=sum + nopowx/prod;
}
System.out.println(" sum = " + sum);
System.out.println(i + " " + j + " " + f + " " + k);
}
}


-------------------------------

/*Version : 1.0
Program to show how to use multiple expression statements in For init
using for construct
Author : Team - J
*/
public class formultiexp
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
int prod,nopowx;
for(i=1,j=0,no=3,System.out.println("in For init") ; i<5;i++,f++,k+=99,System.out.println("in For update"),System.out.println("in For update2")){
System.out.println("in For body");
}

}
}


----------------------------------------------------


/*Version : 1
Program using for construct
1+1/1!+1/2!+1/3!+1/4!
Author : Team - J
*/
public class forone
{
public static void main(String args[]){
int i,j,no;
float sum=1.0f;
int prod;
for(i=1 ; i<5;i++){
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;

}
System.out.println(prod);
sum=sum + 1.0F/prod;
}
System.out.println(" sum = " + sum);
}
}


---------------------------

ForStatement:
for ( ForInit opt ; Expression opt ; ForUpdate opt )
Statement | Block of Statements

ForInit:
StatementExpressionList
LocalVariableDeclaration
ForUpdate:
StatementExpressionList
StatementExpressionList:
StatementExpression
StatementExpressionList , StatementExpression

---------------------------------------------



/*Version : 1.0
Program to show how to use labled continue
using for construct
Author : Team - J
*/
public class lablecontinuefor
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
lab1:
System.out.println(" lable one");
//lab1:
//System.out.println(" lable one second time");
int prod,nopowx;

lab1:
//while(true){
//System.out.println(" in while");
lab2:
for(i=1; i<3;i++){

System.out.println(" value of i = " +i);
lab3:
for(j=1;j<=4;j++){
System.out.println(" value of j = " + j);
if( j ==1)
continue lab3;
System.out.println(" After break lab3");
if( j ==2)
continue lab3;
System.out.println(" After break lab3 ..");
if( j ==3)
continue lab1;
System.out.println(" After break lab1");
}
}
//}

}
}


--------------------------------------------


/*Version : 1.0
Program to show how to use labled break
using for construct
Author : Team - J
*/
public class lablefor
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
lab1:
System.out.println(" lable one");
//lab1:
//System.out.println(" lable one second time");
int prod,nopowx;

lab1:
while(true){
System.out.println(" in while");
lab2:
for(i=1; i<3;i++){

System.out.println(" value of i = " +i);
lab3:
for(j=1;j<=4;j++){
System.out.println(" value of j = " + j);
if( j ==1)
break lab3;
System.out.println(" After break lab3");
if( j ==2)
break lab3;
System.out.println(" After break lab2");
if( j ==3)
break lab1;
System.out.println(" After break lab1");
}
}
}

}
}

---------------------------------------------

JAVA3
/*Version : 1.0
Program to compute x pow 1 /1 ! + x pow 2 / 2! + x pow 3/ 3!
using for construct
Author : Team - J
*/
public class for2
{
public static void main(String args[]){
int i,j,no=3;
float sum=1.0f;
int prod,nopowx;
for(i=1 ; i<5;i++){
//find no power i
nopowx=no;
for(j=1;j
nopowx= nopowx * no;
System.out.println(" power = " + nopowx);
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;
}
System.out.println(prod);
sum=sum + nopowx/prod;
}
System.out.println(" sum = " + sum);
}

}


---------------------------------------

/*Version : 1
This program displays a pattern
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
using for construct
Author : Team - J
*/
public class for3
{
public static void main(String args[]){
int no=10;
int i=1,j;
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
System.out.print(" ");
else
System.out.print("&");

for(j=2;j <10;j++)
System.out.print("&");
if ( (i %2 ) == 0)
System.out.print(" ");
else
System.out.print("&");
System.out.println();
}

}
}


-----------------------------------------------------

/*Version : 1
This program uses break and continue
using for construct
Author : Team - J
*/
public class for4
{
public static void main(String args[]){
int no=10;
int i=1,j;
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
continue;
/* break;*/
System.out.println(i);
}

}
}


-------------------------------------------------

/*Version : 1
This program uses break and continue
using for construct
Author : Team - J
*/
public class for5
{
public static void main(String args[]){
int no=10;
int i=1,j;
outer_for: for(j=0;j<10;j++){
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
/* continue;*/
break outer_for;
System.out.println(i);
}
}

}
}


---------------------------------------


/*Version : 1
This program prints the following pattern
*********
*******
*****
***
*
using for construct
Author : Team - J
*/
public class for6
{
public static void main(String args[]){
int max=9,lines=5,spaces=0;
int i=1,j,k;
for(i=0;i
// print spaces first
for(k=0;k
System.out.print(" ");
for(j=0;j<(max- spaces*2);j++)
System.out.print("*");
spaces++;
System.out.println();
}

}
}



-----------------------------


/*Version : 1.0
This program prints the following pattern
*
***
*****
*******
*********
using for construct
Author : Team - J
*/
public class for7
{
public static void main(String args[]){
int stars=1,lines=5,spaces=5;
int i=1,j,k;
for(i=0;i
// print spaces first
for(k=0;k
System.out.print(" ");
for(j=0;j<(stars);j++)
System.out.print("*");
spaces--;
stars +=2;
System.out.println();
}

}
}


--------------------------------


/*Version : 1
This program prints the following pattern
*
***
*****
*******
*********
using for construct
Author : Team - J
*/
public class for8
{
public static void main(String args[]){
int stars=1,lines=5;
int i=1,j,k;
for(i=0;i
for(j=0;j<(stars);j++)
System.out.print("*");
stars+=2;
System.out.println();
}

}
}


---------------------------------------


/*Version : 1
This program prints the following pattern
using for construct
Author : Team - J
*/
public class for9
{
public static void main(String args[]){
int stars=1,lines=5;
int i=1,j,k;
for(i=0;;i++){
System.out.println(i);
}

}
}


-----------------------------------------

/*Version : 1.0
Program to show how multiple statements can be included in For init
using for construct
Author : Team - J
*/
public class for10
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
int prod,nopowx;
for(i=1,j=0,no=3 ; i<5;i++,f++,k+=99){
//find no power i
nopowx=no;
for(j=1;j
nopowx= nopowx * no;
System.out.println(" power = " + nopowx);
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;
}
System.out.println(prod);
sum=sum + nopowx/prod;
}
System.out.println(" sum = " + sum);
System.out.println(i + " " + j + " " + f + " " + k);
}
}


-------------------------------

/*Version : 1.0
Program to show how to use multiple expression statements in For init
using for construct
Author : Team - J
*/
public class formultiexp
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
int prod,nopowx;
for(i=1,j=0,no=3,System.out.println("in For init") ; i<5;i++,f++,k+=99,System.out.println("in For update"),System.out.println("in For update2")){
System.out.println("in For body");
}

}
}


----------------------------------------------------


/*Version : 1
Program using for construct
1+1/1!+1/2!+1/3!+1/4!
Author : Team - J
*/
public class forone
{
public static void main(String args[]){
int i,j,no;
float sum=1.0f;
int prod;
for(i=1 ; i<5;i++){
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;

}
System.out.println(prod);
sum=sum + 1.0F/prod;
}
System.out.println(" sum = " + sum);
}
}


---------------------------

ForStatement:
for ( ForInit opt ; Expression opt ; ForUpdate opt )
Statement | Block of Statements

ForInit:
StatementExpressionList
LocalVariableDeclaration
ForUpdate:
StatementExpressionList
StatementExpressionList:
StatementExpression
StatementExpressionList , StatementExpression

---------------------------------------------



/*Version : 1.0
Program to show how to use labled continue
using for construct
Author : Team - J
*/
public class lablecontinuefor
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
lab1:
System.out.println(" lable one");
//lab1:
//System.out.println(" lable one second time");
int prod,nopowx;

lab1:
//while(true){
//System.out.println(" in while");
lab2:
for(i=1; i<3;i++){

System.out.println(" value of i = " +i);
lab3:
for(j=1;j<=4;j++){
System.out.println(" value of j = " + j);
if( j ==1)
continue lab3;
System.out.println(" After break lab3");
if( j ==2)
continue lab3;
System.out.println(" After break lab3 ..");
if( j ==3)
continue lab1;
System.out.println(" After break lab1");
}
}
//}

}
}


--------------------------------------------


/*Version : 1.0
Program to show how to use labled break
using for construct
Author : Team - J
*/
public class lablefor
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
lab1:
System.out.println(" lable one");
//lab1:
//System.out.println(" lable one second time");
int prod,nopowx;

lab1:
while(true){
System.out.println(" in while");
lab2:
for(i=1; i<3;i++){

System.out.println(" value of i = " +i);
lab3:
for(j=1;j<=4;j++){
System.out.println(" value of j = " + j);
if( j ==1)
break lab3;
System.out.println(" After break lab3");
if( j ==2)
break lab3;
System.out.println(" After break lab2");
if( j ==3)
break lab1;
System.out.println(" After break lab1");
}
}
}

}
}

---------------------------------------------

JAVA3
/*Version : 1.0
Program to compute x pow 1 /1 ! + x pow 2 / 2! + x pow 3/ 3!
using for construct
Author : Team - J
*/
public class for2
{
public static void main(String args[]){
int i,j,no=3;
float sum=1.0f;
int prod,nopowx;
for(i=1 ; i<5;i++){
//find no power i
nopowx=no;
for(j=1;j
nopowx= nopowx * no;
System.out.println(" power = " + nopowx);
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;
}
System.out.println(prod);
sum=sum + nopowx/prod;
}
System.out.println(" sum = " + sum);
}

}


---------------------------------------

/*Version : 1
This program displays a pattern
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&
using for construct
Author : Team - J
*/
public class for3
{
public static void main(String args[]){
int no=10;
int i=1,j;
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
System.out.print(" ");
else
System.out.print("&");

for(j=2;j <10;j++)
System.out.print("&");
if ( (i %2 ) == 0)
System.out.print(" ");
else
System.out.print("&");
System.out.println();
}

}
}


-----------------------------------------------------

/*Version : 1
This program uses break and continue
using for construct
Author : Team - J
*/
public class for4
{
public static void main(String args[]){
int no=10;
int i=1,j;
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
continue;
/* break;*/
System.out.println(i);
}

}
}


-------------------------------------------------

/*Version : 1
This program uses break and continue
using for construct
Author : Team - J
*/
public class for5
{
public static void main(String args[]){
int no=10;
int i=1,j;
outer_for: for(j=0;j<10;j++){
for(i=1;i<10;i++)
{
if ( (i %2 ) == 0)
/* continue;*/
break outer_for;
System.out.println(i);
}
}

}
}


---------------------------------------


/*Version : 1
This program prints the following pattern
*********
*******
*****
***
*
using for construct
Author : Team - J
*/
public class for6
{
public static void main(String args[]){
int max=9,lines=5,spaces=0;
int i=1,j,k;
for(i=0;i
// print spaces first
for(k=0;k
System.out.print(" ");
for(j=0;j<(max- spaces*2);j++)
System.out.print("*");
spaces++;
System.out.println();
}

}
}



-----------------------------


/*Version : 1.0
This program prints the following pattern
*
***
*****
*******
*********
using for construct
Author : Team - J
*/
public class for7
{
public static void main(String args[]){
int stars=1,lines=5,spaces=5;
int i=1,j,k;
for(i=0;i
// print spaces first
for(k=0;k
System.out.print(" ");
for(j=0;j<(stars);j++)
System.out.print("*");
spaces--;
stars +=2;
System.out.println();
}

}
}


--------------------------------


/*Version : 1
This program prints the following pattern
*
***
*****
*******
*********
using for construct
Author : Team - J
*/
public class for8
{
public static void main(String args[]){
int stars=1,lines=5;
int i=1,j,k;
for(i=0;i
for(j=0;j<(stars);j++)
System.out.print("*");
stars+=2;
System.out.println();
}

}
}


---------------------------------------


/*Version : 1
This program prints the following pattern
using for construct
Author : Team - J
*/
public class for9
{
public static void main(String args[]){
int stars=1,lines=5;
int i=1,j,k;
for(i=0;;i++){
System.out.println(i);
}

}
}


-----------------------------------------

/*Version : 1.0
Program to show how multiple statements can be included in For init
using for construct
Author : Team - J
*/
public class for10
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
int prod,nopowx;
for(i=1,j=0,no=3 ; i<5;i++,f++,k+=99){
//find no power i
nopowx=no;
for(j=1;j
nopowx= nopowx * no;
System.out.println(" power = " + nopowx);
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;
}
System.out.println(prod);
sum=sum + nopowx/prod;
}
System.out.println(" sum = " + sum);
System.out.println(i + " " + j + " " + f + " " + k);
}
}


-------------------------------

/*Version : 1.0
Program to show how to use multiple expression statements in For init
using for construct
Author : Team - J
*/
public class formultiexp
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
int prod,nopowx;
for(i=1,j=0,no=3,System.out.println("in For init") ; i<5;i++,f++,k+=99,System.out.println("in For update"),System.out.println("in For update2")){
System.out.println("in For body");
}

}
}


----------------------------------------------------


/*Version : 1
Program using for construct
1+1/1!+1/2!+1/3!+1/4!
Author : Team - J
*/
public class forone
{
public static void main(String args[]){
int i,j,no;
float sum=1.0f;
int prod;
for(i=1 ; i<5;i++){
//find factorial of i
prod=1;
for(j=1;j<=i;j++){
prod=prod * j;

}
System.out.println(prod);
sum=sum + 1.0F/prod;
}
System.out.println(" sum = " + sum);
}
}


---------------------------

ForStatement:
for ( ForInit opt ; Expression opt ; ForUpdate opt )
Statement | Block of Statements

ForInit:
StatementExpressionList
LocalVariableDeclaration
ForUpdate:
StatementExpressionList
StatementExpressionList:
StatementExpression
StatementExpressionList , StatementExpression

---------------------------------------------



/*Version : 1.0
Program to show how to use labled continue
using for construct
Author : Team - J
*/
public class lablecontinuefor
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
lab1:
System.out.println(" lable one");
//lab1:
//System.out.println(" lable one second time");
int prod,nopowx;

lab1:
//while(true){
//System.out.println(" in while");
lab2:
for(i=1; i<3;i++){

System.out.println(" value of i = " +i);
lab3:
for(j=1;j<=4;j++){
System.out.println(" value of j = " + j);
if( j ==1)
continue lab3;
System.out.println(" After break lab3");
if( j ==2)
continue lab3;
System.out.println(" After break lab3 ..");
if( j ==3)
continue lab1;
System.out.println(" After break lab1");
}
}
//}

}
}


--------------------------------------------


/*Version : 1.0
Program to show how to use labled break
using for construct
Author : Team - J
*/
public class lablefor
{
public static void main(String args[]){
int i,j,no=3,f=0,k=10;
float sum=1.0f;
lab1:
System.out.println(" lable one");
//lab1:
//System.out.println(" lable one second time");
int prod,nopowx;

lab1:
while(true){
System.out.println(" in while");
lab2:
for(i=1; i<3;i++){

System.out.println(" value of i = " +i);
lab3:
for(j=1;j<=4;j++){
System.out.println(" value of j = " + j);
if( j ==1)
break lab3;
System.out.println(" After break lab3");
if( j ==2)
break lab3;
System.out.println(" After break lab2");
if( j ==3)
break lab1;
System.out.println(" After break lab1");
}
}
}

}
}