Skip to main content

Javier Neira

Javier Neira's Public Library

Working with Java Enumerated types (Enums) « Java PitStop

01 enum Speed{
02 LOW(3,2.5){ //Line 1
03 String getInformation(){ //Method overriden by the Enum constants
04 return "Running of Low speed with less units consumed";
05 }
06 },
07 MEDIUM(6,5.0){ //Line 2
08 String getInformation(){
09 return "Running of Medium speed with moderate units consumed";
10 }
11 },
12 HIGH(10,7.5){ //Line 3
13 String getInformation(){
14 return "Running of High speed with Maximum units consumed";
15 }
16 };
17 private int speedValue;
18 private double unitsConsumed;
19 Speed(int speed, double units){
20 this.speedValue=speed;
21 this.unitsConsumed=units;
22 }
23 public int getSpeedValue(){
24 return this.speedValue;
25 }
26 public double getUnitsConsumed(){
27 return this.unitsConsumed;
28 }
29 abstract String getInformation(); //This is an abstract method
30 }
31 public class Machine{
32 Speed machineSpeed;
33 Machine(Speed speed){
34 this.machineSpeed=speed;
35 }
36 Speed getSpeed(){
37 return this.machineSpeed;
38 }
39 public static void main(String[] args){
40 Machine machine1 = new Machine(Speed.LOW);
41 Machine machine2 = new Machine(Speed.HIGH);
42 System.out.println("Machine 1 speed: "+machine1.getSpeed().getInformation());
43 System.out.println("Machine 2 speed: "+machine2.getSpeed().getInformation());
44 }
45 }

javaforyou.wordpress.com/...th-java-enumerated-types-enums - Preview

java enums tutorial basics

The busy Java developer's guide to Scala: Scala and servlets

Summary: In order for a language to be recognized as "real-world" and "ready for prime-time," the language has to be able to reach out to real-world environments and applications. In this installment, Ted Neward begins a tour of Scala in the real world by examining how Scala can interact with the core Servlet API and perhaps even improve it a little.

www.ibm.com/...j-scala12228.html - Preview

scala webdev servlet howto

The Java Community Process(SM) Program - JSRs: Java Specification Requests - detail JSR# 316

    • We propose to include the following new JSRs in Java EE 6:


      • JSR-196 Java Authentication SPI for Containers
      • JSR-236 Timer for Application Servers
      • JSR-237 Work Manager for Application Servers
      • JSR-299 Web Beans
      • JSR-311 JAX-RS: Java API for RESTful Web Services
      • Enterprise JavaBeans
      • Java Persistence API
      • Servlets
      • JavaServer Faces
      • JAX-WS
      • Java EE Connector API
    • JSR-168 Portlet Specification
    • JSR-170 Content Repository for Java technology API
    • JSR-207 Process Definition for Java
    • JSR-208 Java Business Integration (JBI)
    • JSR-225 XQuery API for Java (XQJ)
    • JSR-235 Service Data Objects
    • JSR-286 Portlet Specification 2.0
    • JSR-289 SIP Servlet v1.1
    • JSR-301 Portlet Bridge Specification for JavaServer Faces

String Interpolation in Clojure - Chas Emerick - Muck and Brass

(ns commons.clojure.strint
(:use [clojure.contrib.duck-streams :only (slurp*)]))

(defn- silent-read
[s]
(try
(let [r (-> s java.io.StringReader. java.io.PushbackReader.)]
[(read r) (slurp* r)])
(catch Exception e))) ; this indicates an invalid form -- s is just string data

(defn- interpolate
([s atom?]
(lazy-seq
(if-let [[form rest] (silent-read (subs s (if atom? 2 1)))]
(cons form (interpolate (if atom? (subs rest 1) rest)))
(cons (subs s 0 2) (interpolate (subs s 2))))))
([#^String s]
(let [start (max (.indexOf s "~{") (.indexOf s "~("))]
(if (== start -1)
[s]
(lazy-seq (cons
(subs s 0 start)
(interpolate (subs s start) (= \{ (.charAt s (inc start))))))))))

(defmacro <<
[string]
`(str ~@(interpolate string)))

muckandbrass.com/...tring+Interpolation+in+Clojure - Preview

clojure macro << template string

  • The public macro << (named as an homage to heredocs) takes a single string argument, and emits a str invocation that concatenates the string data and evaluated expressions contained within that argument.
  • (<< "There's ~(dec n) bottles of beer on the wall...")
    "There's 98 bottles of beer on the wall..."
  • 6 more annotations...

Groovy Goodness: Using the ServletCategory - Messages from mrhaki

// File: Start.groovy
01.import javax.servlet.http.*
02.import javax.servlet.*
03.import groovy.servlet.ServletCategory
04.
05.class Start extends HttpServlet {
06. def application
07.
08. void init(ServletConfig config) {
09. super.init(config)
10. application = config.servletContext
11. use(ServletCategory) {
12. application.author = 'mrhaki'
13. }
14. }
15.
16. void doGet(HttpServletRequest request, HttpServletRespons reponse) {
17. def session = request.session
18. use (ServletCategory) {
19. if (session.counter) { // We can use . notation to access session attribute.
20. session.counter++ // We can use . notation to set value for session attribute.
21. } else {
22. session.counter = 1
23. }
24.
25. request.pageTitle = 'Groovy Rocks!'
26. }
27. application.getRequestDispatcher('/output').forward(request, response)
28. }
29.}

mrhaki.blogspot.com/...ess-using-servletcategory.html - Preview

groovy goodness webdev servlet example

1 - 20 of 2236 Next › Last »
Showing 20 items per page

Highlighter, Sticky notes, Tagging, Groups and Network: integrated suite dramatically boosting research productivity. Learn more »

Join Diigo