Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Thursday, December 11, 2014

Print System IP Address and Current Date/Time

<%! int day = 3; %>
<%! int fontSize = 3; %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>
<%
out.println("Your IP address is " + request.getRemoteAddr());
%>
<p>
   Today's date: <%= (new java.util.Date()).toLocaleString()%>
</p>
<% if (day == 1 | day == 7) { %>
      <p> Today is weekend</p>
<% } else { %>
      <p> Today is not weekend</p>
<% } %>

<%for ( fontSize = 1; fontSize <= 3; fontSize++){ %>
   <font color="green" size="<%= fontSize %>">
    JSP Tutorial
   </font><br />
<%}%>

</body>
</html>

Java Basic Concepts

1. 
Inheritance:
To achieve method overriding there should be inheritance
explanation:
In Child class override the methods declared in parent class

Static Methods can call directly without using create instance (obj) of the class
explanation:
Cal.display();
here Cal is the Class name

2.
Java Bean:
Java Bean is the example of Encapsulation
Hiding Implementation details reduce the complexity and the output is Easier maintenance

3.
Instance Variable : Created on Class level
Class Variable: Created on Class level with static keyword
Local Variable: Created inside the method body

4.
base: this keyword is used to invoke constructor of base class

5.
Interface:

  • Multiple Inheritance can be implemented with the help of Interface.
  • It provide abstractions
  • A contract b/w senior and junior
  • 100% Abstraction
  • It can hold only method prototype (declaration)
  • It can also have var that will be constant
  • The class implementing Interface must have to define all the methods


6.
Abstract:

  • These are the special classes defined with the keyword abstract
  • Use of Abstract Class:
  • When we know about partial implementations


7.
Polymorphism:

  • Ability to take more than one form
  • A child class may override some of the behaviors of the parent class
  • It allows abstract operations to be defined and used

explanation:
abstract operations are defined in base class and used in derived class

declared as abstract or virtual

8.
Package:

  • If the class defined inside the package then the package statement should be the first statement 
  • In simple its a way of categorizing the Classes and Interfaces


9.
Has-A

  • This relationship helps to reduce duplication of code as well as bugs
  • A Class cannot extends more than one class
  • public class extends Animal, Mammal{}  --- It's not possible in Java but can be implemented with the help of Interface

10.
Static:
A method declared static cannot be overridden but can be re-declared.

11.
super
When invoking a super class version of an overridden method the super keyword is used.

12.
Object Declaration:
Animal b = new Dog(); // Animal reference but Dog object
Animal b = new Animal(); //Animal object

Wednesday, December 10, 2014

JSP Learning

JSP Processing
http://www.tutorialspoint.com/images/jsp-processing.jpg

JSP Life Cycle
http://www.tutorialspoint.com/images/jsp_life_cycle.jpg

Scriptlet Syntax
<% code fragment %>
or
<jsp:scriptlet>
   code fragment
</jsp:scriptlet>

Variable Declaration
<%! int i = 0; %>
<%! int a, b, c; %>
<%! Circle a = new Circle(2.0); %>

JSP Expresstion
<%= expression %>

JSP Comments
<%-- This is JSP comment --%>

JSP Action
<jsp:action_name attribute="value" />

JSP Directive
<%@ page ... %>
<%@ include ... %>
<%@ taglib ... %>

<%@ include file="relative url" %>
<jsp:directive.include file="relative url" />

The <jsp:setProperty> Action
The <jsp:getProperty> Action
The <jsp:forward> Action
The <jsp:plugin> Action
The plugin action is used to insert Java components into a JSP page
The Java component can be either an Applet or a JavaBean.

The <jsp:element> Action
The <jsp:attribute> Action
The <jsp:body> Action

The <jsp:text> Action