1,105,286 Community Members

How to put my logic to something what java will understand?

Member Avatar
razor2890
Newbie Poster
7 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
Hey guys!!! Just found this wonderful forum.....Thanks for the guys who run this forum..

I am an Elec. & Telecom engineer...
I understand Java Programming & I have more than 90% of the concepts of core-java and good knowledge of jsp,servlets,struts....I have some basic knowledge of oracle....

I have a excellent logical & quant aptitude...
What I really struggle in is putting my logic in terms of java....

For eg: A program to show whether the entered string is palindrome or not.
            I know that for a string to be palindrome 1st half of the string elements must be same as the other half....I am able to form the for loop....but struggle in what to write inside the for-loop (coding)..this is just an example....


    for(int i=0;i<=n/2;i++)
    {I struggle here}




What should i do?? I know all the basic concepts related to core-java. I have learnt everything from arrays,threads, generics,collections,string,string-builder....

I know i am not from CompSci or IT background....but i am placed in an it company as a software developer  and undergoing training for the same....

I am required to complete a project Shopping cart portal to pass....(In a week!!!)otherwise i think i will be fired...

I managed to build static home page using HTML & CSS..(not the toughest part i know..)...But for the final I have to create a dynamic page. I have prepared a database for everything(Logo,header,footer,categories)... but i am not able to display it....
for eg: String Header stores my header info... it gets it from database but displays version of the browser which i use....

i use
        ${header}



                        this is my code:
                        Database connection page:
                        /*
                         * To change this template, choose Tools | Templates
                         * and open the template in the editor.
                         */
                        package model;

                        import java.sql.*;
                        import java.sql.Connection;
                        import javax.servlet.http.HttpServletRequest;

                        import org.apache.struts.action.ActionErrors;
                        import org.apache.struts.action.ActionMapping;
                        import org.apache.struts.action.ActionMessage;

                        /**
                         *
                         * @author Ankur5
                         */
                        public class Bean extends org.apache.struts.action.ActionForm {

                            String url = "jdbc:oracle:thin:@localhost:1521:XE";
                            String username = "xxx";
                            String password = "xxx";
                            String header;
                            Connection con;

                            public DbCon() throws ClassNotFoundException, SQLException {
                                getConnection();
                            }

                            public void getConnection() throws ClassNotFoundException, SQLException {
                                Class.forName("oracle.jdbc.OracleDriver");
                                con = DriverManager.getConnection(url, username, password);
                            }

                            public String getHeader() throws SQLException {
                                Statement createStatement = con.createStatement();
                                ResultSet rs = createStatement.executeQuery("select * from CONFIG;");
                                while (rs.next()) {
                                    header = rs.getString(2);
                                }

                                return header;

                            }
                            /**
                             * This is the action called from the Struts framework.
                             *
                             * @param mapping The ActionMapping used to select this instance.
                             * @param request The HTTP Request we are processing.
                             * @return
                             */
                            /*public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
                             * ActionErrors errors = new ActionErrors();
                             * if (getUsername() == null || getUsername().length() < 1) {
                             * errors.add("name", new ActionMessage("error.name.required"));
                             * // TODO: add 'error.name.required' key to your resources
                             * }
                             * return errors;
                             * }*/
                        }

                        ActionClass

                        /*
                         * To change this template, choose Tools | Templates
                         * and open the template in the editor.
                         */
                        package com.myapp.struts;

                        import model.Bean;
                        import javax.servlet.http.HttpServletRequest;
                        import javax.servlet.http.HttpServletResponse;
                        import javax.servlet.http.HttpSession;
                        import org.apache.struts.action.ActionForm;
                        import org.apache.struts.action.ActionForward;
                        import org.apache.struts.action.ActionMapping;

                        /**
                         *
                         * @author Ankur5
                         */
                        public class ActionObject extends org.apache.struts.action.Action {

                            /* forward name="success" path="" */
                            private static final String SUCCESS = "success";
                            String header;

                            /**
                             * This is the action called from the Struts framework.
                             *
                             * @param mapping The ActionMapping used to select this instance.
                             * @param form The optional ActionForm bean for this request.
                             * @param request The HTTP Request we are processing.
                             * @param response The HTTP Response we are processing.
                             * @throws java.lang.Exception
                             * @return
                             */
                            @Override
                            public ActionForward execute(ActionMapping mapping, ActionForm form,
                                    HttpServletRequest request, HttpServletResponse response)
                                    throws Exception {

                                DbCon db = new DbCon();
                                header = db.getHeader();
                                HttpSession s = request.getSession();
                                s.setAttribute("header", header);





                                return mapping.findForward(SUCCESS);
                            }
                        }



I used HttpSession to bind header to session and display..
Is there any error. I dont want you guys to give programs but learn programming. suggest me an approach to MASTER JAVA because I feel that knowing what to be done but not able to put it in programming is just Dumb....
Member Avatar
rubberman
Senior Poster
3,984 posts since Mar 2010
Reputation Points: 513 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 87 [?]
 
0
 

First, the first half of a palindrom is not the same as the second half. A palidrom is a word that reads the same forward or backward. This is something quite different! Here is a helpful Wikipedia article about them: http://en.wikipedia.org/wiki/Palindrome

I don't have time to review your code right now (need to go get dinner for wife), but you will likely need to adjust it in light of these differences.

Member Avatar
razor2890
Newbie Poster
7 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Sorry.. I was not clear before... What I meant to say was 1st element(Letter) should be same as last....& so on.. Until middle element...So n/2 times for loop will execute...

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article