• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Jeffige

Can someone explain what this means please

4 posts in this topic

I got to this example in one of my java books. Typed it out, compiled it. It ran fine. But, I seen this warning or whatever it is. Is there anything wrong with this? How can I correct it? Is it something that is out of date?


From the book-
[img]http://i1211.photobucket.com/albums/cc440/jeffige/BOOKIMAGE_1.gif[/img]
From Eclipse-

[img]http://i1211.photobucket.com/albums/cc440/jeffige/eclipseimg_2.gif[/img]

Also, is it better to learn using Netbeans or Eclipse or just something like notepad and cmd on windows?

Thanks for any help.
0

Share this post


Link to post
Share on other sites
Just use sc.close() to "shut down" the Scanner.

It is much easier to use an IDE like those you mentioned, as it gives you syntax highlighting, debugging, and easy compiling and running. Edited by SamiHuutoniemi
0

Share this post


Link to post
Share on other sites
First of all, please copy and paste the code text on the forums, using [ code ] tags or the helpful edit buttons provided. This makes it easier for us because we can quickly copy your code into our own IDE and test it out.

To your question, some Java objects deal with external resources. For example, a file on your hard disk, or a connection to a network, or more esoteric resources still. These need to be explicitly managed and promptly closed when you are finished using them so that the operating system can do any maintenance and cleanup it needs to do. Most external resources can be cleaned up by the operating system when your program exits. However, it can only clean up what it knows about.

Sometimes data can be lost - for example, if you write some data to a file, the data will often end up in a buffer in memory (for performance reasons). It gets written out periodically as the buffer gets larger. Closing a resource will cause any remaining data in these buffers to be permanently written to the disk. If the file is not closed, when the program ends the operating system is not aware of the special nature of this buffer, so it doesn't know to put it in the file when it is cleaning up.

There are other consequences to not cleaning up resources. Long running programs are said to "leak" resources that they don't clean up. Some operation systems have limits on the number of open resources (files, network connections, etc) that a given program can use. If a program doesn't close all the resources, they'll eventually reach their limit and the operating system will refuse to open new resources for them. Thus the program stops functioning after some time.

This is particularly important in games, where the number of loops per second is very high. A resource leak such as not alerting the operating system / graphics driver that you are finished with a particular texture could result in the game slowing down between level loads and eventually failing to load a level.

To come back to the specifics, the Scanner class can be used to wrap all sorts of input devices, not just the interactive console. The interactive console is a relatively simple resource, there are few of the downsides mentioned above to reckon with. If you were wrapping a file or network connection, close()ing the scanner (which closes the "wrapped" device) would be much more important. However, it is good practise to close() it anyway.

You may not be aware of this, but it is possible to make your program read data from a file, and write it to a file. On windows, you could do this:
input.txt
[code]
10
[/code]

console:
[code]
c:\path o\project> java ComputeCircle < input.txt > output.txt
[/code]
This tells the command interpreter to:
[list]
* Execute the java program
* Pass ComputeCircle as the parameter to the program
* Instead of the keyboard, read from "input.txt"
* Instead of the screen, write any output lines to "output.txt"
[/list]
If you were to open output.txt subsequently, it should contain the same data that Eclipse's console output contains.

Now, all of a sudden, without changing the code, that close() call you omitted might be more important!

[quote]
Also, is it better to learn using Netbeans or Eclipse or just something like notepad and cmd on windows?
[/quote]
I'd stick with the IDE until you are relatively familiar with the language. The exact IDE isn't all that important, provided it is a good one. I've heard good things about Netbeans and I've used Eclipse and it is good.

But it is valuable to understand the build process at a low level eventually. This is because someday Eclipse or Netbeans might have trouble that requires this understanding, or you might be in a situation where you want to compile code or run your program when you don't have an IDE installed and cannot do so. But I wouldn't worry too much for the time being.
0

Share this post


Link to post
Share on other sites
Thanks, SamiHuutoniemi for the info on sc.close()
Since I am a complete beginner, where exactly would I place sc.close() to close the scanner? On the next line after: Scanner cs=new Scanner(System.in);

[quote name='rip-off']
First of all, please copy and paste the code text on the forums, using [ code ] tags or the helpful edit buttons provided. This makes it easier for us because we can quickly copy your code into our own IDE and test it out. [/quote]

Understand. Thank you rip-off.

[quote name='rip-off']
You may not be aware of this, but it is possible to make your program read data from a file, and write it to a file
[/quote]

Uh, no. Very unaware of that. I am a total beginner. I have been learning java for about... 7 hours or so. And 3 of those hours have been trying to get everything installed and running correctly. But hey, I ran my 1st two programs. A million more to go... Edited by Jeffige
0

Share this post


Link to post
Share on other sites
You just need to close it before the end of your program. The last line would be a good place, as that way if you were to add more input statements later you might forget that you closed the scanner earlier.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0