Java Downcasting

Java da bir base class i daha belirli bir class a çevirme i?lemine downcasting denilir. Mesela Object class ini String class ina çevirmek. Bu casting i?lemi objeyi tam olarak çevirmez, sadece çevirdi?ini iddia eder. Bundan dolay? baz? durumlarda compile time veya runtime hatalar? al?nabilir.

Örnek verecek olursak :

Çalisabilecek kod :

1
2
3
Object o = getSomeObject();
 
String s = (String) o; // Burada compile time hatas? al?nmaz çünkü o objesi String class inin referans?na sahip olabilir.

Runtime hatas? alacak kod :

1
2
3
Object o = new Object();
 
String s = (String) o; // Object class inin String class ina referans? olmad??? için runtime hatas? olacak

Çal??an kod:

1
2
3
Object o = "a String";
 
String s = (String) o; // String referans? oldu?u için çal??acak

Compile time hatas? alacak kod :

1
2
3
Integer i = getSomeInteger();
 
String s = (String) i; // i nin String class i na referans? olmad??? için dermele an?nda hata verecektir.

referans : stackoverflow.com

Flex ldquo;Could not resolve hellip; to a component implementation.rdquo; hatas?

flex3

Flex de bu hata Türkçe karakter probleminden kaynaklan?yor. Çözümü için iki yol var. Birincisi FlexBuilder.ini de gerekli de?i?ikleri yapmak, ikincisi ise bilgisayar?m?zda unicode olmayan programlar?n dilini de?i?tirmek. Ben ikisini de anlataca??m ama ilk çözüm daha mant?kl? çünkü flex d???ndaki programlar? etkilemiyor.

FlexBuilder.ini yi de?i?tirmek

C:\Program Files\Adobe\Flex Builder 3 alt?ndaki FlexBuilder.ini dosyas?n? herhangi bir text editor ile aç?n. A?a??daki iki sat?r? dosyan?n sonuna ekleyin.

-Duser.language=en

-Duser.location=us

flex1

Dosyam?z?n son hali yandaki gibi olacakt?r. Daha sonra Flex Builder i kapat?p açt???m?zda hata vermedi?ini görece?iz.

 

 

 

 

 

 

Unicode olmayan programlar?n dilini de?i?tirmek

Windows 7 için Denetim Masas? –> Bölge ve Dil Seçenekleri –> Yönetim in alt?nda unicode olmayan programlar için olan dil ayar?n? ingilizce seçiyoruz.

flex2

Daha sonra sistemi yeniden ba?latmam?z? isteyecektir. Sistemi yeniden ba?latt?ktan sonra sorun çözülmü? olacakt?r.

Eclipse Ogre4j 3d Motoru Kurulumu

1. Eclipsi ba?lat?p yeni bir java projesi olu?turun. Bo? HelloWorld class ? olu?turun.

2. Ogre4j yi a?a??daki adresten indirin.

http://ogre4j.sourceforge.net/

ogre4j-1.6.2-beta6-bin-win32.tar.bz2 dosyas?n?n inmi? olmas? gerekmektedir.

3. OGRE yi www.ogre3d.org adresinden indirin. ?ndirmek için a?a??daki dosyay? seçin.

downloads -> SDK -> OGRE 1.6.2 SDK for Visual C++ .Net 2005 (8.0) SP1

4. OGRE SDK yi kurun.

5. SWT nin son versiyonunu http://www.eclipse.org/swt/ adresinden indirin. Dosya ad? swt-x.x-win32-win32-x86.zip olmal?d?r.

6. http://ogre4j.sourceforge.net/webstart/lib/media.jar dosyas?n? indirin.

7. dll ve jar dosyalar?n? ogre4j-1.6.2-beta6-bin-win32.tar.bz2 klasöründe ç?kar?p projeniniz root klasörüne ekleyin. (c:\users\ugur\workspace\OgreHelloWorld)

8. OGRE SDK daki dll dosyalar?n? projenizin root klasörüne ekleyin. (C:\OgreSDK_1.6.2\bin\release\*.dll)

9. Projenizin root klasöründe ‘media’ adlo bir klasör olu?turun. media.jar dosyas?n?n ismini media.zip yap?p içindeki zuh.mesh ve zuh.material dosyalar?n? olu?turdu?unu media klasörüne kopyalay?n.

10. swt.jar dosyas?n? swt-x.x-win32-win32-x86.zip dosyas?ndan ç?kararak projenizin root klasörüne kopyalay?n.

11. Eclipse projenizi seçip f5 e basarak klasörlerin yenilenmesini sa?lay?n.

12. Projenize sa? t?klay?p "Build path"->"Configure build path->libraries->Add jars” e gelerek bütün jar dosyalar?n? ekleyin(swt.jar ve ogre4j.jar).

