Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Java Newsletters Archive: 5

JavaFAQ Home » Java Newsletters Go to all tips in Java Newsletters


Bookmark and Share

Hello dear subsribers!

We continue to send you our daily Java tips!

Today you receive our tips that will appear
on our site in October, 11 and following week.
This week they are really big and we can say more
than small tips!
Mini articles Smile .

This is not sent unsolicited. You are receiving this
newsletter because you signed up for it, or a friend has
forwarded it for you.
******************************************************
Please, if you like our tips, recommend us to your friends and colleagues.
******************************************************
Tip1

Question: Are not-initializable classes and methods like
System.out.println() and Math.random() "synchronized" ?
Answer: I think they are synchronized. Simple observation: did you ever
see once that printout was broken into two pices by another printout?
I mean for example if you do smth. like this:

In 1st thread:
System.out.println("1234567890");
And in 2nd thread:
System.out.println("something else here");

it never will be broken like:

12345
something else here
67890

Even if Sun didn't write about it explicitly, we can see that it is
synchronized or at least behaves like synchronized that is the same
for our real life.
......................................................................………………………..
Tip 2
How can I set a JFrame to be full screen at the start of a program? I want
no borders, no titles and I just want to use the entire screen.
A: Try using JWindow instead, that one can be customized to have no
borders or titles... as for size, I think you can use:
setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().

getDefaultScreenDevice().getDefaultConfiguration().getBounds());
to fill out the entire screen.
......................................................................………………………..
Tip 3
Whats the difference between the two: System.err. and System.out?
When should we use System.err?
Answer 1: System.out leads the output to the standard output stream
(normally mapped to your console screen), System.err leads the
output to the standard error stream (by default the console, too).
The standard output should be used for regular program output,
the standard error for errormessages. If you start your console
program regularly both message types will appear on your screen.

But you may redirect both streams to different destinations (e.g. files),
e.g. if you want to create an error log file where you don't want to be
the regualr output in.

On an UNIX you may redirect the output as follows:

java yourprog.class >output.log 2>error.log

this causes your regular output (using System.out) to be stored in
output.log and your error messages (using System.err) to be stored
in error.log

Aanswer 2: System.err is a "special" pipe that usually is directed
to the standard consolle. You can redirect the System.out with the
normal pipe control (| or >), but System.err no. If you want to put
both the "normal" output and the "error" output to a file you must
use the special redirect 2>.

This allow you to send normal messages into a file or in the /null
black hole, but still receive the error messages on the console.
......................................................................………………………..

Tip 4
Why cannot I mix AWT and Swing?
Q: Recently, I have been hearing a lot of people from various
newsgroups and website saying, java swing and awt can't be in the
same application. They will not work together and they might
produce unexpected results. At the same time, i don't hear people
saying "why" you shouldn't use swing and awt together. Could
someone out there shed some light for me.
Is their any logical reason why we shouldn't mix Swing and AWT
in the same application/applet? If there is a problem mixing Swing
and AWT... what are the results, what can happen? I design using
IBM's Visual Age for Java 3.0, and I mix swing and awt in the
same application/applet, it works fine when testing in the IDE
(I haven't tested it outside of the IDE yet).
If you have tested application/applets outside of the IDE, please
let me know what happened?

A: There are fundamental incompatibilities in the way they
draw themselves. AWT java classes are not "pure" Java classes,
they use underlaying C/C++ native code (dependable on operation
system) that can cause different appearence in different OSs.
Swing is pure Java implementation and has no native code at all.
Swing applications look the same.

> If there is problems mixing swing and awt... what are the results,
> what can happen?

Some objects drawn on top of others are not properly occluded.
This is most obvious with drop down menus, which have a tendency
to stay visible even after you have selected a menu item. Another
problem is that if you use AWT components on a JtabbedPane
they will not disappear when you switch tabs. There are many
similar issues.
......................................................................………………………..
Tip 5

I will be thankful if anyone tells me why JVM is called virtual
machine.

A: JVM is called a virtual machine because there is no real
hardware, which interprets the byte code. If you have done
any assembly programming for any microprocessor/microcontroller
you will able to understand this. A microprocessor has builtin
instruction set to interpret the assemly code. Similarly the JVM
is similar to a microprocessor in the sense it has its own instruction
set but it implemented in software.
That is why it is called a virtual machine!

......................................................................………………………..
Tip 6

I am totally confused about the differences between the SDK, JDK
and IDE products…
Q: I am brand new to the world of Java and am most interested in learning
the language. However, I am confused about the differences between the
SDK, JDK and IDE products. I have gone to the Sun site and even some of
the IDE vendor sites and I have yet to find something that tells me
what the differences are between the three and which of the three
I need to program in Java.

I want to program using some form of IDE but do I need to separately
download and install a SDK and/or JDK? Sun needs to improve their
documentation for us new to the Java environment.

A1: IDE is an acronym for _I_ntegrated _D_evelopment _E_nvironment.
These products are the one-stop shops for coding, running and debugging
your code. Often these will include GUI based drag and drop form
designers and "wizards" for the shells of common forms of code
(Application, Applet, etc.) JBuilder is an IDE.

The IDE may stand on its own, or it may act as a front end for a JDK.

JDK is _J_ava _D_esign _K_it. A JDK is a command line based interface
to the JVM, plus the classes. You are responsible for your own editors,
creating code for GUI elements, and all code. All of the IDE's I have
reviewed personally come with JDK or their own vendor's equivalent
(JVM and class libraries). Some IDE's are capable of a sort of
"upgrading" by downloading the latest JDK from Sun (JBuilder for example).

A2: If you want to write a Java program using any editor and not an
IDE then you would want to download the JDK. It will let you compile
and run Java programs from the command line (like a DOS window).
JDK stands for Java Development Kit and SDK stands for Standard
Development Kit.

Java comes in three versions - Standard, Enterprise, and Micro editions.
JDK could be any one of the three. SDK is the standard one - this is the
one most people use. If you want an IDE they typically come with a
JDK so all you would need to do there is download the IDE and start using it. ......................................................................………………………..
Tip 7

How can I pass a string to the command line (DOS)? Also i want to
capture the output given by the command line in a string.

A1: Try this out:

// works for DOS
String cmds[] = new String[2];
cmds[0] = "dir"; // replace with "ls" on UNIX
cmds[1] = "c:"; // replace with "/" on UNIX

// execute the command
Process pro = Runtime.getRuntime().exec(cmds);
// wait until it's done executing
pro.waitFor();

// what did the process output from the Input pipe back to
// this process (okay, who named this stuff)?
InputStream out = pro.getInputStream();

// output it (really slowly)
int i;

while ((i = out.read()) != -1) System.out.println((char) i);


With best regards Java FAQ team, http://javafaq.nu/java
Free Daily Java Tips, free books, code examples and hand-selected links!
You can find our tips on site later also!
Recommend us to your friends!


 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy