File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Netbeans and java source files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Netbeans and java source files" Watch "Netbeans and java source files" New topic
Author

Netbeans and java source files

drew taylor
Greenhorn

Joined: Feb 20, 2006
Posts: 21
I'm confused because java example code from most books tells you to write a program with the following and declaire the class

Public Class MyFirstApp {

etc

}

But when you create a new file in Netbeans it does this before the static void main(string[] args)

Does it need the package bit? Why does it have the public class, and then Public MyFirstApp() again? If the second is a method does it need it? Or is this just how Nebeans wants the code?

package myfirstapp;

public class MyFirstApp {

public MyFirstApp() {
}
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14430
    
  23

Welcome to JavaRanch!

Note that Java is case-sensitive. You must write "public" and "class", not "Public" and "Class".

Your questions are very basic questions about the structure of a Java program. To learn what this all means, have a look at Sun's excellent Java Tutorial.

There are also many good books available to learn Java - for example, Head First Java.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
It may be better to use something like Jcreator or a favourite text editor and get to grips with Java first, before delving into the realms of IDEs...


Moosey knows best
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by drew taylor:
Does it need the package bit?


You need it when you don't want your class to reside in the default package, which typically is frowned upon.

Why does it have the public class, and then Public MyFirstApp() again? If the second is a method does it need it? Or is this just how Nebeans wants the code?


It's called a constructor. In this case, you could safely delete it.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Netbeans and java source files