13. http://ogre4j.svn.sourceforge.net/viewvc/ogre4j/trunk/org.ogre4j.examples.swt/src/org/ogre4j/examples/swt/HelloWorld.java?view=markup linkindeki içeri?i HelloWorld class? na ekleyerek çal??t?r?n.

Visual Studio 2008 e Irrlicth 3d Motoru Kurulumu

1. Irrlicth in son sürümünü a?a??daki adresten indiriyoruz.

http://irrlicht.sourceforge.net/downloads.html

2. Zip dosyas?n? aç?yoruz.

3. Irrlicth-x.x/include un alt?ndaki header dosyalar?n?n hepsini C:\Program Files\Microsoft Visual Studio 9.0\VC\include klasörüne kopyal?yoruz.

4.   Visual Studio 2008 de Tool->Options->Project and Solutions->VC++ Directories k?sm?na a?a??daki iki sat?r? ekliyoruz.

…/Irrlicth-x.x/include

…/Irrlicth-x.x/lib/Win32-visualstudio

image

5. Visual Studio 2008 de Project->Options->Configuration Properties->Linker->Input->Additional Dependecies k?sm?na a?a??daki sat?r? ekliyoruz.

Irrlicht.lib

image

6. Yeni bir proje olu?turuyoruz.

image

7. Irrlicth in header dosyalar?n? projemizin header k?sm?na ekliyoruz.

image

…\irrlicht-x.x\include alt?ndaki bütün dosyalar? ekliyoruz.

image

8. Source folder ina yeni bir cpp dosyas? ekleyip a?a??daki kodu ekliyoruz.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
// ask user for driver
 
video::E_DRIVER_TYPE driverType;
 
printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
" (d) Software Renderer\n (e) Burning's Software Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");
 
char i;
std::cin >> i;
 
switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL;   break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
case 'f': driverType = video::EDT_NULL;     break;
default: return 1;
}
 
// create device and exit if creation failed
 
IrrlichtDevice *device =
createDevice(driverType, core::dimension2d<u32>(640, 480));
 
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
device->getFileSystem()->addZipFileArchive("C:/Users/Ugur/Desktop/irrlicht-1.6/media/map-20kdm2.pk3");
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* node = 0;
if (mesh)
node = smgr->addOctTreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
//              node = smgr->addMeshSceneNode(mesh->getMesh(0));
if (node)
node->setPosition(core::vector3df(-1300,-144,-1249));
smgr->addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(false);
int lastFPS = -1;
 
while(device->run())
{
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255,200,200,200));
smgr->drawAll();
driver->endScene();
 
int fps = driver->getFPS();
 
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Engine - Quake 3 Map example [";
str += driver->getName();
str += "] FPS:";
str += fps;
 
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
else
device->yield();
}
device->drop();
return 0;
}

9.  Projeyi build etti?imz zaman Quake 3 in bir haritas? aç?lacakt?r.

image image

U?ur Dönmez

METU CENG

ugur@ugurdonmez.com

Visual Stdio 2008 ile Ogre Kullanmak

1. Ogre SDK yi http://www.ogre3d.org/wiki/index.php/Installing_the_Ogre_SDK_on_Windows adresinden indiriyoruz. Ben Installing the Ogre SDK for Visual C++ 2008 & Code::Blocks paketini kurdum.

2. Ogre Application Wizard i http://www.jacmoe.dk/forum/index.php?topic=3.0 adresinden indiriyoruz.

3. Ogre SDK yi C:\OgreSDK alt?na kuruyoruz. Ba?ka bir yere kurmak sorun ç?karabilir.

4. Ogre SDK ortam de?i?keninin varl???n? her ihtimale kar?? kontrol ediyoruz. Bunun için Bilgisayar?m a sa? t?klay?p Geli?mi? tab?ndaki ortam de?i?kenlerine t?kl?yoruz.

image

5. OGRE AppWizard i unzip edip

image

VC9_Setup u çal??t?r?yoruz.

image

6. Visual Studio 2008 den yeni proje olu?turuyoruz.

image

Ogre SDK Application u seçiyoruz.

image

OGRE SDK Application Wizard u takip ediyoruz.

image

image

Finish dedikten sonra örnek projemiz olu?uyor.

image

7. Olu?turdu?umuz projeyi build ediyoruz.

image

8. Build etti?imiz proje OgreSDK/bin/debug klasörünün alt?nda yer almaktad?r.

image

Kaynak : http://www.ogre3d.org

Microsoft Visual Studio 2008 ile OpenGl Kullanmak

Öncelikle gerekli binary dosyalar? a?a??daki adreslerden indiriyoruz.

freeglut 2.4.0

GLUT win32 binaries

