JAVA 101 help

As a complete novice with JAVA I am trying some sample tests to get some sort of handle on how to program in this language.

Please see the below code

import java.util.Scanner;

public class makeitwork {

static Scanner scanner = new Scanner(;

public static void main(String] args) {
	Boolean alarm = false;
	System.out.println("What time 0-24");
	Integer clock = Integer.parseInt(scanner.nextLine());
	System.out.println("Door open 'T' or 'F'");
	String door = (scanner.nextLine());
	System.out.println("Test combo 0000-9999");
	String combo = (scanner.nextLine());
	if (clock < 5){
	if (clock == 5){
		System.out.println("clock = 5");
	if (clock >5 && clock <24){
		System.out.println("clock > 5 and < 24");
	if (clock >5 || clock <24){ // watch out for this one :) it only fails with 24
		System.out.println("clock > 5 or < 24");
	if (clock >=23 && clock <=24 || clock>= 0 && clock <= 3){
		System.out.println("clock 11pm to 3 am");
	// all those integer functions seem to work on clock.
	// lets see what work for strings
	if (door == "t"){
		System.out.println("It's a t:)");
			System.out.println("Don't know-"+door+"-");
} //end of main

}// end of public

The integer functions seem to work just as expected but when I try the same thing with what I think is a string it does not work at all. The print will always be “Don’t know-”+door+"-" result.

So my question(s) are;
What am I doing wrong?

Where in the “eclipse” enviroment can I find example help on functions?
When using the ‘Help’ function in eclipse what does one do to get a list functions?

Currently I am looking for way of finding things out about a string such as;
1)it’s length
2)how to strip a string apart one charater at a time and search for delimiters etc.
for example;
assume test] are strings

test = “334,5,t,678,c,9”
from the ‘test’ I would like to extract the string parts separted by a ‘,’
to get
test1 = “334”
test2 = “5”
test3 = “t”
test4 = “678”
test5 = “c”
test6 = “9”

Many thanks

You have (door == “t”), this is not recommended.

Strings are objects, unlike ints and other primitive types. And because Strings are objects, you can’t use ‘==’ to compare two Strings. You would need to use

The java string classhas methods to do each of the things you’re asking about.

.equals() and .length() for the first two.

While you can manually tear the string apart, there is a method .split() which will parse out comma separated (or any regular expression separated) substrings.

The Java tutorial maintained by Oracle is here:
Tutorial Big Index
You can perhaps find better ones (better for you), if you look around. However, this one is the safe, common denominator for me to recommend. It should include a section or subsection about String objects.

The Java version 8, Standard Edition, API reference, maintained by Oracle, is here:
Java 8 SE API Reference
Looking up the String class will show you String’s “equals” method, along with all the others available for what you want to do. This is the same info GeeTwo’s link will take you to, except that I gave the URL for the entire Java SE version 8 API doc. His link goes straight to the Java SE version 7 String class.

PS: I dunno how to configure Eclipse to help you. However, the “StackOverflow” Q&A site often has answers for questions like these, because someone else already already asked the same question. I gravitate toward their links when I use Google to search for software answers.

When you evaluate door == “t” it is not checking to see if door has that value. It is checking to see if the bits are the same. In the case of a String object, that means “are they pointing at the same place in memory?”, not “are they equal in value?” Because the bits are the location where the object’s data is stored. With an integer you are dealing with a primitive so the bits are a value and not a memory location. As GeeTwo said, if you use if(door.equals(“t”)) you will get the comparison you want.

It might be useful to talk about the reason for this.

Let’s say I have two Strings:

String a = “blah”;
String b = “blah”;

When I instantiate these Strings, Java allocates two different memory locations for them. And ‘a’ points to the first one that has the “blah” data in it, and 'b" points to another location with the “blah” data in it.

That’s why a==b returns false, because ‘a’ and ‘b’ are pointing to two different objects, even if they have the same value.

The ‘==’ operator in this case checks to see if they are the same object, not if the have ‘equal’ values.

Added a word for clarity:

One great approach to learning JAVA is to use GreenFoot. This is a set of 10 minute videos and a special build JAVA environment. Easy and fun to use.
Dave Frederick

Many thanks to all those that have responded with all the get help and links.

That’s barbaric. At least C++ allows overloading operators.
All my fears of Java are coming true.