Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Few very basic Java questions.

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Few very basic Java questions.

    Hey, I'm brand new to the forum; just signed up.

    Anyway, Im taking a Java programming class right now in college, yet the teacher is horrible doesn't explain anything. She currently just gives us code that we copy and paste into text pad, compile and then run.

    So because of this, it leaves everyone full of questions, tis why I need a few answers.
    Also I'd appreciate it for the answers to be dumbed down a bit..

    1. In the current program she has us writing we are importing 2 files
    import java.awt.*;
    import java.awt.event.*;
    Now from my understandings, isn't * a wildcard and wouldn't it import everything in java.awt in the first line?

    2. Shortly after we have,
    public static void main(String[] args) { some code etc }
    Does public mean that the following code is a class? Also are classes like functions as in I can call them later in the program? Also what exactly does static/void mean. I assume main means its the start of the program or main program.

    3. Last question I have is with this piece of code:
    public void windowClosing(WindowEvent e)
    	{
    		System.exit(0);
    	}
    Now after WindowEvent, there is an e. Is this a variable? or like a parameter or something?

    Thanks for any replies!


  2. #2
    Junior Member
    Join Date
    Jan 2010
    Location
    Orpington, Kent, UK
    Posts
    18
    Thanks
    0
    Thanked 9 Times in 8 Posts

    Default Re: Few very basic Java questions.

    The .* wildcard on the import statement will import all classes within the package, so all classes within java.awt package in your case, however this does not extend to subpackages so classes java.awt.event need to have a seperate import statement.

    public is used to indicate the method has public accessiblity, i.e. any user of this class would be able to access this method, if the method were private only code within the class would be able to access the method, you should get a good Java book and read up on the basic OO principles regarding encapsulation to understand this and other methods of accessibility (such as protected and package), however it is important you understand it.

    When a variable is declared with the static keyword, its called a “class variable”. All instances share the same copy of the variable. A class variable can be accessed directly with the class, without the need to create an instance.
    Without the “static” keyword, it's called an “instance variable”, and each instance of the class has its own copy of the variable. Methods can also be declared with the static keyword. When a method is declared static, it can be called/used without having to create a object first. Methods declared with “static” keyword are called “class methods”. Otherwise they are “instance methods”.

    the public static void main method should be declared if you wish to make your Java class runnable, this is the method the JVM will look for to run the class, if no such method exists then the class can not be run direct from the JVM but can be used be used by other classes within the JVM providing it is on the classpath.

    WindowEvent e is a parameter sent to the WindowClosing method you can access this parameter within the scope of the method by using the e variable.

    I would suggest you get hold of a good Java book, this one is excellent and will give you a good basic understanding:

    Try 'Head First Java' by 'Kathy Sierra'

    "http://www.amazon.co.uk/Head-First-Java-Kathy-Sierra/dp/0596009208/ref=sr_1_1?ie=UTF8&s=books&qid=1266056131&sr=8-1"

  3. The Following User Says Thank You to JavaDaveUK For This Useful Post:

    01001010 (February 13th, 2010)

  4. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Few very basic Java questions.

    Alright, thanks, ill definitely get that book!

Similar Threads

  1. [SOLVED] Questions About Threads
    By neo_2010 in forum Threads
    Replies: 4
    Last Post: March 15th, 2010, 10:04 AM
  2. Replies: 2
    Last Post: October 29th, 2009, 07:13 PM
  3. Basic Java Program Help
    By roaster in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 6th, 2009, 11:28 PM
  4. free scjp 1.6 sample questions
    By sumanjava11 in forum The Cafe
    Replies: 1
    Last Post: August 19th, 2009, 05:00 AM
  5. Some basic questions.
    By trips in forum Java Theory & Questions
    Replies: 5
    Last Post: July 21st, 2009, 03:15 AM