Daha sonra indirdi?imiz dosyalar? do?ru klasörlere yerle?tirmemiz gerekiyor.

  • freeglut.h i dosyas?n? ‘C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL\’ klasörüne ( GL klasörünü yaratman?z gerekmektedir.  )
  • freeglut_ext.h dosyas?n? ‘C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL\’ klasörüne,
  • freeglut_std.h dosyas?n? ‘C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL\’ klasörüne,
  • freeglut.lib dosyas?n? ‘C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\’ klasörüne,
  • freeglut.dll dosyas?n? ‘C:\WINDOWS\system32\’ klasörüne,
  • glut32.dll dosyas?n? ‘C:\WINDOWS\system32\’ klasörüne,
  • glut32.lib dosyas?n?‘C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\’ klasörüne,
  • glut.h dosyas?n? ‘C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL\’ klasörüne kopyal?yoruz.

Daha sonra olu?turaca??m?z C++ projesine freeglut kütüphanesini tan?tmam?z gerekiyor.

1. Visual Studio da yeni bir C++ Console Application olu?turuyoruz.

1a. Win32 Application Wizard da ‘Empty Project’ i seçiyoruz.

image02

2. Projeye yeni bir cpp dosyas? ekliyoruz. ?çine a?a??daki örnek kodu yaz?yoruz.

#include <freeglut.h>
int main ()
{
return 0;
}

3. Debug etmeye çal???rsak Visual Studio hata verecektir çünkü freeglut header dosyalar?n? projeye henüz tan?tmad?k.

3a. Menu bar dan Project->Project Properties i aç?yoruz.

3b.  Linker->Input ta Additional Dependencies yazan yere a?ag?daki sat?r? kopyal?yoruz.

opengl32.lib glu32.lib glut32.lib

image07

4. Derlemeye çal???rsak hala hata verebilir çünkü header ve library lerin klasörünü projenin directories ine eklememiz gerekmektedir.

4a. Tools –> Options alt?ndaki Project and Solutions menüsünde VC++ Directories i seçiyoruz.

4b. C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL sat?r?n? ekliyoruz.

include files

5. Proje art?k derlenmektedir.

Java: Scanner nextInt() hasNextInt() Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.Vector;
 
public class ScannerExample {
 
	public static void main (String [] args) {
		Vector<Integer> vector = new Vector<Integer>();
		Scanner scanner;
		try {
			scanner = new Scanner(new File("map.txt"));
			Integer i;
			while (scanner.hasNextInt()) {
				i =  scanner.nextInt();
				vector.addElement(i);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
 
		System.out.println("the elements of vector: " + vector);
		System.out.println(vector.size());
	}
}

Java: Vector Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.Random;
import java.util.Vector;
 
public class VectorDeneme {
 
	public static void main (String [] args) {
		Vector<Integer> vector =  new Vector<Integer>();
		Random generator = new Random();
 
		int randomInteger;
		for (int i = 0 ; i < 10 ; i++) {
			randomInteger = generator.nextInt( 100 );
			vector.add(randomInteger);
		}
 
		System.out.println("the elements of vector: " + vector);
	        System.out.println("The size of vector are: " + vector.size());
	        System.out.println("The elements at position 2 is: " + vector.elementAt(2));
	        System.out.println("The first element of vector is: " + vector.firstElement());
	        System.out.println("The last element of vector is: " + vector.lastElement());
 
	        vector.removeElementAt(2);
	        vector.removeElementAt(8);
 
	        System.out.println("the elements of vector: " + vector);
	}
}

Possible Output:
the elements of vector: [51, 72, 88, 70, 17, 73, 28, 61, 70, 62]
The size of vector are: 10
The elements at position 2 is: 88
The first element of vector is: 51
The last element of vector is: 62
the elements of vector: [51, 72, 70, 17, 73, 28, 61, 70]

Java Deserialization:Reading an Object Stream

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.*;
 
public class UnserializeBoolean {
 
    public UnserializeBoolean() {
        Boolean booleanData = null;
        try {
            FileInputStream fis = new FileInputStream("boolean.ser");
            ObjectInputStream ois = new ObjectInputStream(fis);
            booleanData = (Boolean) ois.readObject();
            ois.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        System.out.println("Unserialized boolen from " + "boolean.ser");
        System.out.println("Boolean data: " + booleanData);
        System.out.println("Compare data with true: " + booleanData.equals(new Boolean("true")));
    }
 
    public static void main(String [] args) {
        UnserializeBoolean uab = new UnserializeBoolean();
    }
}

Java Serialization: Writing an Object Stream

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.io.*;
 
public class SerializeBoolean {
 
    public SerializeBoolean() {
        Boolean booleanDAta = new Boolean("true");
        try {
            FileOutputStream fos = new FileOutputStream("boolean.ser");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(booleanDAta);
            oos.close();
        } catch (IOException ie) {
            ie.printStackTrace();
        }
    }
 
    public static void main(String [] args) {
        SerializeBoolean ab = new SerializeBoolean();
    }
}