Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:27:57+00:00 2026-06-13T04:27:57+00:00

I am a PHP/Mysql programmer trying to learn Java and I’m stuck on how

  • 0

I am a PHP/Mysql programmer trying to learn Java and I’m stuck on how to complile a file with this in it:

public static void main(String[] args)

Here is example code:

import java.net.*;
import java.io.*;

public class GreetingClient
{
public static void main(String [] args)
{
  String serverName = args[0];
  int port = Integer.parseInt(args[1]);
  try
  {
     System.out.println("Connecting to " + serverName
                         + " on port " + port);
     Socket client = new Socket(serverName, port);
     System.out.println("Just connected to "
                  + client.getRemoteSocketAddress());
     OutputStream outToServer = client.getOutputStream();
     DataOutputStream out =
                   new DataOutputStream(outToServer);

     out.writeUTF("Hello from "
                  + client.getLocalSocketAddress());
     InputStream inFromServer = client.getInputStream();
     DataInputStream in =
                    new DataInputStream(inFromServer);
     System.out.println("Server says " + in.readUTF());
     client.close();
  }catch(IOException e)
  {
     e.printStackTrace();
  }
}
}

When run the try to use the javac command in Windows Command prompt to compile this from a .java file into a .class file to be called in a webpage, I get an error saying:

bad class file: .\String.java
file does not contain class String
Please remove or make sure it appears in the correct subdirectory of the classpath.

public static void main(String[] args) {

If a compile a .java file like this one:

import java.applet.Applet;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Properties;
public class applet_test extends Applet {
private InetAddress addr = null;
public void init() {
    try {
        addr = InetAddress.getLocalHost();
    }
    catch (UnknownHostException e) {
        System.exit(0);
    }
}
public InetAddress getLHost() {
    return addr;
}

}

I get no errors, the .java file compiles into a .class file and I am able to use the .class file in a webpage just fine.

Not sure what I’m doing wrong.

Thanks guys!


Ok, so now, when I run this command:

C:\ > javac GreetingClient.java

I get this:

GreetingClient.java:9: cannot find symbol
symbol  : method parseInt(GreetingClient)
location: class java.lang.Integer
  int port = Integer.parseInt(args[1]);
                    ^
GreetingClient.java:14: cannot find symbol
symbol  : constructor Socket(GreetingClient,int)
location: class java.net.Socket
     Socket client = new Socket(serverName, port);
                     ^
2 errors

Again, I only seem to get errors when running the javac command on a file with this line in it:

 public static void main(String[] args)

I know I’m missing something, any help would be appreciated it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:27:58+00:00Added an answer on June 13, 2026 at 4:27 am

    Since your file contains class GreetingClient, it must be named GreetingClient.java. Java requires that the name of the file match the name of the class defined inside it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a newbie programmer doing his best to self learn PHP. I'm trying to
i'm a iphone programmer, and not so great in php and mysql. My question
I'm an experienced programmer (PHP/mySQL, jQuery), but know nothing about ColdFusion. A precursory Google
I am a beginner level php programmer. I was trying to use the MVC
I'm trying to format some dates in PHP (i'm a Coldfusion programmer, so the
I am a new php and mysql programmer. I am handling quite large amount
This is how last part of my application(php/mysql website) is supposed to work: BackEnd
Web programmer here - using AJAX (HTML, CSS, JavaScript, AJAX, PHP, MySQL), but for
I have the following MYSQL select statement in a php file that was provided
Note: Configuration are being kept in a PHP file, config.php . I've seen this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.