• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Netbeans and java source files

 
drew taylor
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sam Bluesman
Ranch Hand
Posts: 191
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic