Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Tuesday, June 10, 2014

Learn Java Movies Java Core




Welcome to the LearnJavaOnline.org Interactive Java Tutorial.
Whether you are an experienced programmer or not, this website is intended for everyone who wishes to learn the Java programming language.
Just click on the chapter you wish to begin from, and follow the instructions. Good luck!
Table of Contents
Learn the Basics

Hello, World!
Variables and Types
Conditionals
Arrays
Loops
Functions
Objects
Compiling and Running with Arguments

Advanced Topics (Under Construction)
Inheritance
Try and Catch
Abstract Classes
Interfaces
Using Generics
Collections
Wrappers and Autoboxing
Exceptions
Generic Types
IO Streams



Saturday, January 19, 2013

How to set environment variables in Windows 7 for Java

Environmental variables are used by the operating system to save settings (default values, locations of resources) to be used by Windows or by processes launched by users.
There are two types of environmental variables:
  • user variables that are specific to a particular Windows user account;
  • system variables are always visible, regardless of the used user account.

Even if these variables are usually defined and initialized automatically when you install the system or other applications, there are situations in which the user must manually define them to put at the disposal of applications.
The considered scenario is to set environment variables to enable the compilation and execution of Java applications from the command line (command prompt) or by using an IDE like Eclipse. By installing the Java SDK, system variables about the location of executables (compiler, java virtual machine) are not defined or initialized automatically.
Testing is done by opening command prompt (Start -> cmd) and trying to launch the compiler with the command

Wednesday, December 26, 2012

Android - Function to convert ImageURL to Bitmap object

IMAGE URL TO BITMAP

Use this function “convertURLtoBitmap”

public Bitmap convertURLtoBitmap(String src) {

                try {

                                URL url = new URL(src);
                                                
                                HttpURLConnection connection = (HttpURLConnection) url
                                                .openConnection();

                                connection.setDoInput(true);
                                connection.connect();

                                InputStream input = connection.getInputStream();
                                Bitmap myBitmap = BitmapFactory.decodeStream(input);

                                return myBitmap;

                }

                catch (IOException e) {

                                e.printStackTrace();
                                return null;

                }
}

Email Validation Function


public boolean validateEmail(String email) {

Pattern pattern;
Matcher matcher;
String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
pattern = Pattern.compile(EMAIL_PATTERN);
matcher = pattern.matcher(email);
return matcher.matches();

}

Searching the elements of a String array, starts with SEARCHTEXT (String)


Searching the elements of a String array, starts with SEARCHTEXT (String)

public static ArrayList<String> searchFromStart(String[] inputArray, String searchText) {

            ArrayList<String> outputArray = new ArrayList<String>();

            for (int i = 0; i < inputArray.length; i++) {

                        if (searchText.compareToIgnoreCase(inputArray[i].substring(0,
                                                searchText.length())) == 0) {

                                    outputArray.add(inputArray[i]);

                        }

            }

            return outputArray;
}

Monday, December 24, 2012

Ví dụ cơ bản về Spring Framework web


Tạo một package mới với tên tùy ý bên trong của thư mục src. Class Spring Controller extends đến org.springframework.web.servlet.mvc.AbstractController. Để tạo ra một Class Controller mới kích chuột phải vào thư mục src và tạo ra một lớp java mới, hãy nhập tên Controller class và tên super class và nhấn nút Finish.

Tuesday, December 11, 2012

Handling huge data using ZK


Overview

When your database contains a large amount of data you do not want to load all these items into memory. ZK provides many methods for handling large amounts of data including:

  • Live data scrolling
  • Load on demand Trees
  • Paging components

One of the most convenient ways in which to handle a large amount of data is using a paging mechanism.

Introducing huge data with paging

However, normally the paging mechanism will load all the data into the grid via the model. This Small Talk guides you through a method of handling large amounts (in this case 1,000,000 database entries) of data using a small memory footprint.

Monday, December 10, 2012

Dependency Injection với Abstract Factory


Bài viết này, chúng ta cùng tìm hiểu ưu và nhược điểm của Dependency Injection (DI - “tiêm ” phụ thuộc) với một số cách khác nhau dùng Abstract Factory design pattern. Đặt trong ngữ cảnh của một số vấn đề như: Tạo stateful objects với tham số, điều khiển kiểm tra exceptions khi tạo object, và gắn động các objects. Mà các IoC frameworks, như Spring IoC container, PicoContainer và Guice, không đưa ra giải pháp tốt nhất cho các trường hợp này.

Abstract Factory Design Pattern cho Dependency Injection

GoF* Abstract Factory design pattern được tóm gọn theo 2 bước:
Một factory interface thay thế cho một class abstract factory (Optional),
Mọi factory method chịu trách nhiệm tạo một object và tiêm phụ thuộc vào nó.
Xét ví dụ đơn giản sau:

Khám phá Java: biến static trong inner class


Hôm nay tình cờ đọc một bài về một lỗi khó hiểu của Java. Có thể nó sẽ làm bạn đau đầu đây, cùng tôi khám phá nhé.
Click vô hình để phóng to


Ta có thể nhìn thấy 2 biến được khai báo, nhưng khác kiểu. Theo bạn thì ta đang gặp vấn đề gì vậy

Gợi ý nhé:
1.Nó sẽ đúng khi ta khai báo Object là String, nhưng array thì không.
2. Bạn sẽ bị báo lỗi sau khi dùng Eclipse:
The field OBJECT_CONST cannot be declared static; static fields can only be declared in static or top level types

Báo kiểu này chỉ làm ta rối mắt thêm thôi, vì biến integer dùng được mà.

Dojo JSON-RPC + Java


Dojo hỗ trợ JSON-RPC, là tính năng mở rộng của JSON dùng để triệu gọi phương thức từ xa. JSON-RPC có thể dùng như một phương tiện cho các ứng dụng cần giao tiếp với servers. Ví dụ sau sẽ chỉ ra cách tương tác với Java trên server và gọi một phương thức Java từ JavaScript dùng Dojo RPC services. Nó cũng cho thấy việc sử dụng JSON-RPC dễ dàng hơn khi dùng Java.

Đầu tiên, ta tạo một servlet và viết phương thức POST sẽ đọc nội dung của request:
public class JsonRPC extends HttpServlet {
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
                throws ServletException, IOException {
         String content = streamToString(req.getInputStream());

Ta dùng json.org’s Java library để phân tích và lấy ra các thuộc tính từ JSON object. Một JSON-RPC object gồm có 3 thuộc tính được định nghĩa để gọi: method, params, và id. Như sau:


Popular Posts