java 7 features not working on ubuntu with java version "1.7.0_51" -
according java -version ubuntu java environment like:
java version "1.7.0_51" openjdk runtime environment (icedtea 2.4.4) (7u51-2.4.4-0ubuntu0.12.04.2) openjdk 64-bit server vm (build 24.45-b08, mixed mode) my javac -version is:
javac 1.6.0_30 how change javac version? tip @sotiriosdelimanolis. ;) (if reading , have same problem read comments. link page describes how on ubuntu).
i trying run following program:
import java.util.*; class separate { public static void main(string[] args) { string text = "<head>first program</head> <body>hello world</body>"; set<string> words = new treeset<>(); //1 compiler error try(scanner tokenizingscanner = new scanner(text)) { //2 compiler error tokenizingscanner.usedelimeter("\\w"); while(tokenizingscanner.hasnext()) { string word = tokenizingscanner.next(); if(!word.trim().equals("")) { words.add(word); } } //end while } //end try for(string word: words) { system.out.print(word + " "); } //end } i receive these errors upon trying compile:
separate.java:8: illegal start of type set<string> words = new treeset<>(); ^ separate.java:9: '{' expected try(scanner tokenizingscanner = new scanner(text)) { ^ separate.java:9: ')' expected try(scanner tokenizingscanner = new scanner(text)) { ^ separate.java:9: ';' expected try(scanner tokenizingscanner = new scanner(text)) { ^ separate.java:9: 'try' without 'catch' or 'finally' try(scanner tokenizingscanner = new scanner(text)) { ^ separate.java:24: reached end of file while parsing } ^ 6 errors these errors seem should not errors. first error showing diamond notation found in java 7 not correct syntax or when correct. error shown 1 above in comments.
the other errors stemming scanner object creation in try block try resources java 7 feature. line marked 2 above in source code.
does know missing?
sounds code not compiled under jdk 7. check version of compiler (as sotirios mentioned)
Comments
Post a Comment