Busca

JSantanna

Meu blog sobre engenharia, tecnologia, ciência da Computação, etc.

Categoria

java

Projeto apache commons

commons-logo

Uma biblioteca de APIs que resolve vários problemas comuns de programação, bibliotecas todas em java .

http://commons.apache.org/

Anúncios

Java code geek courses made public :-)

JavaCodeGeeks-logo

Cursos do portal Java Code Geek foram disponibilizados publicamente para quem quiser, segue a lista dos cursos:

 

fonte: https://www.javacodegeeks.com/2015/10/jcg-academy-courses-made-public.html

p

http://oncourse.softplan.com.br

url

Artigo na InfoQ que introduz o uso das expressões lambda no Java .

http://www.infoq.com/br/articles/java8-desmistificando-lambdas

Varargs (Var + args) em java : como criar uma função que aceite múltiplos argumentos

04a3c-arquivos-java

Em algumas situações podemos querer criar uma função que não sabemos de antemão quantos argumentos serão necessários. Veja como exemplo um programa que calcule uma soma. Em determinado momento você quer somar só dois números, mas em outro momento pode querer somar 7 números.

Varargs ( vários argumentos) serve exatamente para isso.

Funciona da seguinte forma:

int soma(int ... x){

// mais código aqui

}

Os três pontos significam Continuar lendo “Varargs (Var + args) em java : como criar uma função que aceite múltiplos argumentos”

Ótima seleção de video aulas da editora DevMedia , e o melhor : video aulas gratuitas

http://www.devmedia.com.br/checklist-programador-java/

Dois bons tutoriais sobre Lambda em Java 8

java-logo-lambda

Tutorial Lambda expressions

https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html

Lambda Quick Start

http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html

Top 7 Reasons to Consider Using NetBeans IDE

Dica: Veja o video até o final, tem muita dica e links bacanas no final.

OBS: eu atualmente só uso do netbeans para todos os meus projetos.

Checking out what is new with Servlet 3.0

To com preguiça de traduzir o post abaixo e coloco na integra o artigo extraído de um blog, quem visita o meu blog deve saber ler em inglês , logo não vejo grandes complicações. O assunto é interessante , é utilizar anotations para substituir as declarações de deploy em arquivos XML em projetos java web, enjoy .

With the JEE6 specification hitting the market, some major changes have taken place with respect to how you would approach developing applications in the enterprise application world. In this article i would be touching upon a few changes that were done with respect to web application development.

First things first, say good bye to the web.xml deployment descriptor (at least for parts of it). Well its not like it is deprecated, but with the rise of the usage of annotations and their usage, the new specification allows us to define our configuration using annotations, though some thing such as welcome file lists, context params etc will still need to go inside your web.xml . Annotations available for use are;
@WebServlet
@WebFilter
@WebInitParam
@WebListener
@MultipartConfig

In this article i would be checking out the @WebServlet and @WebFilter annotations. Let us see how we would usually map a servlet in the web.xml era;

1    <servlet>
2        <servlet-name>myservlet</servlet-name>
3        <servlet-class>com.example.MyServlet</servlet-class>
4    </servlet>
5  
6 <servlet-mapping>
7  <servlet-name>myservlet</servlet-name>
8  <url-pattern>/hello</url-pattern>
9 </servlet-mapping>

With the Servlet 3.0 spec, now configuring a Servlet is as easy as annotating a class that extends HttpServlet. Lets see how that looks like;

01 @WebServlet('/student')
02 public class StudentServlet extends HttpServlet{
03  
04  /**
05   *
06   */
07  private static final long serialVersionUID = 2276157893425171437L;
08  
09  @Override
10  protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1)
11    throws ServletException, IOException {
12   StringBuilder response = new StringBuilder(500);
13   response.append('').append('Registered Student : ').append(arg0.getParameter('txtName')).append('

);

14   arg1.getOutputStream().write(response.toString().getBytes());
15   arg1.getOutputStream().flush();
16   arg1.getOutputStream().close();
17  }
18 }

All you need is the @WebServlet annotation. In order for this to work, the class should reside either in the WEB-INF/classes folder or within a jar residing in the WEB-INF/lib folder. Next up lets see how we would configure a filter with annotations.

01 package com.blog.example.servlettest;
02  
03 import java.io.IOException;
04  
05 import javax.servlet.Filter;
06 import javax.servlet.FilterChain;
07 import javax.servlet.FilterConfig;
08 import javax.servlet.ServletException;
09 import javax.servlet.ServletRequest;
10 import javax.servlet.ServletResponse;
11 import javax.servlet.annotation.WebFilter;
12  
13 @WebFilter('/student')
14 public class StudentFilter implements Filter{
15  
16  @Override
17  public void destroy() {
18  }
19  
20  @Override
21  public void doFilter(ServletRequest arg0, ServletResponse arg1,
22    FilterChain arg2) throws IOException, ServletException {
23  
24   if(arg0.getParameter('txtName')==null || arg0.getParameter('txtName').isEmpty())
25   {
26    arg1.getWriter().append('Invalid name supplied');
27    arg1.getWriter().flush();
28    arg1.getWriter().close();
29   }
30   else
31   {
32    arg2.doFilter(arg0, arg1);
33   }
34  }
35  
36  @Override
37  public void init(FilterConfig arg0) throws ServletException {
38   // TODO Auto-generated method stub
39  
40  }
41  
42 }

Again very easy. Just a mere annotation to notify it as a filter. Note that here we implement the Filter interface. The value or theurlPatterns should be available. Using both is illegal as per the specification.

In the coming weeks i will cover the other new annotations available with JEE6 and wrap up with a comprehensive example using them together. If JEE6 will replace Spring framework or not is not a question by itself, but i believe we would be seeing some fierce competition between the two. The annotations vs xml debate is more or less resolved with people with preference for each holding their own grounds. I believe a little bit from both worlds would be beneficial for an application.

You can download and run a sample example which i have uploaded here. If you are using JBoss-AS7 all you need to do is run the application server on standalone mode and do a mvn package jboss-as:deploy and point the browser to http://localhost:{port}/servlet3.0.

That is it for today. Thank you for reading and if you have any comments or suggestions for improvement, please do leave by a comment.

Have a good day all!!

Reference: Checking out what is new with Servlet 3.0 from our JCG partner Dinuka Arseculeratne at the My Journey Through IT blog.

Crie um website ou blog gratuito no WordPress.com.

Acima ↑